Skip to content

Commit b05e258

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-735' into PR_L3_22_04_2022
2 parents 7e35d6d + b182ae5 commit b05e258

File tree

5 files changed

+333
-34
lines changed

5 files changed

+333
-34
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Quote\Api\CartRepositoryInterface;
12+
use Magento\Quote\Api\Data\AddressInterface;
13+
use Magento\Quote\Api\Data\AddressInterfaceFactory;
14+
use Magento\Quote\Api\Data\CartExtensionFactory;
15+
use Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor;
16+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
17+
use Magento\TestFramework\Fixture\DataFixtureInterface;
18+
19+
class AddAddressToCart implements DataFixtureInterface
20+
{
21+
private const DEFAULT_DATA = [
22+
AddressInterface::KEY_TELEPHONE => 3340000000,
23+
AddressInterface::KEY_POSTCODE => 36104,
24+
AddressInterface::KEY_COUNTRY_ID => 'US',
25+
AddressInterface::KEY_CITY => 'Montgomery',
26+
AddressInterface::KEY_COMPANY => 'Magento',
27+
AddressInterface::KEY_STREET => ['Green str, 67'],
28+
AddressInterface::KEY_LASTNAME => 'Doe',
29+
AddressInterface::KEY_FIRSTNAME => 'John%uniqid%',
30+
AddressInterface::KEY_REGION_ID => 1,
31+
];
32+
/**
33+
* @var ProcessorInterface
34+
*/
35+
private $dataProcessor;
36+
37+
/**
38+
* @var AddressInterfaceFactory
39+
*/
40+
private $addressInterfaceFactory;
41+
42+
/**
43+
* @var CartRepositoryInterface
44+
*/
45+
private $cartRepository;
46+
47+
/**
48+
* @param ProcessorInterface $dataProcessor
49+
* @param AddressInterfaceFactory $addressInterfaceFactory
50+
* @param CartRepositoryInterface $cartRepository
51+
*/
52+
public function __construct(
53+
ProcessorInterface $dataProcessor,
54+
AddressInterfaceFactory $addressInterfaceFactory,
55+
CartRepositoryInterface $cartRepository
56+
) {
57+
$this->addressInterfaceFactory = $addressInterfaceFactory;
58+
$this->dataProcessor = $dataProcessor;
59+
$this->cartRepository = $cartRepository;
60+
}
61+
62+
/**
63+
* {@inheritdoc}
64+
* @param array $data Parameters
65+
* <pre>
66+
* $data = [
67+
* 'cart_id' => (int) Cart ID. Required.
68+
* 'address' => (array) Address Data. Optional. Default: AddAddressToCart::DEFAULT_DATA
69+
* ]
70+
* </pre>
71+
*/
72+
public function apply(array $data = []): ?DataObject
73+
{
74+
$cart = $this->cartRepository->get($data['cart_id']);
75+
$address = $this->addressInterfaceFactory->create(
76+
[
77+
'data' => $this->dataProcessor->process($this, array_merge(self::DEFAULT_DATA, $data['address'] ?? []))
78+
]
79+
);
80+
if (!$cart->getIsMultiShipping()) {
81+
$cart->setIsMultiShipping(1);
82+
foreach ($cart->getAllShippingAddresses() as $existingAddress) {
83+
$cart->removeAddress($existingAddress->getId());
84+
}
85+
}
86+
$address->setCollectShippingRates(true);
87+
$cart->addShippingAddress($address);
88+
89+
$this->cartRepository->save($cart);
90+
91+
return $address;
92+
}
93+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Quote\Api\CartRepositoryInterface;
12+
use Magento\TestFramework\Fixture\DataFixtureInterface;
13+
14+
class ShippingAssignments implements DataFixtureInterface
15+
{
16+
/**
17+
* @var CartRepositoryInterface
18+
*/
19+
private $cartRepository;
20+
21+
/**
22+
* @param CartRepositoryInterface $cartRepository
23+
*/
24+
public function __construct(
25+
CartRepositoryInterface $cartRepository
26+
) {
27+
$this->cartRepository = $cartRepository;
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
* @param array $data Parameters
33+
* <pre>
34+
* $data = [
35+
* 'cart_id' => (int) Cart ID. Required.
36+
* 'assignments' => [
37+
* [
38+
* 'address_id' => (array) Cart Address ID. Required.
39+
* 'item_id' => (int) Cart Item ID. Required.
40+
* 'qty' => (int) Quantity. Optional. Default: 1.
41+
* ]
42+
* ]
43+
* ]
44+
* </pre>
45+
*/
46+
public function apply(array $data = []): ?DataObject
47+
{
48+
$cart = $this->cartRepository->get($data['cart_id']);
49+
foreach ($data['assignments'] as $assignment) {
50+
$cartAddress = $cart->getAddressById($assignment['address_id']);
51+
$cartItem = $cart->getItemById($assignment['item_id']);
52+
$qty = $assignment['qty'] ?? 1;
53+
$cartAddressItem = $cartAddress->getItemByQuoteItemId($assignment['item_id']);
54+
if ($cartAddressItem) {
55+
$cartAddressItem->setQty((int)($cartAddressItem->getQty() + $qty));
56+
} else {
57+
$cartAddress->addItem($cartItem, $qty);
58+
}
59+
}
60+
$cart->setTotalsCollectedFlag(false);
61+
$cart->collectTotals();
62+
$this->cartRepository->save($cart);
63+
return null;
64+
}
65+
}

app/code/Magento/Weee/Model/Total/Quote/WeeeTax.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,20 @@ public function collect(
6868
$weeeCodeToWeeeTaxDetailsMap[$weeeCode] = $weeeTaxDetails;
6969
}
7070
}
71-
$productTaxes = [];
71+
7272
//Process each item that has taxable weee
7373
foreach ($itemToWeeeCodeMap as $mapping) {
74+
$itemWeeTaxDetails = array_intersect_key(
75+
$weeeCodeToWeeeTaxDetailsMap,
76+
array_fill_keys($mapping['weeeCodes'], null)
77+
);
78+
if (empty($itemWeeTaxDetails)) {
79+
continue;
80+
}
7481
$item = $mapping['item'];
7582

7683
$this->weeeData->setApplied($item, []);
77-
84+
$productTaxes = $this->weeeData->getApplied($item);
7885
$totalValueInclTax = 0;
7986
$baseTotalValueInclTax = 0;
8087
$totalRowValueInclTax = 0;
@@ -86,12 +93,7 @@ public function collect(
8693
$baseTotalRowValueExclTax = 0;
8794

8895
//Process each taxed weee attribute of an item
89-
foreach ($mapping['weeeCodes'] as $weeeCode) {
90-
if (!array_key_exists($weeeCode, $weeeCodeToWeeeTaxDetailsMap)) {
91-
//Need to ensure that everyone is in sync for which weee code to process
92-
continue;
93-
}
94-
$weeeTaxDetails = $weeeCodeToWeeeTaxDetailsMap[$weeeCode];
96+
foreach ($itemWeeTaxDetails as $weeeCode => $weeeTaxDetails) {
9597
$attributeCode = explode('-', $weeeCode)[1];
9698

9799
$valueExclTax = $weeeTaxDetails[CommonTaxCollector::KEY_TAX_DETAILS_PRICE_EXCL_TAX];
@@ -115,17 +117,15 @@ public function collect(
115117
$baseTotalRowValueExclTax += $baseRowValueExclTax;
116118

117119
$productTaxes[] = [
118-
[
119-
'title' => $attributeCode, //TODO: fix this
120-
'base_amount' => $baseValueExclTax,
121-
'amount' => $valueExclTax,
122-
'row_amount' => $rowValueExclTax,
123-
'base_row_amount' => $baseRowValueExclTax,
124-
'base_amount_incl_tax' => $baseValueInclTax,
125-
'amount_incl_tax' => $valueInclTax,
126-
'row_amount_incl_tax' => $rowValueInclTax,
127-
'base_row_amount_incl_tax' => $baseRowValueInclTax,
128-
],
120+
'title' => $attributeCode, //TODO: fix this
121+
'base_amount' => $baseValueExclTax,
122+
'amount' => $valueExclTax,
123+
'row_amount' => $rowValueExclTax,
124+
'base_row_amount' => $baseRowValueExclTax,
125+
'base_amount_incl_tax' => $baseValueInclTax,
126+
'amount_incl_tax' => $valueInclTax,
127+
'row_amount_incl_tax' => $rowValueInclTax,
128+
'base_row_amount_incl_tax' => $baseRowValueInclTax,
129129
];
130130
}
131131

@@ -147,11 +147,11 @@ public function collect(
147147
$baseTotalRowValueInclTax
148148
);
149149

150+
$this->weeeData->setApplied(
151+
$item,
152+
$productTaxes
153+
);
150154
}
151-
$this->weeeData->setApplied(
152-
$item,
153-
array_merge($this->weeeData->getApplied($item), ...$productTaxes)
154-
);
155155
}
156156
return $this;
157157
}
@@ -239,7 +239,7 @@ protected function processTotalAmount(
239239
*/
240240
public function fetch(Quote $quote, Total $total)
241241
{
242-
$items = $total['quote_items'] ?? [];
242+
$items = $total['address_quote_items'] ?? [];
243243

244244
$weeeTotal = $this->weeeData->getTotalAmounts($items, $quote->getStore());
245245
if ($weeeTotal) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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\Weee\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
12+
class Attribute extends \Magento\Catalog\Test\Fixture\Attribute
13+
{
14+
private const DEFAULT_DATA = [
15+
'frontend_input' => 'weee',
16+
];
17+
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function apply(array $data = []): ?DataObject
22+
{
23+
return parent::apply(array_merge(self::DEFAULT_DATA, $data));
24+
}
25+
}

0 commit comments

Comments
 (0)