Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Multishipping Class Reference
Inheritance diagram for Multishipping:
DataObject

Public Member Functions

 __construct (\Magento\Checkout\Model\Session $checkoutSession, \Magento\Customer\Model\Session $customerSession, \Magento\Sales\Model\OrderFactory $orderFactory, AddressRepositoryInterface $addressRepository, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Session\Generic $session, \Magento\Quote\Model\Quote\AddressFactory $addressFactory, \Magento\Quote\Model\Quote\Address\ToOrder $quoteAddressToOrder, \Magento\Quote\Model\Quote\Address\ToOrderAddress $quoteAddressToOrderAddress, \Magento\Quote\Model\Quote\Payment\ToOrderPayment $quotePaymentToOrderPayment, \Magento\Quote\Model\Quote\Item\ToOrderItem $quoteItemToOrderItem, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification, \Magento\Multishipping\Helper\Data $helper, OrderSender $orderSender, PriceCurrencyInterface $priceCurrency, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Framework\Api\FilterBuilder $filterBuilder, \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector, array $data=[], \Magento\Quote\Api\Data\CartExtensionFactory $cartExtensionFactory=null, AllowedCountries $allowedCountryReader=null, Multishipping\PlaceOrderFactory $placeOrderFactory=null, LoggerInterface $logger=null, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper=null)
 
 getQuoteShippingAddressesItems ()
 
 removeAddressItem ($addressId, $itemId)
 
 setShippingItemsInformation ($info)
 
 updateQuoteCustomerShippingAddress ($addressId)
 
 setQuoteCustomerBillingAddress ($addressId)
 
 setPaymentMethod ($payment)
 
 save ()
 
 reset ()
 
 validateMinimumAmount ()
 
 getMinimumAmountDescription ()
 
 getMinimumAmountError ()
 
 getOrderIds ($asAssoc=false)
 
 getCustomerDefaultBillingAddress ()
 
 getCustomerDefaultShippingAddress ()
 
 getCheckoutSession ()
 
 getQuote ()
 
 getQuoteItems ()
 
 getCustomerSession ()
 
 getCustomer ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Protected Member Functions

 _init ()
 
 _addShippingItem ($quoteItemId, $data)
 
 _prepareOrder (\Magento\Quote\Model\Quote\Address $address)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_quoteShippingAddressesItems
 
 $_eventManager = null
 
 $_scopeConfig
 
 $_session
 
 $_storeManager
 
 $_addressFactory
 
 $paymentSpecification
 
 $helper
 
 $_checkoutSession
 
 $_customerSession
 
 $_orderFactory
 
 $addressRepository
 
 $orderSender
 
 $priceCurrency
 
 $quoteRepository
 
 $searchCriteriaBuilder
 
 $filterBuilder
 
 $quoteAddressToOrder
 
 $quoteItemToOrderItem
 
 $quotePaymentToOrderPayment
 
 $quoteAddressToOrderAddress
 
 $totalsCollector
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Multishipping checkout model

