Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
quote_with_split_items.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 require __DIR__ . '/quote.php';
11 
16 $items = $quote->getAllItems();
17 $addressList = $quote->getAllShippingAddresses();
18 
19 foreach ($addressList as $key => $address) {
20  $item = $items[$key];
21  // set correct quantity per shipping address
22  $item->setQty(1);
23  $address->setTotalQty(1);
24  $address->addItem($item);
25 }
26 
27 // assign virtual product to the billing address
28 $billingAddress = $quote->getBillingAddress();
29 $virtualItem = $items[sizeof($items) - 1];
30 $billingAddress->setTotalQty(1);
32 
33 // need to recollect totals
34 $quote->setTotalsCollectedFlag(false);
35 $quote->collectTotals();
foreach($addressList as $key=> $address) $billingAddress
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$quote
$address
Definition: customer.php:38
$quoteRepository