Example #1
0
 public function testSetQtyUseOldQuantity()
 {
     $existingQuantity = 2;
     $quantityToAdd = 3;
     $preparedQuantityToAdd = 4;
     $this->localeFormat->expects($this->once())->method('getNumber')->with($quantityToAdd)->will($this->returnValue($preparedQuantityToAdd));
     $this->model->setData('qty', $existingQuantity);
     $this->model->setUseOldQty(true);
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with('sales_quote_item_qty_set_after', ['item' => $this->model]);
     $this->model->setQty($quantityToAdd);
     $this->assertEquals($existingQuantity, $this->model->getQty());
 }
 public function testApplyRulesThatAppliedRuleIdsAreCollected()
 {
     $positivePrice = 1;
     $ruleId1 = 123;
     $ruleId2 = 234;
     $expectedRuleIds = [$ruleId1 => $ruleId1, $ruleId2 => $ruleId2];
     $this->model->init($this->model->getWebsiteId(), $this->model->getCustomerGroupId(), $this->model->getCouponCode());
     $this->item->setDiscountCalculationPrice($positivePrice);
     $this->item->setData('calculation_price', $positivePrice);
     $this->model->setSkipActionsValidation(true);
     $this->rulesApplier->expects($this->once())->method('applyRules')->with($this->equalTo($this->item), $this->equalTo($this->ruleCollection), $this->anything(), $this->anything())->will($this->returnValue($expectedRuleIds));
     $this->rulesApplier->expects($this->once())->method('setAppliedRuleIds')->with($this->anything(), $expectedRuleIds);
     $this->model->process($this->item);
 }
Example #3
0
 /**
  * Set qty and custom price for quote item
  *
  * @param Item $item
  * @param \Magento\Framework\Object $request
  * @param Product $candidate
  * @return void
  */
 public function prepare(Item $item, Object $request, Product $candidate)
 {
     /**
      * We specify qty after we know about parent (for stock)
      */
     if ($request->getResetCount()) {
         $item->setData(CartItemInterface::KEY_QTY, 0);
     }
     $item->addQty($candidate->getCartQty());
     $customPrice = $request->getCustomPrice();
     if (!empty($customPrice)) {
         $item->setCustomPrice($customPrice);
         $item->setOriginalCustomPrice($customPrice);
     }
 }
 /**
  * Initialize stock item
  *
  * @param \Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem
  * @param \Magento\Quote\Model\Quote\Item $quoteItem
  * @param int $qty
  *
  * @return \Magento\Framework\DataObject
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function initialize(\Magento\CatalogInventory\Api\Data\StockItemInterface $stockItem, \Magento\Quote\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 ($productTypeCustomOption !== null) {
         // Check if product related to current item is a part of product that represents product set
         if ($this->typeConfig->isProductSet($productTypeCustomOption->getValue())) {
             $stockItem->setIsChildItem(true);
         }
     }
     $stockItem->setProductName($quoteItem->getProduct()->getName());
     $result = $this->stockState->checkQuoteItemQty($quoteItem->getProduct()->getId(), $rowQty, $qtyForCheck, $qty, $quoteItem->getProduct()->getStore()->getWebsiteId());
     if ($stockItem->hasIsChildItem()) {
         $stockItem->unsIsChildItem();
     }
     if ($result->getItemIsQtyDecimal() !== null) {
         $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 ($result->getItemUseOldQty() !== null) {
         $quoteItem->setUseOldQty($result->getItemUseOldQty());
     }
     if ($result->getMessage() !== null) {
         $quoteItem->setMessage($result->getMessage());
     }
     if ($result->getItemBackorders() !== null) {
         $quoteItem->setBackorders($result->getItemBackorders());
     }
     return $result;
 }