示例#1
0
 /**
  * @return string
  */
 public function _toHtml()
 {
     if (!$this->helper->isMultishippingCheckoutAvailable()) {
         return '';
     }
     return parent::_toHtml();
 }
示例#2
0
 /**
  * @param bool $result
  * @param bool $quoteHasItems
  * @param bool $isMultiShipping
  * @param bool $hasItemsWithDecimalQty
  * @param bool $validateMinimumAmount
  * @param int $itemsSummaryQty
  * @param int $itemVirtualQty
  * @param int $maximumQty
  * @dataProvider isMultishippingCheckoutAvailableDataProvider
  */
 public function testIsMultishippingCheckoutAvailable($result, $quoteHasItems, $isMultiShipping, $hasItemsWithDecimalQty, $validateMinimumAmount, $itemsSummaryQty, $itemVirtualQty, $maximumQty)
 {
     $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with(\Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE)->will($this->returnValue($isMultiShipping));
     $this->checkoutSessionMock->expects($this->once())->method('getQuote')->will($this->returnValue($this->quoteMock));
     $this->quoteMock->expects($this->once())->method('hasItems')->will($this->returnValue($quoteHasItems));
     $this->quoteMock->expects($this->any())->method('hasItemsWithDecimalQty')->will($this->returnValue($hasItemsWithDecimalQty));
     $this->quoteMock->expects($this->any())->method('validateMinimumAmount')->with(true)->will($this->returnValue($validateMinimumAmount));
     $this->quoteMock->expects($this->any())->method('getItemsSummaryQty')->will($this->returnValue($itemsSummaryQty));
     $this->quoteMock->expects($this->any())->method('getItemVirtualQty')->will($this->returnValue($itemVirtualQty));
     $this->scopeConfigMock->expects($this->any())->method('getValue')->with(\Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY)->will($this->returnValue($maximumQty));
     $this->assertEquals($result, $this->helper->isMultishippingCheckoutAvailable());
 }
 /**
  * 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;
 }