Skip to content

Commit c8abcdd

Browse files
committed
Merge remote-tracking branch 'mpi/MC-18519' into pr_vk_2019_08_16
2 parents d6a0bbf + 250180b commit c8abcdd

19 files changed

+723
-24
lines changed

app/code/Magento/Multishipping/Block/Checkout/Overview.php

Lines changed: 104 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Multishipping\Block\Checkout;
78

89
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -12,8 +13,8 @@
1213
* Multishipping checkout overview information
1314
*
1415
* @api
15-
* @author Magento Core Team <core@magentocommerce.com>
16-
* @since 100.0.2
16+
* @author Magento Core Team <core@magentocommerce.com>
17+
* @since 100.0.2
1718
*/
1819
class Overview extends \Magento\Sales\Block\Items\AbstractItems
1920
{
@@ -48,13 +49,13 @@ class Overview extends \Magento\Sales\Block\Items\AbstractItems
4849
protected $totalsReader;
4950

5051
/**
51-
* @param \Magento\Framework\View\Element\Template\Context $context
52+
* @param \Magento\Framework\View\Element\Template\Context $context
5253
* @param \Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping
53-
* @param \Magento\Tax\Helper\Data $taxHelper
54-
* @param PriceCurrencyInterface $priceCurrency
55-
* @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector
56-
* @param \Magento\Quote\Model\Quote\TotalsReader $totalsReader
57-
* @param array $data
54+
* @param \Magento\Tax\Helper\Data $taxHelper
55+
* @param PriceCurrencyInterface $priceCurrency
56+
* @param \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector
57+
* @param \Magento\Quote\Model\Quote\TotalsReader $totalsReader
58+
* @param array $data
5859
*/
5960
public function __construct(
6061
\Magento\Framework\View\Element\Template\Context $context,
@@ -74,6 +75,37 @@ public function __construct(
7475
$this->totalsReader = $totalsReader;
7576
}
7677

78+
/**
79+
* Overwrite the total value of shipping amount for viewing purpose
80+
*
81+
* @param array $totals
82+
* @return mixed
83+
* @throws \Exception
84+
*/
85+
private function getMultishippingTotals($totals)
86+
{
87+
if (isset($totals['shipping']) && !empty($totals['shipping'])) {
88+
$total = $totals['shipping'];
89+
$shippingMethod = $total->getAddress()->getShippingMethod();
90+
if (isset($shippingMethod) && !empty($shippingMethod)) {
91+
$shippingRate = $total->getAddress()->getShippingRateByCode($shippingMethod);
92+
$shippingPrice = $shippingRate->getPrice();
93+
} else {
94+
$shippingPrice = $total->getAddress()->getShippingAmount();
95+
}
96+
/**
97+
* @var \Magento\Store\Api\Data\StoreInterface
98+
*/
99+
$store = $this->getQuote()->getStore();
100+
$amountPrice = $store->getBaseCurrency()
101+
->convert($shippingPrice, $store->getCurrentCurrencyCode());
102+
$total->setBaseShippingAmount($shippingPrice);
103+
$total->setShippingAmount($amountPrice);
104+
$total->setValue($amountPrice);
105+
}
106+
return $totals;
107+
}
108+
77109
/**
78110
* Initialize default item renderer
79111
*
@@ -98,6 +130,8 @@ public function getCheckout()
98130
}
99131

100132
/**
133+
* Get billing address
134+
*
101135
* @return Address
102136
*/
103137
public function getBillingAddress()
@@ -106,6 +140,8 @@ public function getBillingAddress()
106140
}
107141

108142
/**
143+
* Get payment info
144+
*
109145
* @return string
110146
*/
111147
public function getPaymentHtml()
@@ -124,6 +160,8 @@ public function getPayment()
124160
}
125161

126162
/**
163+
* Get shipping addresses
164+
*
127165
* @return array
128166
*/
129167
public function getShippingAddresses()
@@ -132,6 +170,8 @@ public function getShippingAddresses()
132170
}
133171

134172
/**
173+
* Get number of shipping addresses
174+
*
135175
* @return int|mixed
136176
*/
137177
public function getShippingAddressCount()
@@ -145,8 +185,10 @@ public function getShippingAddressCount()
145185
}
146186