@api @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 28 of file Multishipping.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Checkout\Model\Session  $checkoutSession,
\Magento\Customer\Model\Session  $customerSession,
\Magento\Sales\Model\OrderFactory  $orderFactory,
AddressRepositoryInterface  $addressRepository,
\Magento\Framework\Event\ManagerInterface  $eventManager,
\Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Framework\Session\Generic  $session,
\Magento\Quote\Model\Quote\AddressFactory  $addressFactory,
\Magento\Quote\Model\Quote\Address\ToOrder  $quoteAddressToOrder,
\Magento\Quote\Model\Quote\Address\ToOrderAddress  $quoteAddressToOrderAddress,
\Magento\Quote\Model\Quote\Payment\ToOrderPayment  $quotePaymentToOrderPayment,
\Magento\Quote\Model\Quote\Item\ToOrderItem  $quoteItemToOrderItem,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Payment\Model\Method\SpecificationInterface  $paymentSpecification,
\Magento\Multishipping\Helper\Data  $helper,
OrderSender  $orderSender,
PriceCurrencyInterface  $priceCurrency,
\Magento\Quote\Api\CartRepositoryInterface  $quoteRepository,
\Magento\Framework\Api\SearchCriteriaBuilder  $searchCriteriaBuilder,
\Magento\Framework\Api\FilterBuilder  $filterBuilder,
\Magento\Quote\Model\Quote\TotalsCollector  $totalsCollector,
array  $data = [],
\Magento\Quote\Api\Data\CartExtensionFactory  $cartExtensionFactory = null,
AllowedCountries  $allowedCountryReader = null,
Multishipping\PlaceOrderFactory  $placeOrderFactory = null,
LoggerInterface  $logger = null,
\Magento\Framework\Api\DataObjectHelper  $dataObjectHelper = null 
)
Parameters
\Magento\Checkout\Model\Session$checkoutSession
\Magento\Customer\Model\Session$customerSession
\Magento\Sales\Model\OrderFactory$orderFactory
AddressRepositoryInterface$addressRepository
\Magento\Framework\Event\ManagerInterface$eventManager
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\Framework\Session\Generic$session
\Magento\Quote\Model\Quote\AddressFactory$addressFactory
\Magento\Quote\Model\Quote\Address\ToOrder$quoteAddressToOrder
\Magento\Quote\Model\Quote\Address\ToOrderAddress$quoteAddressToOrderAddress
\Magento\Quote\Model\Quote\Payment\ToOrderPayment$quotePaymentToOrderPayment
\Magento\Quote\Model\Quote\Item\ToOrderItem$quoteItemToOrderItem
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Payment\Model\Method\SpecificationInterface$paymentSpecification
\Magento\Multishipping\Helper\Data$helper
OrderSender$orderSender
PriceCurrencyInterface$priceCurrency
\Magento\Quote\Api\CartRepositoryInterface$quoteRepository
\Magento\Framework\Api\SearchCriteriaBuilder$searchCriteriaBuilder
\Magento\Framework\Api\FilterBuilder$filterBuilder
\Magento\Quote\Model\Quote\TotalsCollector$totalsCollector
array$data
\Magento\Quote\Api\Data\CartExtensionFactory | null$cartExtensionFactory
AllowedCountries | null$allowedCountryReader
Multishipping\PlaceOrderFactory | null$placeOrderFactory
LoggerInterface | null$logger
\Magento\Framework\Api\DataObjectHelper | null$dataObjectHelper@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 208 of file Multishipping.php.

236  {
237  $this->_eventManager = $eventManager;
238  $this->_scopeConfig = $scopeConfig;
239  $this->_session = $session;
240  $this->_addressFactory = $addressFactory;
241  $this->_storeManager = $storeManager;
242  $this->paymentSpecification = $paymentSpecification;
243  $this->helper = $helper;
244  $this->_checkoutSession = $checkoutSession;
245  $this->_customerSession = $customerSession;
246  $this->_orderFactory = $orderFactory;
247  $this->addressRepository = $addressRepository;
248  $this->orderSender = $orderSender;
249  $this->priceCurrency = $priceCurrency;
250  $this->quoteRepository = $quoteRepository;
251  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
252  $this->filterBuilder = $filterBuilder;
253  $this->quoteAddressToOrder = $quoteAddressToOrder;
254  $this->quoteItemToOrderItem = $quoteItemToOrderItem;
255  $this->quotePaymentToOrderPayment = $quotePaymentToOrderPayment;
256  $this->quoteAddressToOrderAddress = $quoteAddressToOrderAddress;
257  $this->totalsCollector = $totalsCollector;
258  $this->cartExtensionFactory = $cartExtensionFactory ?: ObjectManager::getInstance()
259  ->get(\Magento\Quote\Api\Data\CartExtensionFactory::class);
260  $this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance()
261  ->get(AllowedCountries::class);
262  $this->placeOrderFactory = $placeOrderFactory ?: ObjectManager::getInstance()
263  ->get(Multishipping\PlaceOrderFactory::class);
264  $this->logger = $logger ?: ObjectManager::getInstance()
265  ->get(LoggerInterface::class);
266  $this->dataObjectHelper = $dataObjectHelper ?: ObjectManager::getInstance()
267  ->get(\Magento\Framework\Api\DataObjectHelper::class);
268  parent::__construct($data);
269  $this->_init();
270  }
$storeManager
$logger
$addressFactory
Definition: quote.php:20

Member Function Documentation

◆ _addShippingItem()

_addShippingItem (   $quoteItemId,
  $data 
)
protected

Add quote item to specific shipping address based on customer address id

Parameters
int$quoteItemId
array$dataarray('qty'=>$qty, 'address'=>$customerAddressId)
Exceptions

Skip item processing if qty 0

Require shipping rate recollect

