Beispiel #1
0
 /**
  * Returns options adopted to compare
  *
  * @param Item $item
  * @return array
  */
 public function getOptions(Item $item)
 {
     $options = [];
     foreach ($item->getOptions() as $option) {
         $options[$option->getCode()] = $this->getOptionValues($option->getValue());
     }
     return $options;
 }
Beispiel #2
0
 /**
  * @param $baseRowTotalInclTax
  * @param $baseRowWeeeTaxInclTax
  * @param $weeeEnabled
  * @param $expectedValue
  * @dataProvider testGetFinalDisplayPriceDataProvider
  */
 public function testGetBaseFinalRowDisplayPriceInclTax($baseRowTotalInclTax, $baseRowWeeeTaxInclTax, $weeeEnabled, $expectedValue)
 {
     $this->weeeHelper->expects($this->once())->method('isEnabled')->will($this->returnValue($weeeEnabled));
     $this->weeeHelper->expects($this->any())->method('getBaseRowWeeeTaxInclTax')->with($this->item)->will($this->returnValue($baseRowWeeeTaxInclTax));
     $this->item->expects($this->once())->method('getBaseRowTotalInclTax')->will($this->returnValue($baseRowTotalInclTax));
     $this->assertEquals($expectedValue, $this->renderer->getBaseFinalRowDisplayPriceInclTax());
 }
Beispiel #3
0
 /**
  * Initialize item option
  *
  * @param \Magento\Sales\Model\Quote\Item\Option $option
  * @param \Magento\Sales\Model\Quote\Item $quoteItem
  * @param int $qty
  *
  * @return \Magento\Framework\Object
  * @throws \Magento\Framework\Model\Exception
  */
 public function initialize(\Magento\Sales\Model\Quote\Item\Option $option, \Magento\Sales\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 = $stockItem->checkQuoteItemQty($optionQty, $qtyForCheck, $optionValue);
     if (!is_null($result->getItemIsQtyDecimal())) {
         $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 (!is_null($result->getMessage())) {
         $option->setMessage($result->getMessage());
         $quoteItem->setMessage($result->getMessage());
     }
     if (!is_null($result->getItemBackorders())) {
         $option->setBackorders($result->getItemBackorders());
     }
     $stockItem->unsIsChildItem();
     return $result;
 }
 public function testInitTotalsNoItems()
 {
     $address = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Address', [], [], '', false);
     $this->item->expects($this->never())->method('getParentItemId');
     $this->model->init($this->model->getWebsiteId(), $this->model->getCustomerGroupId(), $this->model->getCouponCode());
     $this->model->initTotals([], $address);
 }
Beispiel #5
0
 /**
  * test compare two items first without options and second with options
  */
 public function testCompareItemWithoutOptionWithCompared()
 {
     $this->itemMock->expects($this->any())->method('getProductId')->will($this->returnValue(1));
     $this->comparedMock->expects($this->any())->method('getProductId')->will($this->returnValue(1));
     $this->comparedMock->expects($this->any())->method('getOptions')->will($this->returnValue([$this->getOptionMock('option-1', 1), $this->getOptionMock('option-2', 'option-value'), $this->getOptionMock('option-3', serialize(['value' => 'value-1', 'qty' => 2]))]));
     $this->itemMock->expects($this->any())->method('getOptions')->will($this->returnValue([]));
     $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock));
 }
