/** * Initialize item option * * @param \Magento\Quote\Model\Quote\Item\Option $option * @param \Magento\Quote\Model\Quote\Item $quoteItem * @param int $qty * * @return \Magento\Framework\Object * @throws \Magento\Framework\Exception\LocalizedException */ public function initialize(\Magento\Quote\Model\Quote\Item\Option $option, \Magento\Quote\Model\Quote\Item $quoteItem, $qty) { $optionValue = $option->getValue(); $optionQty = $qty * $optionValue; $increaseOptionQty = ($quoteItem->getQtyToAdd() ? $quoteItem->getQtyToAdd() : $qty) * $optionValue; $qtyForCheck = $this->quoteItemQtyList->getQty($option->getProduct()->getId(), $quoteItem->getId(), $quoteItem->getQuoteId(), $increaseOptionQty); $stockItem = $this->getStockItem($option, $quoteItem); $result = $this->stockState->checkQuoteItemQty($option->getProduct()->getId(), $optionQty, $qtyForCheck, $optionValue, $option->getProduct()->getStore()->getWebsiteId()); if ($result->getItemIsQtyDecimal() !== null) { $option->setIsQtyDecimal($result->getItemIsQtyDecimal()); } if ($result->getHasQtyOptionUpdate()) { $option->setHasQtyOptionUpdate(true); $quoteItem->updateQtyOption($option, $result->getOrigQty()); $option->setValue($result->getOrigQty()); /** * if option's qty was updates we also need to update quote item qty */ $quoteItem->setData('qty', intval($qty)); } if ($result->getMessage() !== null) { $option->setMessage($result->getMessage()); $quoteItem->setMessage($result->getMessage()); } if ($result->getItemBackorders() !== null) { $option->setBackorders($result->getItemBackorders()); } $stockItem->unsIsChildItem(); return $result; }
public function testExecuteBadSecretKey() { $this->itemOptionMock->expects($this->once())->method('load')->willReturnSelf(); $this->itemOptionMock->expects($this->once())->method('getId')->willReturn(self::OPTION_ID); $this->itemOptionMock->expects($this->any())->method('getCode')->willReturn(self::OPTION_CODE); $this->itemOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID); $this->itemOptionMock->expects($this->any())->method('getValue')->willReturn(self::OPTION_VALUE); $this->productOptionMock->expects($this->once())->method('load')->willReturnSelf(); $this->productOptionMock->expects($this->any())->method('getId')->willReturn(self::OPTION_ID); $this->productOptionMock->expects($this->any())->method('getProductId')->willReturn(self::OPTION_PRODUCT_ID); $this->productOptionMock->expects($this->any())->method('getType')->willReturn(self::OPTION_TYPE); $this->unserializeMock->expects($this->once())->method('unserialize')->with(self::OPTION_VALUE)->willReturn([self::SECRET_KEY => 'bad_test_secret_key']); $this->resultForwardMock->expects($this->once())->method('forward')->with('noroute')->willReturn(true); $this->objectMock->execute(); }
/** * Implementation of product specify logic of which product needs to be assigned to option. * For example if product which was added to option already removed from catalog. * * @param \Magento\Catalog\Model\Product|null $optionProduct * @param \Magento\Quote\Model\Quote\Item\Option $option * @param \Magento\Catalog\Model\Product|null $product * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function assignProductToOption($optionProduct, $option, $product) { if ($optionProduct) { $option->setProduct($optionProduct); } else { $option->getItem()->setHasConfigurationUnavailableError(true); } return $this; }
/** * Register option code * * @param \Magento\Quote\Model\Quote\Item\Option $option * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ protected function _addOptionCode($option) { if (!isset($this->_optionsByCode[$option->getCode()])) { $this->_optionsByCode[$option->getCode()] = $option; } else { throw new \Magento\Framework\Exception\LocalizedException(__('An item option with code %1 already exists.', $option->getCode())); } return $this; }
/** * Implementation of product specify logic of which product needs to be assigned to option. * For example if product which was added to option already removed from catalog. * * @param \Magento\Catalog\Model\Product $optionProduct * @param \Magento\Quote\Model\Quote\Item\Option $option * @param \Magento\Catalog\Model\Product $product * @return $this */ public function assignProductToOption($optionProduct, $option, $product) { if ($optionProduct) { $option->setProduct($optionProduct); } else { $option->setProduct($product); } return $this; }