コード例 #1
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;
 }
コード例 #2
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);
 }