public function testGetMaximumQty() { $maximumQty = 10; $this->scopeConfigMock->expects($this->once())->method('getValue')->with(\Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY)->will($this->returnValue($maximumQty)); $this->assertEquals($maximumQty, $this->helper->getMaximumQty()); }
/** * Assign quote items to addresses and specify items qty * * array structure: * array( * $quoteItemId => array( * 'qty' => $qty, * 'address' => $customerAddressId * ) * ) * * @param array $info * @return \Magento\Multishipping\Model\Checkout\Type\Multishipping * @throws \Magento\Framework\Exception\LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function setShippingItemsInformation($info) { if (is_array($info)) { $allQty = 0; $itemsInfo = []; foreach ($info as $itemData) { foreach ($itemData as $quoteItemId => $data) { $allQty += $data['qty']; $itemsInfo[$quoteItemId] = $data; } } $maxQty = $this->helper->getMaximumQty(); if ($allQty > $maxQty) { throw new \Magento\Framework\Exception\LocalizedException(__('Maximum qty allowed for Shipping to multiple addresses is %1', $maxQty)); } $quote = $this->getQuote(); $addresses = $quote->getAllShippingAddresses(); foreach ($addresses as $address) { $quote->removeAddress($address->getId()); } foreach ($info as $itemData) { foreach ($itemData as $quoteItemId => $data) { $this->_addShippingItem($quoteItemId, $data); } } /** * Delete all not virtual quote items which are not added to shipping address * MultishippingQty should be defined for each quote item when it processed with _addShippingItem */ foreach ($quote->getAllItems() as $_item) { if (!$_item->getProduct()->getIsVirtual() && !$_item->getParentItem() && !$_item->getMultishippingQty()) { $quote->removeItem($_item->getId()); } } $billingAddress = $quote->getBillingAddress(); if ($billingAddress) { $quote->removeAddress($billingAddress->getId()); } $customerDefaultBillingId = $this->getCustomerDefaultBillingAddress(); if ($customerDefaultBillingId) { $quote->getBillingAddress()->importCustomerAddressData($this->addressRepository->getById($customerDefaultBillingId)); } foreach ($quote->getAllItems() as $_item) { if (!$_item->getProduct()->getIsVirtual()) { continue; } if (isset($itemsInfo[$_item->getId()]['qty'])) { $qty = (int) $itemsInfo[$_item->getId()]['qty']; if ($qty) { $_item->setQty($qty); $quote->getBillingAddress()->addItem($_item); } else { $_item->setQty(0); $quote->removeItem($_item->getId()); } } } $this->save(); $this->_eventManager->dispatch('checkout_type_multishipping_set_shipping_items', ['quote' => $quote]); } return $this; }