Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockStatusCriteriaMapper.php
Go to the documentation of this file.
1 <?php
8 
10 
16 {
20  protected function init()
21  {
22  $this->initResource(\Magento\CatalogInventory\Model\ResourceModel\Stock\Status::class);
23  }
24 
30  public function mapInitialCondition()
31  {
32  $this->getSelect()->join(
33  ['cp_table' => $this->getTable('catalog_product_entity')],
34  'main_table.product_id = cp_table.entity_id',
35  ['sku', 'type_id']
36  );
37  }
38 
45  public function mapWebsiteFilter($website)
46  {
47  if ($website instanceof \Magento\Store\Model\Website) {
48  $website = $website->getId();
49  }
50  $this->addFieldToFilter('main_table.website_id', $website);
51  }
52 
59  public function mapProductsFilter($products)
60  {
61  $productIds = [];
62  if (!is_array($products)) {
63  $products = [$products];
64  }
65  foreach ($products as $product) {
66  if ($product instanceof \Magento\Catalog\Model\Product) {
67  $productIds[] = $product->getId();
68  } else {
70  }
71  }
72  if (empty($productIds)) {
73  $productIds[] = false;
74  }
75  $this->addFieldToFilter('main_table.product_id', ['in' => $productIds]);
76  }
77 
84  public function mapQtyFilter($qty)
85  {
86  $this->addFieldToFilter('main_table.qty', ['lteq' => $qty]);
87  }
88 }
addFieldToFilter($field, $condition=null)