Skip to content

Commit c792758

Browse files
committed
MC-35653:MyAccount :: Order Details :: Payments Methods, shipping address, billing address by Order Number
- Fixed review comments
1 parent 11b1dcf commit c792758

File tree

3 files changed

+63
-66
lines changed

3 files changed

+63
-66
lines changed

app/code/Magento/SalesGraphQl/Model/Order/OrderAddress.php

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
namespace Magento\SalesGraphQl\Model\Order;
99

1010
use Magento\Quote\Model\Quote\Address;
11+
use Magento\Sales\Api\Data\OrderAddressInterface;
1112
use Magento\Sales\Api\Data\OrderInterface;
12-
use Magento\Sales\Model\Order\Address as SalesOrderAddress;
1313

1414
/**
1515
* Class to fetch the order address details
@@ -20,19 +20,16 @@ class OrderAddress
2020
* Get the order Shipping address
2121
*
2222
* @param OrderInterface $order
23-
* @return array
23+
* @return array|null
2424
*/
2525
public function getOrderShippingAddress(
2626
OrderInterface $order
27-
): array {
28-
$shippingAddress = [];
29-
$orderAddresses = $order->getAddresses();
30-
foreach ($orderAddresses as $orderAddress) {
31-
if ($orderAddress->getDataByKey("address_type") === address::TYPE_SHIPPING) {
32-
$shippingAddress = $this->OrderAddressDataFormatter(
33-
$orderAddress,
34-
address::TYPE_SHIPPING
35-
);
27+
) {
28+
$shippingAddress = null;
29+
$orderShippingAddress = $order->getShippingAddress() ?? null;
30+
if ($orderShippingAddress) {
31+
if ($orderShippingAddress->getAddressType() === ADDRESS::TYPE_SHIPPING) {
32+
$shippingAddress = $this->OrderAddressDataFormatter($orderShippingAddress);
3633
}
3734
}
3835
return $shippingAddress;
@@ -42,19 +39,16 @@ public function getOrderShippingAddress(
4239
* Get the order billing address
4340
*
4441
* @param OrderInterface $order
45-
* @return array
42+
* @return array|null
4643
*/
4744
public function getOrderBillingAddress(
4845
OrderInterface $order
49-
): array {
50-
$billingAddress = [];
51-
$orderAddresses = $order->getAddresses();
52-
foreach ($orderAddresses as $orderAddress) {
53-
if ($orderAddress->getDataByKey("address_type") === address::TYPE_BILLING) {
54-
$billingAddress = $this->OrderAddressDataFormatter(
55-
$orderAddress,
56-
address::TYPE_BILLING
57-
);
46+
) {
47+
$billingAddress = null;
48+
$orderBillingAddress = $order->getBillingAddress() ?? null;
49+
if ($orderBillingAddress) {
50+
if ($orderBillingAddress->getAddressType() === ADDRESS::TYPE_BILLING) {
51+
$billingAddress = $this->OrderAddressDataFormatter($orderBillingAddress);
5852
}
5953
}
6054
return $billingAddress;
@@ -63,34 +57,29 @@ public function getOrderBillingAddress(
6357
/**
6458
* Customer Order address data formatter
6559
*
66-
* @param SalesOrderAddress $orderAddress
67-
* @param string $addressType
60+
* @param OrderAddressInterface $orderAddress
6861
* @return array
6962
*/
7063
private function OrderAddressDataFormatter(
71-
SalesOrderAddress $orderAddress,
72-
string $addressType
64+
OrderAddressInterface $orderAddress
7365
): array {
74-
$orderAddressData = [];
75-
if ($addressType === $orderAddress->getDataByKey("address_type")) {
76-
$orderAddressData = [
77-
'firstname' => $orderAddress->getDataByKey('firstname'),
78-
'lastname' => $orderAddress->getDataByKey('lastname'),
79-
'middlename' => $orderAddress->getDataByKey('middlename'),
80-
'postcode' => $orderAddress->getDataByKey('postcode'),
81-
'prefix' => $orderAddress->getDataByKey('prefix'),
82-
'suffix' => $orderAddress->getDataByKey('suffix'),
83-
'city' => $orderAddress->getDataByKey('city'),
84-
'company' => $orderAddress->getDataByKey('company'),
85-
'fax' => $orderAddress->getDataByKey('fax'),
86-
'telephone' => $orderAddress->getDataByKey('telephone'),
87-
'vat_id' => $orderAddress->getDataByKey('vat_id'),
88-
'street' => explode("\n", $orderAddress->getDataByKey('street')),
89-
'country_code' => $orderAddress->getDataByKey('country_id'),
90-
'region' => $orderAddress->getDataByKey('region'),
91-
'region_id' => $orderAddress->getDataByKey('region_id')
92-
];
93-
}
94-
return $orderAddressData;
66+
return
67+
[
68+
'firstname' => $orderAddress->getFirstname(),
69+
'lastname' => $orderAddress->getLastname(),
70+
'middlename' => $orderAddress->getMiddlename(),
71+
'postcode' => $orderAddress->getPostcode(),
72+
'prefix' => $orderAddress->getFirstname(),
73+
'suffix' => $orderAddress->getFirstname(),
74+
'street' => $orderAddress->getStreet(),
75+
'country_code' => $orderAddress->getCountryId(),
76+
'city' => $orderAddress->getCity(),
77+
'company' => $orderAddress->getCompany(),
78+
'fax' => $orderAddress->getFax(),
79+
'telephone' => $orderAddress->getTelephone(),
80+
'vat_id' => $orderAddress->getVatId(),
81+
'region_id' => $orderAddress->getRegionId(),
82+
'region' => $orderAddress->getRegion()
83+
];
9584
}
9685
}

app/code/Magento/SalesGraphQl/Model/Order/OrderPayments.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ class OrderPayments
2121
public function getOrderPaymentMethod(OrderInterface $orderModel): array
2222
{
2323
$orderPayment = $orderModel->getPayment();
24+
$paymentAdditionalInfo = $orderModel->getExtensionAttributes()->getPaymentAdditionalInfo();
25+
$paymentAdditionalData = [];
26+
foreach ($paymentAdditionalInfo as $key => $paymentAdditionalInfoDetails) {
27+
$paymentAdditionalData[$key]['name'] = $paymentAdditionalInfoDetails->getKey();
28+
$paymentAdditionalData[$key]['value'] = $paymentAdditionalInfoDetails->getValue();
29+
}
2430
$additionalInformationCcType = $orderPayment->getCcType();
2531
$additionalInformationCcNumber = $orderPayment->getCcLast4();
26-
if ($orderPayment->getMethod() === 'checkmo' || $orderPayment->getMethod() === 'free') {
32+
if ($orderPayment->getMethod() === 'checkmo' || $orderPayment->getMethod() === 'free' ||
33+
$orderPayment->getMethod() === 'purchaseorder' ||$orderPayment->getMethod() === 'cashondelivery' ||
34+
$orderPayment->getMethod() === 'banktransfer'
35+
) {
2736
$additionalData = [];
2837
} else {
2938
$additionalData = [
@@ -40,11 +49,10 @@ public function getOrderPaymentMethod(OrderInterface $orderModel): array
4049

4150
return [
4251
[
43-
'name' => $orderPayment->getAdditionalInformation()['method_title'],
44-
'type' => $orderPayment->getMethod(),
52+
'name' => $orderPayment->getAdditionalInformation()['method_title'] ?? null,
53+
'type' => $orderPayment->getMethod() ?? null,
4554
'additional_data' => $additionalData
4655
]
4756
];
4857
}
4958
}
50-

app/code/Magento/SalesGraphQl/etc/schema.graphqls

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ type CustomerOrder @doc(description: "Contains details about each of the custome
5959
grand_total: Float @deprecated(reason: "Use the totals.grand_total attribute instead")
6060
}
6161

62-
type OrderAddress @doc(description: "OrderAddress contains detailed information about the order billing and shipping addresses"){
63-
firstname: String! @doc(description: "The first name of the person associated with the shipping/billing address on the order")
64-
lastname: String! @doc(description: "The family name of the person associated with the shipping/billing address on the order")
65-
middlename: String @doc(description: "The middle name of the person associated with the shipping/billing address on the order")
66-
region: String @doc(description: "The state or province name on the order")
67-
region_id: ID @doc(description: "The unique ID for a pre-defined region on the order")
68-
country_code: CountryCodeEnum @doc(description: "The customer's country on the order")
69-
street: [String]! @doc(description: "An array of strings that define the street number and name on the order")
70-
company: String @doc(description: "The customer's company on the order")
71-
telephone: String! @doc(description: "The telephone number on the order")
72-
fax: String @doc(description: "The fax number on the order")
73-
postcode: String @doc(description: "The customer's order ZIP or postal code on the order")
74-
city: String! @doc(description: "The city or town on the order")
75-
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs. on the order")
76-
suffix: String @doc(description: "A value such as Sr., Jr., or III on the order")
77-
vat_id: String @doc(description: "The customer's Value-added tax (VAT) number (for corporate customers) on the order")
62+
type OrderAddress @doc(description: "OrderAddress contains detailed information about an order's billing and shipping addresses"){
63+
firstname: String! @doc(description: "The first name of the person associated with the shipping/billing address")
64+
lastname: String! @doc(description: "The family name of the person associated with the shipping/billing address")
65+
middlename: String @doc(description: "The middle name of the person associated with the shipping/billing address")
66+
region: String @doc(description: "The state or province name")
67+
region_id: ID @doc(description: "The unique ID for a pre-defined region")
68+
country_code: CountryCodeEnum @doc(description: "The customer's country")
69+
street: [String!]! @doc(description: "An array of strings that define the street number and name")
70+
company: String @doc(description: "The customer's company")
71+
telephone: String! @doc(description: "The telephone number")
72+
fax: String @doc(description: "The fax number")
73+
postcode: String @doc(description: "The customer's order ZIP or postal code")
74+
city: String! @doc(description: "The city or town")
75+
prefix: String @doc(description: "An honorific, such as Dr., Mr., or Mrs.")
76+
suffix: String @doc(description: "A value such as Sr., Jr., or III")
77+
vat_id: String @doc(description: "The customer's Value-added tax (VAT) number (for corporate customers)")
7878
}
7979

8080
interface OrderItemInterface @doc(description: "Order item details") @typeResolver(class: "Magento\\SalesGraphQl\\Model\\OrderItemTypeResolver") {

0 commit comments

Comments
 (0)