|
10 | 10 | use Magento\Framework\Api\ExtensibleDataObjectConverter;
|
11 | 11 | use Magento\Quote\Api\Data\AddressInterface;
|
12 | 12 | use Magento\Quote\Api\Data\CartInterface;
|
| 13 | +use Magento\Quote\Model\Quote\Address as QuoteAddress; |
13 | 14 |
|
14 | 15 | /**
|
15 | 16 | * Class AddressDataProvider
|
@@ -49,22 +50,45 @@ public function getCartAddresses(CartInterface $cart): array
|
49 | 50 | if ($shippingAddress) {
|
50 | 51 | $shippingData = $this->dataObjectConverter->toFlatArray($shippingAddress, [], AddressInterface::class);
|
51 | 52 | $shippingData['address_type'] = 'SHIPPING';
|
52 |
| - $shippingData['selected_shipping_method'] = [ |
53 |
| - 'code' => $shippingAddress->getShippingMethod(), |
54 |
| - 'label' => $shippingAddress->getShippingDescription(), |
55 |
| - 'free_shipping' => $shippingAddress->getFreeShipping(), |
56 |
| - ]; |
57 |
| - $shippingData['items_weight'] = $shippingAddress->getWeight(); |
58 |
| - $shippingData['customer_notes'] = $shippingAddress->getCustomerNotes(); |
59 |
| - $addressData[] = $shippingData; |
| 53 | + $addressData[] = array_merge($shippingData, $this->extractAddressData($shippingAddress)); |
60 | 54 | }
|
61 | 55 |
|
62 | 56 | if ($billingAddress) {
|
63 | 57 | $billingData = $this->dataObjectConverter->toFlatArray($billingAddress, [], AddressInterface::class);
|
64 | 58 | $billingData['address_type'] = 'BILLING';
|
65 |
| - $addressData[] = $billingData; |
| 59 | + $addressData[] = array_merge($billingData, $this->extractAddressData($billingAddress)); |
66 | 60 | }
|
67 | 61 |
|
68 | 62 | return $addressData;
|
69 | 63 | }
|
| 64 | + |
| 65 | + /** |
| 66 | + * Extract the necessary address fields from address model |
| 67 | + * |
| 68 | + * @param QuoteAddress $address |
| 69 | + * @return array |
| 70 | + */ |
| 71 | + private function extractAddressData(QuoteAddress $address): array |
| 72 | + { |
| 73 | + $addressData = [ |
| 74 | + 'country' => [ |
| 75 | + 'code' => $address->getCountryId(), |
| 76 | + 'label' => $address->getCountry() |
| 77 | + ], |
| 78 | + 'region' => [ |
| 79 | + 'code' => $address->getRegionCode(), |
| 80 | + 'label' => $address->getRegion() |
| 81 | + ], |
| 82 | + 'street' => $address->getStreet(), |
| 83 | + 'selected_shipping_method' => [ |
| 84 | + 'code' => $address->getShippingMethod(), |
| 85 | + 'label' => $address->getShippingDescription(), |
| 86 | + 'free_shipping' => $address->getFreeShipping(), |
| 87 | + ], |
| 88 | + 'items_weight' => $address->getWeight(), |
| 89 | + 'customer_notes' => $address->getCustomerNotes() |
| 90 | + ]; |
| 91 | + |
| 92 | + return $addressData; |
| 93 | + } |
70 | 94 | }
|
0 commit comments