Definition at line 507 of file Multishipping.php.

508  {
509  $qty = isset($data['qty']) ? (int)$data['qty'] : 1;
510  //$qty = $qty > 0 ? $qty : 1;
511  $addressId = isset($data['address']) ? $data['address'] : false;
512  $quoteItem = $this->getQuote()->getItemById($quoteItemId);
513 
514  if ($addressId && $quoteItem) {
515  if (!$this->isAddressIdApplicable($addressId)) {
516  throw new LocalizedException(__('Verify the shipping address information and continue.'));
517  }
518 
522  if ($qty === 0) {
523  return $this;
524  }
525  $quoteItem->setMultishippingQty((int)$quoteItem->getMultishippingQty() + $qty);
526  $quoteItem->setQty($quoteItem->getMultishippingQty());
527  try {
528  $address = $this->addressRepository->getById($addressId);
529  } catch (\Exception $e) {
530  }
531  if (isset($address)) {
532  if (!($quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($address->getId()))) {
533  $quoteAddress = $this->_addressFactory->create()->importCustomerAddressData($address);
534  $this->getQuote()->addShippingAddress($quoteAddress);
535  }
536 
537  $quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($address->getId());
538  $quoteAddress->setCustomerAddressId($addressId);
539  $quoteAddressItem = $quoteAddress->getItemByQuoteItemId($quoteItemId);
540  if ($quoteAddressItem) {
541  $quoteAddressItem->setQty((int)($quoteAddressItem->getQty() + $qty));
542  } else {
543  $quoteAddress->addItem($quoteItem, $qty);
544  }
548  $quoteAddress->setCollectShippingRates((bool)$this->getCollectRatesFlag());
549  }
550  }
551  return $this;
552  }
__()
Definition: __.php:13
$address
Definition: customer.php:38
$quoteItem
Definition: quote.php:38
$quoteItemId
Definition: cart.php:17

◆ _init()

_init ( )
protected

Initialize multishipping checkout.

Split virtual/not virtual items between default billing/shipping addresses

Returns
\Magento\Multishipping\Model\Checkout\Type\Multishipping @SuppressWarnings(PHPMD.CyclomaticComplexity)

reset quote shipping addresses and items

Remove all addresses

Items with parent id we add in importQuoteItem method. Skip virtual items

Definition at line 280 of file Multishipping.php.

281  {
285  $quote = $this->getQuote();
286  if (!$this->getCustomer()->getId()) {
287  return $this;
288  }
289 
290  if ($this->getCheckoutSession()->getCheckoutState() === \Magento\Checkout\Model\Session::CHECKOUT_STATE_BEGIN
291  ) {
292  $this->getCheckoutSession()->setCheckoutState(true);
296  $addresses = $quote->getAllAddresses();
297  foreach ($addresses as $address) {
298  $quote->removeAddress($address->getId());
299  }
300 
301  $defaultShippingId = $this->getCustomerDefaultShippingAddress();
302  if ($defaultShippingId) {
303  $quote->getShippingAddress()->importCustomerAddressData(
304  $this->addressRepository->getById($defaultShippingId)
305  );
306 
307  foreach ($this->getQuoteItems() as $item) {
312  if ($item->getParentItemId() || $item->getProduct()->getIsVirtual()) {
313  continue;
314  }
315  $quote->getShippingAddress()->addItem($item);
316  }
317  }
318 
319  $defaultBillingAddressId = $this->getCustomerDefaultBillingAddress();
320  if ($defaultBillingAddressId) {
321  $quote->getBillingAddress()->importCustomerAddressData(
322  $this->addressRepository->getById($defaultBillingAddressId)
323  );
324  foreach ($this->getQuoteItems() as $item) {
325  if ($item->getParentItemId()) {
326  continue;
327  }
328  if ($item->getProduct()->getIsVirtual()) {
329  $quote->getBillingAddress()->addItem($item);
330  }
331  }
332  }
333  $this->save();
334  }
335  return $this;
336  }
$addresses
Definition: address_list.php:7
$quote
$address
Definition: customer.php:38

◆ _prepareOrder()

_prepareOrder ( \Magento\Quote\Model\Quote\Address  $address)
protected

Prepare order based on quote address

Parameters
\Magento\Quote\Model\Quote\Address$address
Returns
\Magento\Sales\Model\Order
Exceptions

Definition at line 675 of file Multishipping.php.