Beispiel #6
0
 public function testGetTotalAmount()
 {
     $rowTotal = 100;
     $taxAmount = 10;
     $hiddenTaxAmount = 2;
     $discountAmount = 20;
     $weeeTaxAppliedRowAmount = 10;
     $expectedResult = $rowTotal + $taxAmount + $hiddenTaxAmount - $discountAmount + $weeeTaxAppliedRowAmount;
     $this->itemMock->expects($this->once())->method('getRowTotal')->will($this->returnValue($rowTotal));
     $this->itemMock->expects($this->once())->method('getTaxAmount')->will($this->returnValue($taxAmount));
     $this->itemMock->expects($this->once())->method('getHiddenTaxAmount')->will($this->returnValue($hiddenTaxAmount));
     $this->itemMock->expects($this->once())->method('getDiscountAmount')->will($this->returnValue($discountAmount));
     $this->itemMock->expects($this->once())->method('getWeeeTaxAppliedRowAmount')->will($this->returnValue($weeeTaxAppliedRowAmount));
     $this->assertEquals($expectedResult, $this->block->getTotalAmount($this->itemMock));
 }
Beispiel #7
0
 public function testRemoveErrorInfosByParamsAllErrorsRemoved()
 {
     $message = "message";
     $message2 = "message2";
     $this->errorInfos->expects($this->at(0))->method('addItem')->with(null, null, $message);
     $this->errorInfos->expects($this->at(1))->method('addItem')->with(null, null, $message2);
     $this->assertEquals($this->model, $this->model->addErrorInfo(null, null, $message));
     $this->assertEquals($this->model, $this->model->addErrorInfo(null, null, $message2));
     $this->assertEquals($message . "\n" . $message2, $this->model->getMessage());
     $params = [];
     $removedItems = [['message' => $message], ['message' => $message2]];
     $this->errorInfos->expects($this->once())->method('removeItemsByParams')->with($params)->will($this->returnValue($removedItems));
     $this->errorInfos->expects($this->once())->method('getItems')->will($this->returnValue([]));
     $this->assertEquals($this->model, $this->model->removeErrorInfosByParams($params));
     $this->assertFalse($this->model->getHasError());
     $this->assertEquals('', $this->model->getMessage());
 }
Beispiel #8
0
 /**
  * Set quote item
  *
  * @param   \Magento\Sales\Model\Quote\Item $item
  * @return $this
  */
 public function setItem($item)
 {
     $this->setItemId($item->getId());
     $this->_item = $item;
     return $this;
 }
Beispiel #9
0
 /**
  * Add error to Quote Item
  *
  * @param \Magento\Sales\Model\Quote\Item $item
  * @param string $itemError
  * @param string $quoteError
  * @param string $errorIndex
  * @return $this
  */
 protected function _addQuoteItemError(\Magento\Sales\Model\Quote\Item $item, $itemError, $quoteError, $errorIndex = 'error')
 {
     $item->setHasError(true);
     $item->setMessage($itemError);
     $item->setQuoteMessage($quoteError);
     $item->setQuoteMessageIndex($errorIndex);
     return $this;
 }
Beispiel #10
0
 /**
  * Returns whether moving to wishlist is allowed for this item
  *
  * @param Item $item
  * @return bool
  */
 public function isMoveToWishlistAllowed($item)
 {
     return $item->getProduct()->isVisibleInSiteVisibility();
 }
Beispiel #11
0
 /**
  * Prepare options array for info buy request
  *
  * @param \Magento\Sales\Model\Quote\Item $item
  * @return array
  */
 protected function _prepareOptionsForRequest($item)
 {
     $newInfoOptions = array();
     $optionIds = $item->getOptionByCode('option_ids');
     if ($optionIds) {
         foreach (explode(',', $optionIds->getValue()) as $optionId) {
             $option = $item->getProduct()->getOptionById($optionId);
             $optionValue = $item->getOptionByCode('option_' . $optionId)->getValue();
             $group = $this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Option')->groupFactory($option->getType())->setOption($option)->setQuoteItem($item);
             $newInfoOptions[$optionId] = $group->prepareOptionValueForRequest($optionValue);
         }
     }
     return $newInfoOptions;
 }
