Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Indexer\Fulltext\Datasource\InventoryData::loadInventoryData PHP Метод

loadInventoryData() публичный Метод

Load inventory data for a list of product ids and a given store.
public loadInventoryData ( integer $storeId, array $productIds ) : array
$storeId integer Store id.
$productIds array Product ids list.
Результат 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);
    }

Usage Example

Пример #1
0
 /**
  * Add inventory data to the index data.
  * {@inheritdoc}
  */
 public function addData($storeId, array $indexData)
 {
     $inventoryData = $this->resourceModel->loadInventoryData($storeId, array_keys($indexData));
     foreach ($inventoryData as $inventoryDataRow) {
         $productId = (int) $inventoryDataRow['product_id'];
         $indexData[$productId]['stock'] = ['is_in_stock' => (bool) $inventoryDataRow['stock_status'], 'qty' => (int) $inventoryDataRow['qty']];
     }
     return $indexData;
 }