本文整理汇总了PHP中Magento\CatalogInventory\Api\StockRegistryInterface类的典型用法代码示例。如果您正苦于以下问题:PHP StockRegistryInterface类的具体用法?PHP StockRegistryInterface怎么用?PHP StockRegistryInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StockRegistryInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
$this->stockRegistryMock = $this->getMockBuilder(StockRegistryInterface::class)->setMethods(['getStockItem'])->getMockForAbstractClass();
$this->storeMock = $this->getMockBuilder(Store::class)->disableOriginalConstructor()->getMock();
$this->stockItemMock = $this->getMockBuilder(StockItemInterface::class)->setMethods(['getData'])->getMockForAbstractClass();
$this->stockRegistryMock->expects($this->any())->method('getStockItem')->willReturn($this->stockItemMock);
$this->productMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
}
开发者ID:rafaelstz,项目名称:magento2,代码行数:9,代码来源:AdvancedInventoryTest.php
示例2: setUp
protected function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->registryMock = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
$this->stockItem = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface', ['getQtyIncrements'], '', false);
$this->stockItem->expects($this->any())->method('getStockItem')->willReturn(1);
$this->stockRegistry = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\StockRegistryInterface', ['getStockItem'], '', false);
$this->stockRegistry->expects($this->any())->method('getStockItem')->willReturn($this->stockItem);
$this->block = $objectManager->getObject('Magento\\CatalogInventory\\Block\\Qtyincrements', ['registry' => $this->registryMock, 'stockRegistry' => $this->stockRegistry]);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:QtyincrementsTest.php
示例3: modifyData
/**
* {@inheritdoc}
*/
public function modifyData(array $data)
{
$fieldCode = 'quantity_and_stock_status';
$model = $this->locator->getProduct();
$modelId = $model->getId();
/** @var StockItemInterface $stockItem */
$stockItem = $this->stockRegistry->getStockItem($modelId, $model->getStore()->getWebsiteId());
$stockData = $modelId ? $this->getData($stockItem) : [];
if (!empty($stockData)) {
$data[$modelId][self::DATA_SOURCE_DEFAULT][self::STOCK_DATA_FIELDS] = $stockData;
}
if (isset($stockData['is_in_stock'])) {
$data[$modelId][self::DATA_SOURCE_DEFAULT][$fieldCode]['is_in_stock'] = (int) $stockData['is_in_stock'];
}
if (!empty($this->stockConfiguration->getDefaultConfigValue(StockItemInterface::MIN_SALE_QTY))) {
$minSaleQtyData = null;
$defaultConfigValue = $this->stockConfiguration->getDefaultConfigValue(StockItemInterface::MIN_SALE_QTY);
if (strpos($defaultConfigValue, 'a:') === 0) {
// Set data source for dynamicRows Minimum Qty Allowed in Shopping Cart
$minSaleQtyValue = unserialize($defaultConfigValue);
foreach ($minSaleQtyValue as $group => $qty) {
$minSaleQtyData[] = [StockItemInterface::CUSTOMER_GROUP_ID => $group, StockItemInterface::MIN_SALE_QTY => $qty];
}
} else {
$minSaleQtyData = $defaultConfigValue;
}
$path = $modelId . '/' . self::DATA_SOURCE_DEFAULT . '/stock_data/min_qty_allowed_in_shopping_cart';
$data = $this->arrayManager->set($path, $data, $minSaleQtyData);
}
return $data;
}
开发者ID:Doability,项目名称:magento2dev,代码行数:34,代码来源:AdvancedInventory.php
示例4: getStockId
/**
* Retrieve stock_id by store
*
* @param int $websiteId The website Id
*
* @return int
*/
private function getStockId($websiteId)
{
if (!isset($this->stockIdByWebsite[$websiteId])) {
$stockId = $this->stockRegistry->getStock($websiteId)->getStockId();
$this->stockIdByWebsite[$websiteId] = $stockId;
}
return $this->stockIdByWebsite[$websiteId];
}
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:15,代码来源:InventoryData.php
示例5: build
/**
* Copy product inventory data (used for product duplicate functionality)
*
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Catalog\Model\Product $duplicate
* @return void
*/
public function build(\Magento\Catalog\Model\Product $product, \Magento\Catalog\Model\Product $duplicate)
{
$stockData = ['use_config_min_qty' => 1, 'use_config_min_sale_qty' => 1, 'use_config_max_sale_qty' => 1, 'use_config_backorders' => 1, 'use_config_notify_stock_qty' => 1];
$currentStockItemDo = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
if ($currentStockItemDo->getItemId()) {
$stockData += ['use_config_enable_qty_inc' => $currentStockItemDo->getUseConfigEnableQtyInc(), 'enable_qty_increments' => $currentStockItemDo->getEnableQtyIncrements(), 'use_config_qty_increments' => $currentStockItemDo->getUseConfigQtyIncrements(), 'qty_increments' => $currentStockItemDo->getQtyIncrements()];
}
$duplicate->setStockData($stockData);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:CatalogInventory.php
示例6: afterLoad
/**
* Add stock item information to the product's extension attributes
*
* @param \Magento\Catalog\Model\Product $product
* @return \Magento\Catalog\Model\Product
*/
public function afterLoad(\Magento\Catalog\Model\Product $product)
{
$productExtension = $product->getExtensionAttributes();
if ($productExtension === null) {
$productExtension = $this->productExtensionFactory->create();
}
// stockItem := \Magento\CatalogInventory\Api\Data\StockItemInterface
$productExtension->setStockItem($this->stockRegistry->getStockItem($product->getId()));
$product->setExtensionAttributes($productExtension);
return $product;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:AfterProductLoad.php
示例7: testGenerateSimpleProductsWithPartialData
/**
* @param array $productsData
* @dataProvider generateSimpleProductsWithPartialDataDataProvider
* @magentoDbIsolation enabled
*/
public function testGenerateSimpleProductsWithPartialData($productsData)
{
$this->_product->setNewVariationsAttributeSetId(4);
$generatedProducts = $this->_model->generateSimpleProducts($this->_product, $productsData);
$parentStockItem = $this->stockRegistry->getStockItem($this->_product->getId());
foreach ($generatedProducts as $productId) {
$stockItem = $this->stockRegistry->getStockItem($productId);
$this->assertEquals($parentStockItem->getManageStock(), $stockItem->getManageStock());
$this->assertEquals('1', $stockItem->getIsInStock());
}
}
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:VariationHandlerTest.php
示例8: addStockStatusToProducts
/**
* Add stock status information to products
*
* @param \Magento\Catalog\Model\Resource\Collection\AbstractCollection $productCollection
* @return void
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function addStockStatusToProducts(\Magento\Catalog\Model\Resource\Collection\AbstractCollection $productCollection)
{
$websiteId = $this->storeManager->getStore($productCollection->getStoreId())->getWebsiteId();
$productIds = [];
foreach ($productCollection as $product) {
$productId = $product->getId();
$stockStatus = $this->stockRegistry->getStockStatus($productId, $websiteId);
$status = $stockStatus->getStockStatus();
$product->setIsSalable($status);
}
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:Stock.php
示例9: getProductQtyIncrements
/**
* Retrieve product qty increments
*
* @return float|false
*/
public function getProductQtyIncrements()
{
if ($this->_qtyIncrements === null) {
$stockItem = $this->stockRegistry->getStockItem($this->getProduct()->getId(), $this->getProduct()->getStore()->getWebsiteId());
$this->_qtyIncrements = $stockItem->getQtyIncrements();
if (!$this->getProduct()->isSaleable()) {
$this->_qtyIncrements = false;
}
}
return $this->_qtyIncrements;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:Qtyincrements.php
示例10: init
/**
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Catalog\Model\Product $product
* @param \Magento\Framework\DataObject $config
* @return \Magento\Quote\Model\Quote\Item|string
*/
public function init(\Magento\Quote\Model\Quote $quote, \Magento\Catalog\Model\Product $product, \Magento\Framework\DataObject $config)
{
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $quote->getStore()->getWebsiteId());
if ($stockItem->getIsQtyDecimal()) {
$product->setIsQtyDecimal(1);
} else {
$config->setQty((int) $config->getQty());
}
$product->setCartQty($config->getQty());
$item = $quote->addProduct($product, $config, \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL);
return $item;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:Initializer.php
示例11: testBuildWithCurrentProductStockItem
public function testBuildWithCurrentProductStockItem()
{
$expectedData = ['use_config_min_qty' => 1, 'use_config_min_sale_qty' => 1, 'use_config_max_sale_qty' => 1, 'use_config_backorders' => 1, 'use_config_notify_stock_qty' => 1, 'use_config_enable_qty_inc' => 'use_config_enable_qty_inc', 'enable_qty_increments' => 'enable_qty_increments', 'use_config_qty_increments' => 'use_config_qty_increments', 'qty_increments' => 'qty_increments'];
$this->stockRegistry->expects($this->once())->method('getStockItem')->will($this->returnValue($this->stockItemDoMock));
$this->stockItemDoMock->expects($this->any())->method('getItemId')->will($this->returnValue(50));
$this->stockItemDoMock->expects($this->any())->method('getUseConfigEnableQtyInc')->will($this->returnValue('use_config_enable_qty_inc'));
$this->stockItemDoMock->expects($this->any())->method('getEnableQtyIncrements')->will($this->returnValue('enable_qty_increments'));
$this->stockItemDoMock->expects($this->any())->method('getUseConfigQtyIncrements')->will($this->returnValue('use_config_qty_increments'));
$this->stockItemDoMock->expects($this->any())->method('getQtyIncrements')->will($this->returnValue('qty_increments'));
$this->duplicateMock->expects($this->once())->method('setStockData')->with($expectedData);
$this->model->build($this->productMock, $this->duplicateMock);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:CatalogInventoryTest.php
示例12: afterGetQuantityValidators
/**
* @param \Magento\Catalog\Block\Product\View $block
* @param array $validators
* @return array
*/
public function afterGetQuantityValidators(\Magento\Catalog\Block\Product\View $block, array $validators)
{
$stockItem = $this->stockRegistry->getStockItem($block->getProduct()->getId(), $block->getProduct()->getStore()->getWebsiteId());
$params = [];
$params['minAllowed'] = max((double) $stockItem->getQtyMinAllowed(), 1);
if ($stockItem->getQtyMaxAllowed()) {
$params['maxAllowed'] = $stockItem->getQtyMaxAllowed();
}
if ($stockItem->getQtyIncrements() > 0) {
$params['qtyIncrements'] = (double) $stockItem->getQtyIncrements();
}
$validators['validate-item-quantity'] = $params;
return $validators;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:19,代码来源:ProductView.php
示例13: testGetProductStockQty
/**
* Run test getProductStockQty method
*
* @return void
*/
public function testGetProductStockQty()
{
$productId = 10;
$websiteId = 99;
$qty = 100.0;
$productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', 'getStore'], [], '', false);
$storeMock = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId'], [], '', false);
$stockItemMock = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockItemInterface', [], '', false, true, true, ['getQty']);
$productMock->expects($this->once())->method('getId')->will($this->returnValue($productId));
$productMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
$storeMock->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
$this->stockRegistryMock->expects($this->once())->method('getStockItem')->with($productId, $websiteId)->will($this->returnValue($stockItemMock));
$stockItemMock->expects($this->once())->method('getQty')->will($this->returnValue($qty));
$this->assertEquals($qty, $this->_block->getProductStockQty($productMock));
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:MatrixTest.php
示例14: modifyData
/**
* {@inheritdoc}
*/
public function modifyData(array $data)
{
$fieldCode = 'quantity_and_stock_status';
$model = $this->locator->getProduct();
$modelId = $model->getId();
$stockItem = $this->stockRegistry->getStockItem($modelId, $model->getStore()->getWebsiteId());
$stockData = $stockItem->getData();
if (!empty($stockData)) {
$data[$modelId][self::DATA_SOURCE_DEFAULT][self::STOCK_DATA_FIELDS] = $stockData;
}
if (isset($stockData['is_in_stock'])) {
$data[$modelId][self::DATA_SOURCE_DEFAULT][$fieldCode]['is_in_stock'] = (int) $stockData['is_in_stock'];
}
return $this->prepareStockData($data);
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:18,代码来源:AdvancedInventory.php
示例15: getStockItem
/**
* Init stock item
*
* @param \Magento\Quote\Model\Quote\Item\Option $option
* @param \Magento\Quote\Model\Quote\Item $quoteItem
*
* @return \Magento\CatalogInventory\Model\Stock\Item
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getStockItem(\Magento\Quote\Model\Quote\Item\Option $option, \Magento\Quote\Model\Quote\Item $quoteItem)
{
$stockItem = $this->stockRegistry->getStockItem($option->getProduct()->getId(), $quoteItem->getStore()->getWebsiteId());
if (!$stockItem->getItemId()) {
throw new \Magento\Framework\Exception\LocalizedException(__('The stock item for Product in option is not valid.'));
}
/**
* define that stock item is child for composite product
*/
$stockItem->setIsChildItem(true);
/**
* don't check qty increments value for option product
*/
$stockItem->setSuppressCheckQtyIncrements(true);
return $stockItem;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:25,代码来源:Option.php
示例16: testSaveInventoryData
public function testSaveInventoryData()
{
$productId = 4;
$websiteId = 5;
$stockData = null;
$websitesChanged = true;
$statusChanged = true;
$product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getStockData', 'getIsChangedWebsites', 'dataHasChangedFor', 'getId', 'getStore', '__wakeup'], [], '', false);
$product->expects($this->once())->method('getStockData')->will($this->returnValue($stockData));
if ($stockData === null) {
$product->expects($this->any())->method('getIsChangedWebsites')->will($this->returnValue($websitesChanged));
$product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue($statusChanged));
if ($websitesChanged || $statusChanged) {
$product->expects($this->once())->method('getId')->will($this->returnValue($productId));
$store = $this->getMock('Magento\\Store\\Model\\Store', ['getWebsiteId', '__wakeup'], [], '', false);
$store->expects($this->once())->method('getWebsiteId')->will($this->returnValue($websiteId));
$product->expects($this->once())->method('getStore')->will($this->returnValue($store));
$this->stockIndex->expects($this->once())->method('rebuild')->will($this->returnValue(true));
}
} else {
$stockItem = $this->getMockForAbstractClass('Magento\\CatalogInventory\\Api\\Data\\StockItem', ['__wakeup'], '', false);
$this->stockRegistry->expects($this->once())->method('getStockItem')->with($productId, $websiteId)->will($this->returnValue($stockItem));
}
$this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product));
$this->eventObserver->expects($this->atLeastOnce())->method('getEvent')->will($this->returnValue($this->event));
$this->assertEquals($this->observer, $this->observer->saveInventoryData($this->eventObserver));
}
开发者ID:,项目名称:,代码行数:27,代码来源:
示例17: testAfterGetQuantityValidators
public function testAfterGetQuantityValidators()
{
$result = ['validate-item-quantity' => ['minAllowed' => 2, 'maxAllowed' => 5, 'qtyIncrements' => 3]];
$validators = [];
$productViewBlock = $this->getMockBuilder('Magento\\Catalog\\Block\\Product\\View')->disableOriginalConstructor()->getMock();
$productMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId', 'getStore'])->getMock();
$storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['getWebsiteId', '_wakeup'])->getMock();
$productViewBlock->expects($this->any())->method('getProduct')->willReturn($productMock);
$productMock->expects($this->once())->method('getId')->willReturn('productId');
$productMock->expects($this->once())->method('getStore')->willReturn($storeMock);
$storeMock->expects($this->once())->method('getWebsiteId')->willReturn('websiteId');
$this->stockRegistry->expects($this->once())->method('getStockItem')->with('productId', 'websiteId')->willReturn($this->stockItem);
$this->stockItem->expects($this->once())->method('getQtyMinAllowed')->willReturn(2);
$this->stockItem->expects($this->any())->method('getQtyMaxAllowed')->willReturn(5);
$this->stockItem->expects($this->any())->method('getQtyIncrements')->willReturn(3);
$this->assertEquals($result, $this->block->afterGetQuantityValidators($productViewBlock, $validators));
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:ProductViewTest.php
示例18: getStockId
/**
* Retrieve stock identifier
*
* @return int
*/
public function getStockId()
{
$stockId = $this->getData(static::STOCK_ID);
if ($stockId === null) {
$stockId = $this->stockRegistry->getStock($this->getWebsiteId())->getStockId();
}
return (int) $stockId;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Item.php
示例19: isItemAvailableForReorder
/**
* Check item product availability for reorder
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @return boolean
*/
protected function isItemAvailableForReorder(\Magento\Sales\Model\Order\Item $orderItem)
{
try {
$stockItem = $this->stockRegistry->getStockItem($orderItem->getProduct()->getId(), $orderItem->getStore()->getWebsiteId());
return $stockItem->getIsInStock();
} catch (\Magento\Framework\Exception\NoSuchEntityException $noEntityException) {
return false;
}
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:LastOrderedItems.php
示例20: testUpdateStockItemBySku
public function testUpdateStockItemBySku()
{
$itemId = 1;
$this->stockItem->expects($this->once())->method('setProductId')->willReturnSelf();
$this->stockItem->expects($this->once())->method('getData')->willReturn([]);
$this->stockItem->expects($this->once())->method('addData')->willReturnSelf();
$this->stockItem->expects($this->atLeastOnce())->method('getItemId')->willReturn($itemId);
$this->assertEquals($itemId, $this->stockRegistry->updateStockItemBySku($this->productSku, $this->stockItem));
}
开发者ID:,项目名称:,代码行数:9,代码来源:
注:本文中的Magento\CatalogInventory\Api\StockRegistryInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论