コード例 #1
0
ファイル: Collection.php プロジェクト: pavelnovitsky/magento2
 /**
  * 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;
 }
コード例 #2
0
ファイル: Crosssell.php プロジェクト: aiesh/magento2
 /**
  * Get crosssell products collection
  *
  * @return \Magento\Catalog\Model\Resource\Product\Link\Product\Collection
  */
 protected function _getCollection()
 {
     /** @var \Magento\Catalog\Model\Resource\Product\Link\Product\Collection $collection */
     $collection = $this->_productLinkFactory->create()->useCrossSellLinks()->getProductCollection()->setStoreId($this->_storeManager->getStore()->getId())->addStoreFilter()->setPageSize($this->_maxItemCount)->setVisibility($this->_productVisibility->getVisibleInCatalogIds());
     $this->_addProductAttributesAndPrices($collection);
     $this->_stock->addInStockFilterToCollection($collection);
     return $collection;
 }
コード例 #3
0
ファイル: Observer.php プロジェクト: Atlis/docker-magento2
 /**
  * Cancel order item
  *
  * @param   EventObserver $observer
  * @return  $this
  */
 public function cancelOrderItem($observer)
 {
     $item = $observer->getEvent()->getItem();
     $children = $item->getChildrenItems();
     $qty = $item->getQtyOrdered() - max($item->getQtyShipped(), $item->getQtyInvoiced()) - $item->getQtyCanceled();
     if ($item->getId() && $item->getProductId() && empty($children) && $qty) {
         $this->_stock->backItemQty($item->getProductId(), $qty);
     }
     $this->_priceIndexer->reindexRow($item->getProductId());
     return $this;
 }
コード例 #4
0
ファイル: Stock.php プロジェクト: aiesh/magento2
 /**
  * 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);
 }
コード例 #5
0
 /**
  * @covers \Magento\CatalogInventory\Model\Stock::getProductType
  */
 public function testGettingProductType()
 {
     $productId = 1;
     $qty = 1;
     $productType = 'simple';
     $stockItem = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\Stock\\Item')->disableOriginalConstructor()->getMock();
     $stockItem->expects($this->atLeastOnce())->method('loadByProduct')->with($productId)->will($this->returnSelf());
     $stockItem->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->stockItemFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($stockItem));
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $product->expects($this->atLeastOnce())->method('load')->with($productId);
     $product->expects($this->atLeastOnce())->method('getTypeId')->will($this->returnValue($productType));
     $this->productFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($product));
     $this->stockItemService->expects($this->once())->method('isQty')->with($productType);
     $this->model->backItemQty($productId, $qty);
 }