当前位置: 首页>>代码示例>>PHP>>正文


PHP StockRegistryInterface::getStock方法代码示例

本文整理汇总了PHP中Magento\CatalogInventory\Api\StockRegistryInterface::getStock方法的典型用法代码示例。如果您正苦于以下问题:PHP StockRegistryInterface::getStock方法的具体用法?PHP StockRegistryInterface::getStock怎么用?PHP StockRegistryInterface::getStock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\CatalogInventory\Api\StockRegistryInterface的用法示例。


在下文中一共展示了StockRegistryInterface::getStock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: saveStockItemData

 /**
  * Prepare stock item data for save
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return $this
  */
 protected function saveStockItemData($product)
 {
     $stockItemData = $product->getStockData();
     $stockItemData['product_id'] = $product->getId();
     if (!isset($stockItemData['website_id'])) {
         $stockItemData['website_id'] = $this->stockConfiguration->getDefaultScopeId();
     }
     $stockItemData['stock_id'] = $this->stockRegistry->getStock($stockItemData['website_id'])->getStockId();
     foreach ($this->paramListToCheck as $dataKey => $configPath) {
         if (null !== $product->getData($configPath['item']) && null === $product->getData($configPath['config'])) {
             $stockItemData[$dataKey] = false;
         }
     }
     $originalQty = $product->getData('stock_data/original_inventory_qty');
     if (strlen($originalQty) > 0) {
         $stockItemData['qty_correction'] = (isset($stockItemData['qty']) ? $stockItemData['qty'] : 0) - $originalQty;
     }
     // todo resolve issue with builder and identity field name
     $stockItem = $this->stockRegistry->getStockItem($stockItemData['product_id'], $stockItemData['website_id']);
     $stockItem->addData($stockItemData);
     $this->stockItemRepository->save($stockItem);
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:29,代码来源:SaveInventoryDataObserver.php

示例4: validateStockItem

 /**
  * @param ProductInterface $product
  * @param StockItemInterface $stockItem
  * @throws LocalizedException
  * @return void
  */
 private function validateStockItem(ProductInterface $product, StockItemInterface $stockItem)
 {
     $defaultScopeId = $this->stockConfiguration->getDefaultScopeId();
     $defaultStockId = $this->stockRegistry->getStock($defaultScopeId)->getStockId();
     $stockId = $stockItem->getStockId();
     if ($stockId !== null && $stockId != $defaultStockId) {
         throw new LocalizedException(__('Invalid stock id: %1. Only default stock with id %2 allowed', $stockId, $defaultStockId));
     }
     $stockItemId = $stockItem->getItemId();
     if ($stockItemId !== null && (!is_numeric($stockItemId) || $stockItemId <= 0)) {
         throw new LocalizedException(__('Invalid stock item id: %1. Should be null or numeric value greater than 0', $stockItemId));
     }
     $defaultStockItemId = $this->stockRegistry->getStockItem($product->getId())->getItemId();
     if ($defaultStockItemId && $stockItemId !== null && $defaultStockItemId != $stockItemId) {
         throw new LocalizedException(__('Invalid stock item id: %1. Assigned stock item id is %2', $stockItemId, $defaultStockItemId));
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:23,代码来源:AroundProductRepositorySave.php

示例5: _saveStockItem

 /**
  * Stock item saving.
  *
  * @return $this
  */
 protected function _saveStockItem()
 {
     $indexer = $this->indexerRegistry->get('catalog_product_category');
     /** @var $stockResource \Magento\CatalogInventory\Model\ResourceModel\Stock\Item */
     $stockResource = $this->_stockResItemFac->create();
     $entityTable = $stockResource->getMainTable();
     while ($bunch = $this->_dataSourceModel->getNextBunch()) {
         $stockData = [];
         $productIdsToReindex = [];
         // Format bunch to stock data rows
         foreach ($bunch as $rowNum => $rowData) {
             if (!$this->isRowAllowedToImport($rowData, $rowNum)) {
                 continue;
             }
             $row = [];
             $row['product_id'] = $this->skuProcessor->getNewSku($rowData[self::COL_SKU])['entity_id'];
             $productIdsToReindex[] = $row['product_id'];
             $row['website_id'] = $this->stockConfiguration->getDefaultWebsiteId();
             $row['stock_id'] = $this->stockRegistry->getStock($row['website_id'])->getStockId();
             $stockItemDo = $this->stockRegistry->getStockItem($row['product_id'], $row['website_id']);
             $existStockData = $stockItemDo->getData();
             $row = array_merge($this->defaultStockData, array_intersect_key($existStockData, $this->defaultStockData), array_intersect_key($rowData, $this->defaultStockData), $row);
             if ($this->stockConfiguration->isQty($this->skuProcessor->getNewSku($rowData[self::COL_SKU])['type_id'])) {
                 $stockItemDo->setData($row);
                 $row['is_in_stock'] = $this->stockStateProvider->verifyStock($stockItemDo);
                 if ($this->stockStateProvider->verifyNotification($stockItemDo)) {
                     $row['low_stock_date'] = $this->_localeDate->date(null, null, false)->format('Y-m-d H:i:s');
                 }
                 $row['stock_status_changed_auto'] = (int) (!$this->stockStateProvider->verifyStock($stockItemDo));
             } else {
                 $row['qty'] = 0;
             }
             $stockData[] = $row;
         }
         // Insert rows
         if (!empty($stockData)) {
             $this->_connection->insertOnDuplicate($entityTable, $stockData);
         }
         if ($productIdsToReindex) {
             $indexer->reindexList($productIdsToReindex);
         }
     }
     return $this;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:49,代码来源:Product.php

示例6: testGetStock

 public function testGetStock()
 {
     $this->assertEquals($this->stock, $this->stockRegistry->getStock($this->websiteId));
 }
开发者ID:,项目名称:,代码行数:4,代码来源:


注:本文中的Magento\CatalogInventory\Api\StockRegistryInterface::getStock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。