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
 /**
  * Getter for customer group id, return default group if not set
  *
  * @return int
  */
 public function getCustomerGroupId()
 {
     if ($this->customerGroupId === null) {
         return $this->groupManagement->getAllCustomersGroup()->getId();
     }
     return parent::getCustomerGroupId();
 }
Example #3
0
 public function testProcessIsInStock()
 {
     $this->item->setData(['qty' => 100, 'is_in_stock' => \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK, 'manage_stock' => 1, 'use_config_manage_stock' => 0]);
     $this->item->setData('qty', 0);
     $this->item->processIsInStock();
     $this->assertEquals(\Magento\CatalogInventory\Model\Stock\Status::STATUS_OUT_OF_STOCK, $this->item->getIsInStock());
 }
Example #4
0
 /**
  * Getter for customer group id, return default group if not set
  *
  * @return int
  */
 public function getCustomerGroupId()
 {
     if ($this->_customerGroupId === null) {
         return \Magento\Customer\Service\V1\CustomerGroupServiceInterface::CUST_GROUP_ALL;
     }
     return parent::getCustomerGroupId();
 }
Example #5
0
 public function testGetLowStockDate()
 {
     // ensure we do *not* return '2015' due to casting to an int
     $date = '2015-4-17';
     $this->item->setLowStockDate($date);
     $this->assertEquals($date, $this->item->getLowStockDate());
 }
Example #6
0
 /**
  * @param int $storeId
  * @param int $expected
  * @dataProvider getStoreIdDataProvider
  */
 public function testGetStoreId($storeId, $expected)
 {
     if ($storeId) {
         $property = new \ReflectionProperty($this->item, 'storeId');
         $property->setAccessible(true);
         $property->setValue($this->item, $storeId);
     }
     $this->assertSame($expected, $this->item->getStoreId());
 }
Example #7
0
 /**
  * @param array $config
  * @param mixed $expected
  * @dataProvider getQtyIncrementsDataProvider(
  */
 public function testGetQtyIncrements($config, $expected)
 {
     $this->setDataArrayValue('qty_increments', $config['qty_increments']);
     $this->setDataArrayValue('enable_qty_increments', $config['enable_qty_increments']);
     $this->setDataArrayValue('use_config_qty_increments', $config['use_config_qty_increments']);
     if ($config['use_config_qty_increments']) {
         $this->stockConfiguration->expects($this->once())->method('getQtyIncrements')->with($this->storeId)->willReturn($config['qty_increments']);
     } else {
         $this->setDataArrayValue('qty_increments', $config['qty_increments']);
     }
     $this->assertEquals($expected, $this->item->getQtyIncrements());
 }
Example #8
0
 /**
  * Initialize stock item
  *
  * @param \Magento\CatalogInventory\Model\Stock\Item $stockItem
  * @param \Magento\Sales\Model\Quote\Item $quoteItem
  * @param int $qty
  *
  * @return \Magento\Framework\Object
  * @throws \Magento\Framework\Model\Exception
  */
 public function initialize(\Magento\CatalogInventory\Model\Stock\Item $stockItem, \Magento\Sales\Model\Quote\Item $quoteItem, $qty)
 {
     /**
      * When we work with subitem
      */
     if ($quoteItem->getParentItem()) {
         $rowQty = $quoteItem->getParentItem()->getQty() * $qty;
         /**
          * we are using 0 because original qty was processed
          */
         $qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), 0);
     } else {
         $increaseQty = $quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty;
         $rowQty = $qty;
         $qtyForCheck = $this->quoteItemQtyList->getQty($quoteItem->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseQty);
     }
     $productTypeCustomOption = $quoteItem->getProduct()->getCustomOption('product_type');
     if (!is_null($productTypeCustomOption)) {
         // Check if product related to current item is a part of product that represents product set
         if ($this->typeConfig->isProductSet($productTypeCustomOption->getValue())) {
             $stockItem->setProductName($quoteItem->getProduct()->getName());
             $stockItem->setIsChildItem(true);
         }
     }
     $result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty);
     if ($stockItem->hasIsChildItem()) {
         $stockItem->unsIsChildItem();
     }
     if (!is_null($result->getItemIsQtyDecimal())) {
         $quoteItem->setIsQtyDecimal($result->getItemIsQtyDecimal());
         if ($quoteItem->getParentItem()) {
             $quoteItem->getParentItem()->setIsQtyDecimal($result->getItemIsQtyDecimal());
         }
     }
     /**
      * Just base (parent) item qty can be changed
      * qty of child products are declared just during add process
      * exception for updating also managed by product type
      */
     if ($result->getHasQtyOptionUpdate() && (!$quoteItem->getParentItem() || $quoteItem->getParentItem()->getProduct()->getTypeInstance()->getForceChildItemQtyChanges($quoteItem->getParentItem()->getProduct()))) {
         $quoteItem->setData('qty', $result->getOrigQty());
     }
     if (!is_null($result->getItemUseOldQty())) {
         $quoteItem->setUseOldQty($result->getItemUseOldQty());
     }
     if (!is_null($result->getMessage())) {
         $quoteItem->setMessage($result->getMessage());
     }
     if (!is_null($result->getItemBackorders())) {
         $quoteItem->setBackorders($result->getItemBackorders());
     }
     return $result;
 }
 /**
  * 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;
 }
Example #10
0
 /**
  * @magentoConfigFixture current_store cataloginventory/item_options/enable_qty_increments 1
  */
 public function testSetGetEnableQtyIncrements()
 {
     $this->assertFalse($this->_model->getEnableQtyIncrements());
     $this->_model->setUseConfigEnableQtyInc(true);
     $this->assertTrue($this->_model->getEnableQtyIncrements());
 }