Beispiel #12
0
 /**
  * Adds stock item qty to $items (creates new entry or increments existing one)
  * $items is array with following structure:
  * array(
  *  $productId  => array(
  *      'qty'   => $qty,
  *      'item'  => $stockItems|null
  *  )
  * )
  *
  * @param QuoteItem $quoteItem
  * @param array &$items
  * @return void
  */
 protected function _addItemToQtyArray($quoteItem, &$items)
 {
     $productId = $quoteItem->getProductId();
     if (!$productId) {
         return;
     }
     if (isset($items[$productId])) {
         $items[$productId]['qty'] += $quoteItem->getTotalQty();
     } else {
         $stockItem = null;
         if ($quoteItem->getProduct()) {
             /** @var Item $stockItem */
             $stockItem = $this->stockItemRegistry->retrieve($quoteItem->getProduct()->getId());
         }
         $items[$productId] = array('item' => $stockItem, 'qty' => $quoteItem->getTotalQty());
     }
 }
Beispiel #13
0
 /**
  * Get post parameters for delete from cart
  *
  * @param \Magento\Sales\Model\Quote\Item $item
  * @return string
  */
 public function getDeletePostJson($item)
 {
     $url = $this->_getUrl(self::DELETE_URL);
     $data = ['id' => $item->getId()];
     if (!$this->_request->isAjax()) {
         $data[\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED] = $this->getCurrentBase64Url();
     }
     return json_encode(array('action' => $url, 'data' => $data));
 }
Beispiel #14
0
 /**
  * @param \Magento\Sales\Model\Quote\Item $quoteItem
  * @return $this
  */
 public function importQuoteItem(\Magento\Sales\Model\Quote\Item $quoteItem)
 {
     $this->_quote = $quoteItem->getQuote();
     $this->setQuoteItem($quoteItem)->setQuoteItemId($quoteItem->getId())->setProductId($quoteItem->getProductId())->setProduct($quoteItem->getProduct())->setSku($quoteItem->getSku())->setName($quoteItem->getName())->setDescription($quoteItem->getDescription())->setWeight($quoteItem->getWeight())->setPrice($quoteItem->getPrice())->setCost($quoteItem->getCost());
     if (!$this->hasQty()) {
         $this->setQty($quoteItem->getQty());
     }
     $this->setQuoteItemImported(true);
     return $this;
 }
Beispiel #15
0
 /**
  * Retrieve url for remove product from cart
  *
  * @param   \Magento\Sales\Model\Quote\Item $item
  * @return  string
  */
 public function getRemoveUrl($item)
 {
     $params = array('id' => $item->getId(), \Magento\Framework\App\Action\Action::PARAM_NAME_BASE64_URL => $this->getCurrentBase64Url());
     return $this->_getUrl('checkout/cart/delete', $params);
 }
Beispiel #16
0
 /**
  * Set parent item
  *
  * @param  Item $parentItem
  * @return $this
  */
 public function setParentItem($parentItem)
 {
     if ($parentItem) {
         $this->_parentItem = $parentItem;
         $parentItem->addChild($this);
     }
     return $this;
 }
Beispiel #17
0
 /**
  * Retrieve product identifier linked with item
  *
  * @param \Magento\Sales\Model\Quote\Item $item
  * @return int
  */
 public function getProductId($item)
 {
     return $item->getProduct()->getId();
 }
Beispiel #18
0
 /**
  * Unset custom_price data for quote item
  *
  * @param Item $item
  * @return void
  */
 protected function unsetCustomPrice(Item $item)
 {
     /** @var \Magento\Framework\Object $infoBuyRequest */
     $infoBuyRequest = $item->getBuyRequest();
     if ($infoBuyRequest->hasData('custom_price')) {
         $infoBuyRequest->unsetData('custom_price');
         $infoBuyRequest->setValue(serialize($infoBuyRequest->getData()));
         $infoBuyRequest->setCode('info_buyRequest');
         $infoBuyRequest->setProduct($item->getProduct());
         $item->addOption($infoBuyRequest);
     }
     $item->unsetData('custom_price');
     $item->unsetData('original_custom_price');
 }
