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


PHP StockConfigurationInterface::getDefaultScopeId方法代码示例

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


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

示例1: loadInventoryData

 /**
  * Load inventory data for a list of product ids and a given store.
  *
  * @param integer $storeId    Store id.
  * @param array   $productIds Product ids list.
  *
  * @return array
  */
 public function loadInventoryData($storeId, $productIds)
 {
     $websiteId = $this->getWebsiteId($storeId);
     $stockId = $this->getStockId($websiteId);
     $select = $this->getConnection()->select()->from(['ciss' => $this->getTable('cataloginventory_stock_status')], ['product_id', 'stock_status', 'qty'])->where('ciss.stock_id = ?', $stockId)->where('ciss.website_id = ?', $this->stockConfiguration->getDefaultScopeId())->where('ciss.product_id IN(?)', $productIds);
     return $this->getConnection()->fetchAll($select);
 }
开发者ID:smile-sa,项目名称:elasticsuite,代码行数:15,代码来源:InventoryData.php

示例2: getProductStockStatusBySku

 /**
  * @param string $productSku
  * @param null $scopeId
  * @return int
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function getProductStockStatusBySku($productSku, $scopeId = null)
 {
     //if (!$scopeId) {
     $scopeId = $this->stockConfiguration->getDefaultScopeId();
     //}
     $productId = $this->resolveProductId($productSku);
     return $this->getProductStockStatus($productId, $scopeId);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:StockRegistry.php

示例3: checkQuoteItemQty

 /**
  * @param int $productId
  * @param float $itemQty
  * @param float $qtyToCheck
  * @param float $origQty
  * @param int $scopeId
  * @return int
  */
 public function checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $scopeId = null)
 {
     if ($scopeId === null) {
         $scopeId = $this->stockConfiguration->getDefaultScopeId();
     }
     $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
     return $this->stockStateProvider->checkQuoteItemQty($stockItem, $itemQty, $qtyToCheck, $origQty);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:16,代码来源:StockState.php

示例4: getWebsiteId

 /**
  * Retrieve Website Id
  *
  * @return int
  */
 public function getWebsiteId()
 {
     $websiteId = $this->getData(static::WEBSITE_ID);
     if ($websiteId === null) {
         $websiteId = $this->stockConfiguration->getDefaultScopeId();
     }
     return (int) $websiteId;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:13,代码来源:Item.php

示例5: testReindexEntity

 /**
  * @magentoDataFixture Magento/Store/_files/website.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  *
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  */
 public function testReindexEntity()
 {
     /** @var \Magento\Catalog\Model\ProductRepository $productRepository */
     $productRepository = $this->getObject(\Magento\Catalog\Model\ProductRepository::class);
     /** @var \Magento\Store\Api\WebsiteRepositoryInterface $websiteRepository */
     $websiteRepository = $this->getObject(\Magento\Store\Api\WebsiteRepositoryInterface::class);
     $product = $productRepository->get('simple');
     $testWebsite = $websiteRepository->get('test');
     $product->setWebsiteIds([1, $testWebsite->getId()])->save();
     /** @var \Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory $criteriaFactory */
     $criteriaFactory = $this->getObject(\Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory::class);
     /** @var \Magento\CatalogInventory\Api\StockStatusRepositoryInterface $stockStatusRepository */
     $stockStatusRepository = $this->getObject(\Magento\CatalogInventory\Api\StockStatusRepositoryInterface::class);
     $criteria = $criteriaFactory->create();
     $criteria->setProductsFilter([$product->getId()]);
     $criteria->addFilter('website', 'website_id', $this->stockConfiguration->getDefaultScopeId());
     $items = $stockStatusRepository->getList($criteria)->getItems();
     $this->assertEquals($product->getId(), $items[$product->getId()]->getProductId());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:25,代码来源:DefaultStockTest.php

示例6: updateLowStockDate

 /**
  * Update items low stock date basing on their quantities and config settings
  *
  * @param int|string $website
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  * @return void
  */
 public function updateLowStockDate($website)
 {
     $websiteId = $this->stockConfiguration->getDefaultScopeId();
     $this->_initConfig();
     $connection = $this->getConnection();
     $condition = $connection->quoteInto('(use_config_notify_stock_qty = 1 AND qty < ?)', $this->_configNotifyStockQty) . ' OR (use_config_notify_stock_qty = 0 AND qty < notify_stock_qty)';
     $currentDbTime = $connection->quoteInto('?', $this->dateTime->gmtDate());
     $conditionalDate = $connection->getCheckSql($condition, $currentDbTime, 'NULL');
     $value = ['low_stock_date' => new \Zend_Db_Expr($conditionalDate)];
     $select = $connection->select()->from($this->getTable('catalog_product_entity'), 'entity_id')->where('type_id IN(?)', $this->_configTypeIds);
     $where = sprintf('website_id = %1$d' . ' AND ((use_config_manage_stock = 1 AND 1 = %2$d) OR (use_config_manage_stock = 0 AND manage_stock = 1))' . ' AND product_id IN (%3$s)', $websiteId, $this->_isConfigManageStock, $select->assemble());
     $connection->update($this->getTable('cataloginventory_stock_item'), $value, $where);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:20,代码来源:Stock.php

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

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

示例9: backItemQty

 /**
  * Get back to stock (when order is canceled or whatever else)
  *
  * @param int $productId
  * @param float $qty
  * @param int $scopeId
  * @return bool
  */
 public function backItemQty($productId, $qty, $scopeId = null)
 {
     //if (!$scopeId) {
     $scopeId = $this->stockConfiguration->getDefaultScopeId();
     //}
     $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId);
     if ($stockItem->getItemId() && $this->stockConfiguration->isQty($this->getProductType($productId))) {
         if ($this->canSubtractQty($stockItem)) {
             $stockItem->setQty($stockItem->getQty() + $qty);
         }
         if ($this->stockConfiguration->getCanBackInStock($stockItem->getStoreId()) && $stockItem->getQty() > $stockItem->getMinQty()) {
             $stockItem->setIsInStock(true);
             $stockItem->setStockStatusChangedAutomaticallyFlag(true);
         }
         $stockItem->save();
     }
     return true;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:26,代码来源:StockManagement.php

示例10: _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->getDefaultScopeId();
             $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->dateTime->gmDate('Y-m-d H:i:s', (new \DateTime())->getTimestamp());
                 }
                 $row['stock_status_changed_auto'] = (int) (!$this->stockStateProvider->verifyStock($stockItemDo));
             } else {
                 $row['qty'] = 0;
             }
             if (!isset($stockData[$rowData[self::COL_SKU]])) {
                 $stockData[$rowData[self::COL_SKU]] = $row;
             }
         }
         // Insert rows
         if (!empty($stockData)) {
             $this->_connection->insertOnDuplicate($entityTable, array_values($stockData));
         }
         if ($productIdsToReindex) {
             $indexer->reindexList($productIdsToReindex);
         }
     }
     return $this;
 }
开发者ID:OlgaBurtyka,项目名称:m2,代码行数:51,代码来源:Product.php


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