本文整理汇总了PHP中Magento\CatalogInventory\Api\StockConfigurationInterface::getDefaultWebsiteId方法的典型用法代码示例。如果您正苦于以下问题:PHP StockConfigurationInterface::getDefaultWebsiteId方法的具体用法?PHP StockConfigurationInterface::getDefaultWebsiteId怎么用?PHP StockConfigurationInterface::getDefaultWebsiteId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\CatalogInventory\Api\StockConfigurationInterface
的用法示例。
在下文中一共展示了StockConfigurationInterface::getDefaultWebsiteId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProductStockStatusBySku
/**
* @param string $productSku
* @param null $websiteId
* @return int
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getProductStockStatusBySku($productSku, $websiteId = null)
{
//if (!$websiteId) {
$websiteId = $this->stockConfiguration->getDefaultWebsiteId();
//}
$productId = $this->resolveProductId($productSku);
return $this->getProductStockStatus($productId, $websiteId);
}
示例2: checkQuoteItemQty
/**
* @param int $productId
* @param float $itemQty
* @param float $qtyToCheck
* @param float $origQty
* @param int $websiteId
* @return \Magento\Framework\Object
*/
public function checkQuoteItemQty($productId, $itemQty, $qtyToCheck, $origQty, $websiteId = null)
{
if ($websiteId === null) {
$websiteId = $this->stockConfiguration->getDefaultWebsiteId();
}
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
return $this->stockStateProvider->checkQuoteItemQty($stockItem, $itemQty, $qtyToCheck, $origQty);
}
示例3: getWebsiteId
/**
* Retrieve Website Id
*
* @return int
*/
public function getWebsiteId()
{
$websiteId = $this->getData(static::WEBSITE_ID);
if ($websiteId === null) {
$websiteId = $this->stockConfiguration->getDefaultWebsiteId();
}
return (int) $websiteId;
}
示例4: 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->getDefaultWebsiteId();
}
$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;
}
示例5: backItemQty
/**
* Get back to stock (when order is canceled or whatever else)
*
* @param int $productId
* @param float $qty
* @param int $websiteId
* @return bool
*/
public function backItemQty($productId, $qty, $websiteId = null)
{
//if (!$websiteId) {
$websiteId = $this->stockConfiguration->getDefaultWebsiteId();
//}
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
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;
}
示例6: _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;
}