676  {
677  $quote = $this->getQuote();
678  $quote->unsReservedOrderId();
679  $quote->reserveOrderId();
680  $quote->collectTotals();
681 
682  $order = $this->_orderFactory->create();
683 
684  $this->dataObjectHelper->mergeDataObjects(
685  \Magento\Sales\Api\Data\OrderInterface::class,
686  $order,
687  $this->quoteAddressToOrder->convert($address)
688  );
689 
690  $order->setQuote($quote);
691  $order->setBillingAddress($this->quoteAddressToOrderAddress->convert($quote->getBillingAddress()));
692 
693  if ($address->getAddressType() == 'billing') {
694  $order->setIsVirtual(1);
695  } else {
696  $order->setShippingAddress($this->quoteAddressToOrderAddress->convert($address));
697  $order->setShippingMethod($address->getShippingMethod());
698  }
699 
700  $order->setPayment($this->quotePaymentToOrderPayment->convert($quote->getPayment()));
701  if ($this->priceCurrency->round($address->getGrandTotal()) == 0) {
702  $order->getPayment()->setMethod('free');
703  }
704 
705  foreach ($address->getAllItems() as $item) {
706  $_quoteItem = $item->getQuoteItem();
707  if (!$_quoteItem) {
708  throw new \Magento\Checkout\Exception(
709  __("The item isn't found, or it's already ordered.")
710  );
711  }
712  $item->setProductType(
713  $_quoteItem->getProductType()
714  )->setProductOptions(
715  $_quoteItem->getProduct()->getTypeInstance()->getOrderOptions($_quoteItem->getProduct())
716  );
717  $orderItem = $this->quoteItemToOrderItem->convert($item);
718  if ($item->getParentItem()) {
719  $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
720  }
721  $order->addItem($orderItem);
722  }
723 
724  return $order;
725  }
$orderItem
Definition: order.php:30
$quote
$order
Definition: order.php:55
__()
Definition: __.php:13
$address
Definition: customer.php:38

◆ getCheckoutSession()

getCheckoutSession ( )

Retrieve checkout session model

Returns
\Magento\Checkout\Model\Session

Definition at line 1025 of file Multishipping.php.

1026  {
1027  $checkout = $this->getData('checkout_session');
1028  if ($checkout === null) {
1029  $checkout = $this->_checkoutSession;
1030  $this->setData('checkout_session', $checkout);
1031  }
1032  return $checkout;
1033  }
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72

◆ getCustomer()

getCustomer ( )

Retrieve customer object

Returns
\Magento\Customer\Api\Data\CustomerInterface

Definition at line 1070 of file Multishipping.php.

1071  {
1072  return $this->_customerSession->getCustomerDataObject();
1073  }

◆ getCustomerDefaultBillingAddress()

getCustomerDefaultBillingAddress ( )

Retrieve customer default billing address

Returns
int|null

Definition at line 971 of file Multishipping.php.

972  {
973  $defaultAddressId = $this->getCustomer()->getDefaultBilling();
974  return $this->getDefaultAddressByDataKey('customer_default_billing_address', $defaultAddressId);
975  }

◆ getCustomerDefaultShippingAddress()

getCustomerDefaultShippingAddress ( )

Retrieve customer default shipping address

Returns
int|null

Definition at line 982 of file Multishipping.php.

983  {
984  $defaultAddressId = $this->getCustomer()->getDefaultShipping();
985  return $this->getDefaultAddressByDataKey('customer_default_shipping_address', $defaultAddressId);
986  }

◆ getCustomerSession()

getCustomerSession ( )

Retrieve customer session model

Returns
\Magento\Customer\Model\Session

Definition at line 1060 of file Multishipping.php.

◆ getMinimumAmountDescription()

getMinimumAmountDescription ( )

Get notification message for case when multishipping checkout is not allowed

Returns
string

Definition at line 916 of file Multishipping.php.

917  {
918  $descr = $this->_scopeConfig->getValue(
919  'sales/minimum_order/multi_address_description',
921  );
922  if (empty($descr)) {
923  $descr = $this->_scopeConfig->getValue(
924  'sales/minimum_order/description',
926  );
927  }
928  return $descr;
929  }

◆ getMinimumAmountError()

getMinimumAmountError ( )

Get minimum amount error.

Returns
string

Definition at line 936 of file Multishipping.php.

