public function beforeProcess()
 {
     $stockItem = $this->getEventObserver()->getData('object');
     if (!$stockItem instanceof \Magento\CatalogInventory\Model\Stock\Item) {
         throw new \Ess\M2ePro\Model\Exception('StockItem event doesn\'t have correct StockItem instance.');
     }
     $this->stockItem = $stockItem;
     $this->stockItemId = (int) $this->stockItem->getId();
     $this->storeId = (int) $this->stockItem->getData('store_id');
 }
Example #2
0
 public function testSetProduct()
 {
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', 'getName', 'getStoreId', 'getTypeId', 'dataHasChangedFor', 'getIsChangedWebsites', '__wakeup'], [], '', false);
     $productId = 2;
     $productName = 'Some Name';
     $storeId = 3;
     $typeId = 'simple';
     $status = 1;
     $isChangedWebsites = false;
     $product->expects($this->once())->method('getId')->will($this->returnValue($productId));
     $product->expects($this->once())->method('getName')->will($this->returnValue($productName));
     $product->expects($this->once())->method('getStoreId')->will($this->returnValue($storeId));
     $product->expects($this->once())->method('getTypeId')->will($this->returnValue($typeId));
     $product->expects($this->once())->method('dataHasChangedFor')->with($this->equalTo('status'))->will($this->returnValue($status));
     $product->expects($this->once())->method('getIsChangedWebsites')->will($this->returnValue($isChangedWebsites));
     $this->assertSame($this->item, $this->item->setProduct($product));
     $this->assertSame(['product_id' => 2, 'product_type_id' => 'simple', 'product_name' => 'Some Name', 'product_status_changed' => 1, 'product_changed_websites' => false], $this->item->getData());
 }
 /**
  * Disable resolving for absent $stockId.
  *
  * @param \Magento\CatalogInventory\Model\Stock\Item $subject
  * @param \Closure $proceed
  * @return mixed
  */
 public function aroundGetStockId(\Magento\CatalogInventory\Model\Stock\Item $subject, \Closure $proceed)
 {
     $result = $subject->getData(Cfg::E_CATINV_STOCK_ITEM_A_STOCK_ID);
     return $result;
 }