Skip to content

Commit

Permalink
ENGCOM-5699: Correct cart_item_id source for address items #853
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaorobei authored Oct 14, 2019
2 parents d03e320 + 617fdd1 commit b5721d9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Magento\QuoteGraphQl\Model\Cart;

use Magento\Customer\Model\Address\AbstractAddress;
use Magento\Framework\Api\ExtensibleDataObjectConverter;
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Model\Quote\Address as QuoteAddress;
Expand Down Expand Up @@ -41,28 +40,37 @@ public function execute(QuoteAddress $address): array
$addressData = $this->dataObjectConverter->toFlatArray($address, [], AddressInterface::class);
$addressData['model'] = $address;

$addressData = array_merge($addressData, [
'country' => [
'code' => $address->getCountryId(),
'label' => $address->getCountry()
],
'region' => [
'code' => $address->getRegionCode(),
'label' => $address->getRegion()
],
'street' => $address->getStreet(),
'items_weight' => $address->getWeight(),
'customer_notes' => $address->getCustomerNotes()
]);
$addressData = array_merge(
$addressData,
[
'country' => [
'code' => $address->getCountryId(),
'label' => $address->getCountry()
],
'region' => [
'code' => $address->getRegionCode(),
'label' => $address->getRegion()
],
'street' => $address->getStreet(),
'items_weight' => $address->getWeight(),
'customer_notes' => $address->getCustomerNotes()
]
);

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

$addressItemsData = [];
foreach ($address->getAllItems() as $addressItem) {
if ($addressItem instanceof \Magento\Quote\Model\Quote\Item) {
$itemId = $addressItem->getItemId();
} else {
$itemId = $addressItem->getQuoteItemId();
}

$addressItemsData[] = [
'cart_item_id' => $addressItem->getQuoteItemId(),
'cart_item_id' => $itemId,
'quantity' => $addressItem->getQty()
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function testGetAvailableShippingMethods()
'value' => 10,
'currency' => 'USD',
],
'base_amount' => null,
];
self::assertEquals(
$expectedAddressData,
Expand Down Expand Up @@ -135,25 +136,46 @@ private function getQuery(string $maskedQuoteId): string
query {
cart (cart_id: "{$maskedQuoteId}") {
shipping_addresses {
available_shipping_methods {
amount {
value
currency
}
carrier_code
carrier_title
error_message
method_code
method_title
price_excl_tax {
value
currency
}
price_incl_tax {
value
currency
}
cart_items {
cart_item_id
quantity
}
available_shipping_methods {
amount {
value
currency
}
carrier_code
carrier_title
error_message
method_code
method_title
price_excl_tax {
value
currency
}
price_incl_tax {
value
currency
}
base_amount {
value
currency
}
carrier_code
carrier_title
error_message
method_code
method_title
price_excl_tax {
value
currency
}
price_incl_tax {
value
currency
}
}
}
}
}
Expand Down

0 comments on commit b5721d9

Please sign in to comment.