Skip to content

Commit 9576e12

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/2.3.1-release' into MC-14858
2 parents 111dd2c + ce13acf commit 9576e12

19 files changed

+654
-849
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ public function execute(Quote $cart, array $cartItemData): void
7575
throw new GraphQlNoSuchEntityException(__('Could not find a product with SKU "%sku"', ['sku' => $sku]));
7676
}
7777

78-
$result = $cart->addProduct($product, $this->createBuyRequest($qty, $customizableOptions));
78+
try {
79+
$result = $cart->addProduct($product, $this->createBuyRequest($qty, $customizableOptions));
80+
} catch (\Exception $e) {
81+
throw new GraphQlInputException(
82+
__(
83+
'Could not add the product with SKU %sku to the shopping cart: %message',
84+
['sku' => $sku, 'message' => $e->getMessage()]
85+
)
86+
);
87+
}
7988

8089
if (is_string($result)) {
8190
throw new GraphQlInputException(__($result));

app/code/Magento/QuoteGraphQl/Model/Cart/Address/AddressDataProvider.php

Lines changed: 0 additions & 94 deletions
This file was deleted.

app/code/Magento/QuoteGraphQl/Model/Cart/Address/BillingAddressDataProvider.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

app/code/Magento/QuoteGraphQl/Model/Cart/Address/ShippingAddressesDataProvider.php

Lines changed: 0 additions & 76 deletions
This file was deleted.

app/code/Magento/QuoteGraphQl/Model/Cart/Address/Mapper/Address.php renamed to app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromAddress.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,42 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\QuoteGraphQl\Model\Cart\Address\Mapper;
8+
namespace Magento\QuoteGraphQl\Model\Cart;
99

10+
use Magento\Framework\Api\ExtensibleDataObjectConverter;
11+
use Magento\Quote\Api\Data\AddressInterface;
1012
use Magento\Quote\Model\Quote\Address as QuoteAddress;
1113

1214
/**
13-
* Class Address
14-
*
1515
* Extract the necessary address fields from an Address model
1616
*/
17-
class Address
17+
class ExtractDataFromAddress
1818
{
1919
/**
20-
* Converts Address model data to nested array
20+
* @var ExtensibleDataObjectConverter
21+
*/
22+
private $dataObjectConverter;
23+
24+
/**
25+
* @param ExtensibleDataObjectConverter $dataObjectConverter
26+
*/
27+
public function __construct(ExtensibleDataObjectConverter $dataObjectConverter)
28+
{
29+
$this->dataObjectConverter = $dataObjectConverter;
30+
}
31+
32+
/**
33+
* Converts Address model to flat array
2134
*
2235
* @param QuoteAddress $address
2336
* @return array
2437
*/
25-
public function toNestedArray(QuoteAddress $address): array
38+
public function execute(QuoteAddress $address): array
2639
{
27-
$addressData = [
40+
$addressData = $this->dataObjectConverter->toFlatArray($address, [], AddressInterface::class);
41+
$addressData['model'] = $address;
42+
43+
$addressData = array_merge($addressData, [
2844
'country' => [
2945
'code' => $address->getCountryId(),
3046
'label' => $address->getCountry()
@@ -41,7 +57,7 @@ public function toNestedArray(QuoteAddress $address): array
4157
],
4258
'items_weight' => $address->getWeight(),
4359
'customer_notes' => $address->getCustomerNotes()
44-
];
60+
]);
4561

4662
if (!$address->hasItems()) {
4763
return $addressData;

app/code/Magento/QuoteGraphQl/Model/Cart/ExtractDataFromCart.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,36 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10+
use Magento\Framework\Exception\NoSuchEntityException;
1011
use Magento\Quote\Model\Quote;
1112
use Magento\Quote\Model\Quote\Item as QuoteItem;
13+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1214

1315
/**
1416
* Extract data from cart
1517
*/
1618
class ExtractDataFromCart
1719
{
20+
/**
21+
* @var QuoteIdToMaskedQuoteIdInterface
22+
*/
23+
private $quoteIdToMaskedQuoteId;
24+
25+
/**
26+
* @param QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
27+
*/
28+
public function __construct(
29+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId
30+
) {
31+
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId;
32+
}
33+
1834
/**
1935
* Extract data from cart
2036
*
2137
* @param Quote $cart
2238
* @return array
39+
* @throws NoSuchEntityException
2340
*/
2441
public function execute(Quote $cart): array
2542
{
@@ -43,6 +60,7 @@ public function execute(Quote $cart): array
4360
$appliedCoupon = $cart->getCouponCode();
4461

4562
return [
63+
'cart_id' => $this->quoteIdToMaskedQuoteId->execute((int)$cart->getId()),
4664
'items' => $items,
4765
'applied_coupon' => $appliedCoupon ? ['code' => $appliedCoupon] : null
4866
];

0 commit comments

Comments
 (0)