937  {
938  $error = $this->_scopeConfig->getValue(
939  'sales/minimum_order/multi_address_error_message',
941  );
942  if (empty($error)) {
943  $error = $this->_scopeConfig->getValue(
944  'sales/minimum_order/error_message',
946  );
947  }
948  return $error;
949  }

◆ getOrderIds()

getOrderIds (   $asAssoc = false)

Get order IDs created during checkout

Parameters
bool$asAssoc
Returns
array

Definition at line 957 of file Multishipping.php.

958  {
959  $idsAssoc = $this->_session->getOrderIds();
960  if ($idsAssoc !== null) {
961  return $asAssoc ? $idsAssoc : array_keys($idsAssoc);
962  }
963  return [];
964  }

◆ getQuote()

getQuote ( )

Retrieve quote model

Returns
\Magento\Quote\Model\Quote

Definition at line 1040 of file Multishipping.php.

1041  {
1042  return $this->getCheckoutSession()->getQuote();
1043  }

◆ getQuoteItems()

getQuoteItems ( )

Retrieve quote items

Returns
\Magento\Quote\Model\Quote\Item[]

Definition at line 1050 of file Multishipping.php.

1051  {
1052  return $this->getQuote()->getAllItems();
1053  }

◆ getQuoteShippingAddressesItems()

getQuoteShippingAddressesItems ( )

Get quote items assigned to different quote addresses populated per item qty.

Based on result array we can display each item separately

Returns
array

Definition at line 345 of file Multishipping.php.

346  {
347  if ($this->_quoteShippingAddressesItems !== null) {
349  }
350  $this->_quoteShippingAddressesItems = $this->getQuote()->getShippingAddressesItems();
352  }

◆ removeAddressItem()

removeAddressItem (   $addressId,
  $itemId 
)

Remove item from address

Parameters
int$addressId
int$itemId
Returns
\Magento\Multishipping\Model\Checkout\Type\Multishipping

Require shipping rate recollect

Definition at line 361 of file Multishipping.php.

362  {
363  $address = $this->getQuote()->getAddressById($addressId);
364  /* @var $address \Magento\Quote\Model\Quote\Address */
365  if ($address) {
366  $item = $address->getValidItemById($itemId);
367  if ($item) {
368  if ($item->getQty() > 1 && !$item->getProduct()->getIsVirtual()) {
369  $item->setQty($item->getQty() - 1);
370  } else {
371  $address->removeItem($item->getId());
372  }
373 
377  $address->setCollectShippingRates((bool)$this->getCollectRatesFlag());
378 
379  if (count($address->getAllItems()) == 0) {
380  $address->isDeleted(true);
381  }
382 
383  $quoteItem = $this->getQuote()->getItemById($item->getQuoteItemId());
384  if ($quoteItem) {
385  $newItemQty = $quoteItem->getQty() - 1;
386  if ($newItemQty > 0 && !$item->getProduct()->getIsVirtual()) {
387  $quoteItem->setQty($quoteItem->getQty() - 1);
388  } else {
389  $this->getQuote()->removeItem($quoteItem->getId());
390  }
391  }
392  $this->save();
393  }
394  }
395  return $this;
396  }
$address
Definition: customer.php:38
$quoteItem
Definition: quote.php:38

◆ reset()

reset ( )

Specify BEGIN state in checkout session whot allow reinit multishipping checkout

Returns
\Magento\Multishipping\Model\Checkout\Type\Multishipping

Definition at line 889 of file Multishipping.php.

890  {
891  $this->getCheckoutSession()->setCheckoutState(\Magento\Checkout\Model\Session::CHECKOUT_STATE_BEGIN);
892  return $this;
893  }

◆ save()

save ( )

Collect quote totals and save quote object

Returns
\Magento\Multishipping\Model\Checkout\Type\Multishipping

Definition at line 877 of file Multishipping.php.

878  {
879  $this->getQuote()->collectTotals();
880  $this->quoteRepository->save($this->getQuote());
881  return $this;
882  }

◆ setPaymentMethod()

setPaymentMethod (   $payment)

Set payment method info to quote payment

Parameters
array$payment
Returns
\Magento\Multishipping\Model\Checkout\Type\Multishipping
Exceptions

Definition at line 642 of file Multishipping.php.