147187
/**
148-
* @param Address $address
149-
* @return bool
188+
* Get shipping address rate
189+
*
190+
* @param Address $address
191+
* @return bool
150192
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
151193
*/
152194
public function getShippingAddressRate($address)
@@ -159,27 +201,36 @@ public function getShippingAddressRate($address)
159201
}
160202

161203
/**
162-
* @param Address $address
204+
* Get shipping price including tax
205+
*
206+
* @param Address $address
163207
* @return mixed
164208
*/
165209
public function getShippingPriceInclTax($address)
166210
{
167-
$exclTax = $address->getShippingAmount();
211+
$rate = $address->getShippingRateByCode($address->getShippingMethod());
212+
$exclTax = $rate->getPrice();
168213
$taxAmount = $address->getShippingTaxAmount();
169214
return $this->formatPrice($exclTax + $taxAmount);
170215
}
171216

172217
/**
173-
* @param Address $address
218+
* Get shipping price excluding tax
219+
*
220+
* @param Address $address
174221
* @return mixed
175222
*/
176223
public function getShippingPriceExclTax($address)
177224
{
178-
return $this->formatPrice($address->getShippingAmount());
225+
$rate = $address->getShippingRateByCode($address->getShippingMethod());
226+
$shippingAmount = $rate->getPrice();
227+
return $this->formatPrice($shippingAmount);
179228
}
180229

181230
/**
182-
* @param float $price
231+
* Format price
232+
*
233+
* @param float $price
183234
* @return mixed
184235
*
185236
* @codeCoverageIgnore
@@ -195,7 +246,9 @@ public function formatPrice($price)
195246
}
196247

197248
/**
198-
* @param Address $address
249+
* Get shipping address items
250+
*
251+
* @param Address $address
199252
* @return array
200253
*/
201254
public function getShippingAddressItems($address): array
@@ -204,7 +257,9 @@ public function getShippingAddressItems($address): array
204257
}
205258

206259
/**
207-
* @param Address $address
260+
* Get shipping address totals
261+
*
262+
* @param Address $address
208263
* @return mixed
209264
*/
210265
public function getShippingAddressTotals($address)
@@ -223,6 +278,8 @@ public function getShippingAddressTotals($address)
223278
}
224279

225280
/**
281+
* Get total price
282+
*
226283
* @return float
227284
*/
228285
public function getTotal()
@@ -231,6 +288,8 @@ public function getTotal()
231288
}
232289

233290
/**
291+
* Get the Edit addresses URL
292+
*
234293
* @return string
235294
*/
236295
public function getAddressesEditUrl()
@@ -239,7 +298,9 @@ public function getAddressesEditUrl()
239298
}
240299

241300
/**
242-
* @param Address $address
301+
* Get the Edit shipping address URL
302+
*
303+
* @param Address $address
243304
* @return string
244305
*/
245306
public function getEditShippingAddressUrl($address)
@@ -248,7 +309,9 @@ public function getEditShippingAddressUrl($address)
248309
}
249310

250311
/**
251-
* @param Address $address
312+
* Get the Edit billing address URL
313+
*
314+
* @param Address $address
252315
* @return string
253316
*/
254317
public function getEditBillingAddressUrl($address)
@@ -257,6 +320,8 @@ public function getEditBillingAddressUrl($address)
257320
}
258321

259322
/**
323+
* Get the Edit shipping URL
324+
*
260325
* @return string
261326
*/
262327
public function getEditShippingUrl()
@@ -265,6 +330,8 @@ public function getEditShippingUrl()
265330
}
266331

267332
/**
333+
* Get Post ACtion URL
334+
*
268335
* @return string
269336
*/
270337
public function getPostActionUrl()
@@ -273,6 +340,8 @@ public function getPostActionUrl()
273340
}
274341

275342
/**
343+
* Get the Edit billing URL
344+
*
276345
* @return string
277346
*/
278347
public function getEditBillingUrl()
@@ -281,6 +350,8 @@ public function getEditBillingUrl()
281350
}
282351

283352
/**
353+
* Get back button URL
354+
*
284355
* @return string
285356
*/
286357
public function getBackUrl()
@@ -319,16 +390,20 @@ public function getQuote()
319390
}
320391