Beispiel #19
0
 /**
  * Verify that correct fields of item has been set
  *
  * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Sales\Model\Quote\Item $item
  * @param $itemData
  */
 public function verifyItem(\Magento\Sales\Model\Quote\Item $item, $itemData)
 {
     foreach ($itemData as $key => $value) {
         $this->assertEquals($value, $item->getData($key), 'item ' . $key . ' is incorrect');
     }
 }
Beispiel #20
0
 /**
  * Adding new item to quote
  *
  * @param   \Magento\Sales\Model\Quote\Item $item
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 public function addItem(\Magento\Sales\Model\Quote\Item $item)
 {
     /**
      * Temporary workaround for purchase process: it is too dangerous to purchase more than one nominal item
      * or a mixture of nominal and non-nominal items, although technically possible.
      *
      * The problem is that currently it is implemented as sequential submission of nominal items and order,
      * by one click. It makes logically impossible to make the process of the purchase failsafe.
      * Proper solution is to submit items one by one with customer confirmation each time.
      */
     if ($item->isNominal() && $this->hasItems() || $this->hasNominalItems()) {
         throw new \Magento\Framework\Model\Exception(__('Sorry, but items with payment agreements must be ordered one at a time To continue, please remove or buy the other items in your cart, then order this item by itself.'));
     }
     $item->setQuote($this);
     if (!$item->getId()) {
         $this->getItemsCollection()->addItem($item);
         $this->_eventManager->dispatch('sales_quote_add_item', array('quote_item' => $item));
     }
     return $this;
 }
Beispiel #21
0
 /**
  * Set store_id value to quote item
  *
  * @param Item $item
  * @return void
  */
 protected function setItemStoreId(Item $item)
 {
     if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
         $storeId = $this->storeManager->getStore($this->storeManager->getStore()->getId())->getId();
         $item->setStoreId($storeId);
     } else {
         $item->setStoreId($this->storeManager->getStore()->getId());
     }
 }
Beispiel #22
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;
 }
Beispiel #23
0
 /**
  * Remove item
  *
  * @param Address $address
  * @param  AddressItem|Item $item
  * @return $this
  */
 protected function _removeItem($address, $item)
 {
     if ($item instanceof Item) {
         $address->removeItem($item->getId());
         if ($address->getQuote()) {
             $address->getQuote()->removeItem($item->getId());
         }
     } elseif ($item instanceof AddressItem) {
         $address->removeItem($item->getId());
         if ($address->getQuote()) {
             $address->getQuote()->removeItem($item->getQuoteItemId());
         }
     }
     return $this;
 }
Beispiel #24
0
 /**
  * Removes error statuses from quote and item, set by this observer
  *
  * @param \Magento\Sales\Model\Quote\Item $item
  * @param int $code
  * @return void
  */
 protected function _removeErrorsFromQuoteAndItem($item, $code)
 {
     if ($item->getHasError()) {
         $params = array('origin' => 'cataloginventory', 'code' => $code);
         $item->removeErrorInfosByParams($params);
     }
     $quote = $item->getQuote();
     $quoteItems = $quote->getItemsCollection();
     $canRemoveErrorFromQuote = true;
     foreach ($quoteItems as $quoteItem) {
         if ($quoteItem->getItemId() == $item->getItemId()) {
             continue;
         }
         $errorInfos = $quoteItem->getErrorInfos();
         foreach ($errorInfos as $errorInfo) {
             if ($errorInfo['code'] == $code) {
                 $canRemoveErrorFromQuote = false;
                 break;
             }
         }
         if (!$canRemoveErrorFromQuote) {
             break;
         }
     }
     if ($quote->getHasError() && $canRemoveErrorFromQuote) {
         $params = array('origin' => 'cataloginventory', 'code' => $code);
         $quote->removeErrorInfosByParams(null, $params);
     }
 }