643  {
644  if (!isset($payment['method'])) {
645  throw new \Magento\Framework\Exception\LocalizedException(
646  __("A payment method isn't defined. Verify and try again.")
647  );
648  }
649  if (!$this->paymentSpecification->isSatisfiedBy($payment['method'])) {
650  throw new \Magento\Framework\Exception\LocalizedException(
651  __(
652  "This payment method can't be used for shipping to multiple addresses. "
653  . "Change the payment method and try again."
654  )
655  );
656  }
657  $quote = $this->getQuote();
658  $quote->getPayment()->importData($payment);
659  // shipping totals may be affected by payment method
660  if (!$quote->isVirtual() && $quote->getShippingAddress()) {
661  $quote->getShippingAddress()->setCollectShippingRates(true);
662  $quote->setTotalsCollectedFlag(false)->collectTotals();
663  }
664  $this->quoteRepository->save($quote);
665  return $this;
666  }
$quote
__()
Definition: __.php:13
$payment
Definition: order.php:17

◆ setQuoteCustomerBillingAddress()

setQuoteCustomerBillingAddress (   $addressId)

Reimport customer billing address to quote

Parameters
int$addressIdcustomer address id
Exceptions

Definition at line 588 of file Multishipping.php.

589  {
590  if (!$this->isAddressIdApplicable($addressId)) {
591  throw new LocalizedException(__('Verify the billing address information and continue.'));
592  }
593  try {
594  $address = $this->addressRepository->getById($addressId);
595  } catch (\Exception $e) {
596  //
597  }
598  if (isset($address)) {
599  $quoteAddress = $this->getQuote()->getBillingAddress($addressId)->importCustomerAddressData($address);
600  $this->totalsCollector->collectAddressTotals($this->getQuote(), $quoteAddress);
601  $this->getQuote()->collectTotals();
602  $this->quoteRepository->save($this->getQuote());
603  }
604 
605  return $this;
606  }
__()
Definition: __.php:13
$address
Definition: customer.php:38

◆ setShippingItemsInformation()

setShippingItemsInformation (   $info)

Assign quote items to addresses and specify items qty

Array structure: array( $quoteItemId => array( 'qty' => $qty, 'address' => $customerAddressId ) )

Parameters
array$info
Returns
\Magento\Multishipping\Model\Checkout\Type\Multishipping
Exceptions

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

Definition at line 415 of file Multishipping.php.

416  {
417  if (is_array($info)) {
418  $allQty = 0;
419  $itemsInfo = [];
420  foreach ($info as $itemData) {
421  foreach ($itemData as $quoteItemId => $data) {
422  $allQty += $data['qty'];
423  $itemsInfo[$quoteItemId] = $data;
424  }
425  }
426 
427  $maxQty = $this->helper->getMaximumQty();
428  if ($allQty > $maxQty) {
429  throw new \Magento\Framework\Exception\LocalizedException(
430  __(
431  "The maximum quantity can't be more than %1 when shipping to multiple addresses. "
432  . "Change the quantity and try again.",
433  $maxQty
434  )
435  );
436  }
437  $quote = $this->getQuote();
438  $addresses = $quote->getAllShippingAddresses();
439  foreach ($addresses as $address) {
440  $quote->removeAddress($address->getId());
441  }
442 
443  foreach ($info as $itemData) {
444  foreach ($itemData as $quoteItemId => $data) {
446  }
447  }
448 
449  $this->prepareShippingAssignment($quote);
450 
455  foreach ($quote->getAllItems() as $_item) {
456  if (!$_item->getProduct()->getIsVirtual() && !$_item->getParentItem() && !$_item->getMultishippingQty()
457  ) {
458  $quote->removeItem($_item->getId());
459  }
460  }
461 
462  $billingAddress = $quote->getBillingAddress();
463  if ($billingAddress) {
464  $quote->removeAddress($billingAddress->getId());
465  }
466 
467  $customerDefaultBillingId = $this->getCustomerDefaultBillingAddress();
468  if ($customerDefaultBillingId) {
469  $quote->getBillingAddress()->importCustomerAddressData(
470  $this->addressRepository->getById($customerDefaultBillingId)
471  );
472  }
473 
474  foreach ($quote->getAllItems() as $_item) {
475  if (!$_item->getProduct()->getIsVirtual()) {
476  continue;
477  }
478 
479  if (isset($itemsInfo[$_item->getId()]['qty'])) {
480  $qty = (int)$itemsInfo[$_item->getId()]['qty'];
481  if ($qty) {
482  $_item->setQty($qty);
483  $quote->getBillingAddress()->addItem($_item);
484  } else {
485  $_item->setQty(0);
486  $quote->removeItem($_item->getId());
487  }
488  }
489  }
490 
491  $this->save();
492  $this->_eventManager->dispatch('checkout_type_multishipping_set_shipping_items', ['quote' => $quote]);
493  }
494  return $this;
495  }
$billingAddress
Definition: order.php:25
$addresses
Definition: address_list.php:7
$quote
__()
Definition: __.php:13
$address
Definition: customer.php:38
$_item
Definition: default.phtml:11
$quoteItemId
Definition: cart.php:17
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ updateQuoteCustomerShippingAddress()