321392
/**
393+
* Get billin address totals
394+
*
395+
* @return mixed
322396
* @deprecated
323397
* typo in method name, see getBillingAddressTotals()
324-
* @return mixed
325398
*/
326399
public function getBillinAddressTotals()
327400
{
328401
return $this->getBillingAddressTotals();
329402
}
330403

331404
/**
405+
* Get billing address totals
406+
*
332407
* @return mixed
333408
*/
334409
public function getBillingAddressTotals()
@@ -338,12 +413,17 @@ public function getBillingAddressTotals()
338413
}
339414

340415
/**
341-
* @param mixed $totals
342-
* @param null $colspan
416+
* Render total block
417+
*
418+
* @param mixed $totals
419+
* @param null $colspan
343420
* @return string
344421
*/
345422
public function renderTotals($totals, $colspan = null)
346423
{
424+
//check if the shipment is multi shipment
425+
$totals = $this->getMultishippingTotals($totals);
426+
347427
if ($colspan === null) {
348428
$colspan = 3;
349429
}
@@ -368,7 +448,7 @@ public function renderTotals($totals, $colspan = null)
368448
/**
369449
* Return row-level item html
370450
*
371-
* @param \Magento\Framework\DataObject $item
451+
* @param \Magento\Framework\DataObject $item
372452
* @return string
373453
*/
374454
public function getRowItemHtml(\Magento\Framework\DataObject $item)
@@ -382,7 +462,7 @@ public function getRowItemHtml(\Magento\Framework\DataObject $item)
382462
/**
383463
* Retrieve renderer block for row-level item output
384464
*
385-
* @param string $type
465+
* @param string $type
386466
* @return \Magento\Framework\View\Element\AbstractBlock
387467
*/
388468
protected function _getRowItemRenderer($type)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Multishipping\Model\Cart;
9+
10+
use Magento\Quote\Api\CartRepositoryInterface;
11+
use Magento\Quote\Model\Cart\CartTotalRepository;
12+
use Magento\Quote\Model\Cart\Totals;
13+
14+
/**
15+
* CartTotalPlugin calculate total shipping price for multishipping
16+
*/
17+
class CartTotalRepositoryPlugin
18+
{
19+
/**
20+
* Quote repository.
21+
*
22+
* @var \Magento\Quote\Api\CartRepositoryInterface
23+
*/
24+
private $quoteRepository;
25+
26+
/**
27+
* @param CartRepositoryInterface $quoteRepository
28+
*/
29+
public function __construct(
30+
CartRepositoryInterface $quoteRepository
31+
) {
32+
$this->quoteRepository = $quoteRepository;
33+
}
34+
35+
/**
36+
* Overwrite the CartTotalRepository quoteTotal and update the shipping price
37+
*
38+
* @param CartTotalRepository $subject
39+
* @param Totals $quoteTotals
40+
* @param String $cartId
41+
* @return Totals
42+
* @throws \Magento\Framework\Exception\NoSuchEntityException
43+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
45+
*/
46+
public function afterGet(
47+
CartTotalRepository $subject,
48+
Totals $quoteTotals,
49+
String $cartId
50+
) {
51+
$quote = $this->quoteRepository->getActive($cartId);
52+
if ($quote->getIsMultiShipping()) {
53+
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
54+
if (isset($shippingMethod) && !empty($shippingMethod)) {
55+
$shippingRate = $quote->getShippingAddress()->getShippingRateByCode($shippingMethod);
56+
$shippingPrice = $shippingRate->getPrice();
57+
} else {
58+
$shippingPrice = $quote->getShippingAddress()->getShippingAmount();
59+
}
60+
/**
61+
* @var \Magento\Store\Api\Data\StoreInterface
62+
*/
63+
$store = $quote->getStore();
64+
$amountPrice = $store->getBaseCurrency()
65+
->convert($shippingPrice, $store->getCurrentCurrencyCode());
66+
$quoteTotals->setBaseShippingAmount($shippingPrice);
67+
$quoteTotals->setShippingAmount($amountPrice);
68+
}
69+
return $quoteTotals;
70+
}
71+
}

0 commit comments

Comments
 (0)