/**
  * Add stock filter to collection
  *
  * @param Stock|string|array $stock
  * @return $this
  */
 public function addStockFilter($stock)
 {
     if ($stock instanceof Stock) {
         $this->addFieldToFilter('main_table.stock_id', $stock->getId());
     } else {
         $this->addFieldToFilter('main_table.stock_id', $stock);
     }
     return $this;
 }
Exemple #2
0
 /**
  * Update items low stock date basing on their quantities and config settings
  *
  * @return void
  */
 public function updateLowStockDate()
 {
     $this->_initConfig();
     $adapter = $this->_getWriteAdapter();
     $condition = $adapter->quoteInto('(use_config_notify_stock_qty = 1 AND qty < ?)', $this->_configNotifyStockQty) . ' OR (use_config_notify_stock_qty = 0 AND qty < notify_stock_qty)';
     $currentDbTime = $adapter->quoteInto('?', $this->dateTime->formatDate(true));
     $conditionalDate = $adapter->getCheckSql($condition, $currentDbTime, 'NULL');
     $value = array('low_stock_date' => new \Zend_Db_Expr($conditionalDate));
     $select = $adapter->select()->from($this->getTable('catalog_product_entity'), 'entity_id')->where('type_id IN(?)', $this->_configTypeIds);
     $where = sprintf('stock_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)', $this->_stock->getId(), $this->_isConfigManageStock, $select->assemble());
     $adapter->update($this->getTable('cataloginventory_stock_item'), $value, $where);
 }