updateQuoteCustomerShippingAddress (   $addressId)

Reimport customer address info to quote shipping address

Parameters
int$addressIdcustomer address id
Exceptions

Definition at line 561 of file Multishipping.php.

562  {
563  if (!$this->isAddressIdApplicable($addressId)) {
564  throw new LocalizedException(__('Verify the shipping address information and continue.'));
565  }
566  try {
567  $address = $this->addressRepository->getById($addressId);
568  } catch (\Exception $e) {
569  //
570  }
571  if (isset($address)) {
572  $quoteAddress = $this->getQuote()->getShippingAddressByCustomerAddressId($addressId);
573  $quoteAddress->setCollectShippingRates(true)->importCustomerAddressData($address);
574  $this->totalsCollector->collectAddressTotals($this->getQuote(), $quoteAddress);
575  $this->quoteRepository->save($this->getQuote());
576  }
577 
578  return $this;
579  }
__()
Definition: __.php:13
$address
Definition: customer.php:38

◆ validateMinimumAmount()

validateMinimumAmount ( )

Check if quote amount is allowed for multishipping checkout

Returns
bool

Definition at line 900 of file Multishipping.php.

901  {
902  return !($this->_scopeConfig->isSetFlag(
903  'sales/minimum_order/active',
905  ) && $this->_scopeConfig->isSetFlag(
906  'sales/minimum_order/multi_address',
908  ) && !$this->getQuote()->validateMinimumAmount());
909  }

Field Documentation

◆ $_addressFactory

$_addressFactory
protected

Definition at line 64 of file Multishipping.php.

◆ $_checkoutSession

$_checkoutSession
protected

Definition at line 81 of file Multishipping.php.

◆ $_customerSession

$_customerSession
protected

Definition at line 86 of file Multishipping.php.

◆ $_eventManager

$_eventManager = null
protected

Definition at line 42 of file Multishipping.php.

◆ $_orderFactory

$_orderFactory
protected

Definition at line 91 of file Multishipping.php.

◆ $_quoteShippingAddressesItems

$_quoteShippingAddressesItems
protected

Definition at line 35 of file Multishipping.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 49 of file Multishipping.php.

◆ $_session

$_session
protected

Definition at line 54 of file Multishipping.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 59 of file Multishipping.php.

◆ $addressRepository

$addressRepository
protected

Definition at line 96 of file Multishipping.php.

◆ $filterBuilder

$filterBuilder
protected

Definition at line 121 of file Multishipping.php.

◆ $helper

$helper
protected

Definition at line 76 of file Multishipping.php.

◆ $orderSender

$orderSender
protected

Definition at line 101 of file Multishipping.php.

◆ $paymentSpecification

$paymentSpecification
protected

Definition at line 69 of file Multishipping.php.

◆ $priceCurrency

$priceCurrency
protected

Definition at line 106 of file Multishipping.php.

◆ $quoteAddressToOrder

$quoteAddressToOrder
protected

Definition at line 126 of file Multishipping.php.

◆ $quoteAddressToOrderAddress

$quoteAddressToOrderAddress
protected

Definition at line 141 of file Multishipping.php.

◆ $quoteItemToOrderItem

$quoteItemToOrderItem
protected

Definition at line 131 of file Multishipping.php.

◆ $quotePaymentToOrderPayment

$quotePaymentToOrderPayment
protected

Definition at line 136 of file Multishipping.php.

◆ $quoteRepository

$quoteRepository
protected

Definition at line 111 of file Multishipping.php.

◆ $searchCriteriaBuilder

$searchCriteriaBuilder
protected

Definition at line 116 of file Multishipping.php.

◆ $totalsCollector

$totalsCollector
protected

Definition at line 146 of file Multishipping.php.


The documentation for this class was generated from the following file: