Skip to content

Commit 7e431c9

Browse files
merge magento/2.3-develop into magento-tsg/2.3-develop-mftf-pr13
2 parents 3cea8af + 908ed15 commit 7e431c9

28 files changed

+1607
-392
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Fedex\Plugin\Block\DataProviders\Tracking;
8+
9+
use Magento\Fedex\Model\Carrier;
10+
use Magento\Shipping\Model\Tracking\Result\Status;
11+
use Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle as Subject;
12+
13+
/**
14+
* Plugin to change delivery date title with FedEx customized value
15+
*/
16+
class ChangeTitle
17+
{
18+
/**
19+
* Title modification in case if FedEx used as carrier
20+
*
21+
* @param Subject $subject
22+
* @param \Magento\Framework\Phrase|string $result
23+
* @param Status $trackingStatus
24+
* @return \Magento\Framework\Phrase|string
25+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
26+
*/
27+
public function afterGetTitle(Subject $subject, $result, Status $trackingStatus)
28+
{
29+
if ($trackingStatus->getCarrier() === Carrier::CODE) {
30+
$result = __('Expected Delivery:');
31+
}
32+
return $result;
33+
}
34+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Fedex\Plugin\Block\Tracking;
8+
9+
use Magento\Shipping\Block\Tracking\Popup;
10+
use Magento\Fedex\Model\Carrier;
11+
use Magento\Shipping\Model\Tracking\Result\Status;
12+
13+
/**
14+
* Plugin to update delivery date value in case if Fedex used
15+
*/
16+
class PopupDeliveryDate
17+
{
18+
/**
19+
* Show only date for expected delivery in case if Fedex is a carrier
20+
*
21+
* @param Popup $subject
22+
* @param string $result
23+
* @param string $date
24+
* @param string $time
25+
* @return string
26+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
27+
*/
28+
public function afterFormatDeliveryDateTime(Popup $subject, $result, $date, $time)
29+
{
30+
if ($this->getCarrier($subject) === Carrier::CODE) {
31+
$result = $subject->formatDeliveryDate($date);
32+
}
33+
return $result;
34+
}
35+
36+
/**
37+
* Retrieve carrier name from tracking info
38+
*
39+
* @param Popup $subject
40+
* @return string
41+
*/
42+
private function getCarrier(Popup $subject): string
43+
{
44+
foreach ($subject->getTrackingInfo() as $trackingData) {
45+
foreach ($trackingData as $trackingInfo) {
46+
if ($trackingInfo instanceof Status) {
47+
$carrier = $trackingInfo->getCarrier();
48+
return $carrier;
49+
}
50+
}
51+
}
52+
return '';
53+
}
54+
}

app/code/Magento/Fedex/etc/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@
2222
</argument>
2323
</arguments>
2424
</type>
25+
<type name="Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle">
26+
<plugin name="update_delivery_date_title" type="Magento\Fedex\Plugin\Block\DataProviders\Tracking\ChangeTitle"/>
27+
</type>
28+
<type name="Magento\Shipping\Block\Tracking\Popup">
29+
<plugin name="update_delivery_date_value" type="Magento\Fedex\Plugin\Block\Tracking\PopupDeliveryDate"/>
30+
</type>
2531
</config>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function execute(QuoteAddress $address): array
4141
$addressData['model'] = $address;
4242

4343
$addressData = array_merge($addressData, [
44+
'address_id' => $address->getId(),
4445
'country' => [
4546
'code' => $address->getCountryId(),
4647
'label' => $address->getCountry()

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public function __construct(
4545
* Get cart for user
4646
*
4747
* @param string $cartHash
48-
* @param int|null $userId
48+
* @param int|null $customerId
4949
* @return Quote
5050
* @throws GraphQlAuthorizationException
5151
* @throws GraphQlNoSuchEntityException
5252
*/
53-
public function execute(string $cartHash, ?int $userId): Quote
53+
public function execute(string $cartHash, ?int $customerId): Quote
5454
{
5555
try {
5656
$cartId = $this->maskedQuoteIdToQuoteId->execute($cartHash);
@@ -69,14 +69,14 @@ public function execute(string $cartHash, ?int $userId): Quote
6969
);
7070
}
7171

72-
$customerId = (int)$cart->getCustomerId();
72+
$cartCustomerId = (int)$cart->getCustomerId();
7373

7474
/* Guest cart, allow operations */
75-
if (!$customerId) {
75+
if (!$cartCustomerId && null === $customerId) {
7676
return $cart;
7777
}
7878

79-
if ($customerId !== $userId) {
79+
if ($cartCustomerId !== $customerId) {
8080
throw new GraphQlAuthorizationException(
8181
__(
8282
'The current user cannot perform operations on cart "%masked_cart_id"',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $b
9393
);
9494
}
9595
if (null === $customerAddressId) {
96+
$addressInput['country_id'] = $addressInput['country_code'] ?? '';
9697
$billingAddress = $this->addressModel->addData($addressInput);
9798
} else {
9899
$this->checkCustomerAccount->execute($context->getUserId(), $context->getUserType());

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function execute(ContextInterface $context, CartInterface $cart, array $s
8787
);
8888
}
8989
if (null === $customerAddressId) {
90+
$addressInput['country_id'] = $addressInput['country_code'] ?? '';
9091
$shippingAddress = $this->addressModel->addData($addressInput);
9192
} else {
9293
$this->checkCustomerAccount->execute($context->getUserId(), $context->getUserType());
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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\QuoteGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14+
15+
/**
16+
* @inheritdoc
17+
*/
18+
class SelectedPaymentMethod implements ResolverInterface
19+
{
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
24+
{
25+
if (!isset($value['model'])) {
26+
throw new LocalizedException(__('"model" value should be specified'));
27+
}
28+
29+
/** @var \Magento\Quote\Model\Quote $cart */
30+
$cart = $value['model'];
31+
32+
$payment = $cart->getPayment();
33+
if (!$payment) {
34+
return [];
35+
}
36+
37+
return [
38+
'code' => $payment->getMethod(),
39+
'purchase_order_number' => $payment->getPoNumber(),
40+
];
41+
}
42+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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\QuoteGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
use Magento\Framework\Stdlib\ArrayManager;
16+
use Magento\Quote\Api\Data\PaymentInterface;
17+
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
18+
use Magento\Quote\Api\Data\PaymentInterfaceFactory;
19+
use Magento\Quote\Api\PaymentMethodManagementInterface;
20+
21+
/**
22+
* Mutation resolver for setting payment method for shopping cart
23+
*/
24+
class SetPaymentMethodOnCart implements ResolverInterface
25+
{
26+
/**
27+
* @var GetCartForUser
28+
*/
29+
private $getCartForUser;
30+
31+
/**
32+
* @var ArrayManager
33+
*/
34+
private $arrayManager;
35+
36+
/**
37+
* @var PaymentMethodManagementInterface
38+
*/
39+
private $paymentMethodManagement;
40+
41+
/**
42+
* @var PaymentInterfaceFactory
43+
*/
44+
private $paymentFactory;
45+
46+
/**
47+
* @param GetCartForUser $getCartForUser
48+
* @param ArrayManager $arrayManager
49+
* @param PaymentMethodManagementInterface $paymentMethodManagement
50+
* @param PaymentInterfaceFactory $paymentFactory
51+
*/
52+
public function __construct(
53+
GetCartForUser $getCartForUser,
54+
ArrayManager $arrayManager,
55+
PaymentMethodManagementInterface $paymentMethodManagement,
56+
PaymentInterfaceFactory $paymentFactory
57+
) {
58+
$this->getCartForUser = $getCartForUser;
59+
$this->arrayManager = $arrayManager;
60+
$this->paymentMethodManagement = $paymentMethodManagement;
61+
$this->paymentFactory = $paymentFactory;
62+
}
63+
64+
/**
65+
* @inheritdoc
66+
*/
67+
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
68+
{
69+
$maskedCartId = (string)$this->arrayManager->get('input/cart_id', $args);
70+
if (!$maskedCartId) {
71+
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
72+
}
73+
74+
$paymentMethod = $this->arrayManager->get('input/payment_method', $args);
75+
if (!$paymentMethod) {
76+
throw new GraphQlInputException(__('Required parameter "payment_method" is missing'));
77+
}
78+
79+
$paymentMethodCode = (string) $this->arrayManager->get('input/payment_method/code', $args);
80+
if (!$paymentMethodCode) {
81+
throw new GraphQlInputException(__('Required parameter payment "code" is missing'));
82+
}
83+
84+
$poNumber = $this->arrayManager->get('input/payment_method/purchase_order_number', $args);
85+
86+
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId());
87+
$payment = $this->paymentFactory->create([
88+
'data' => [
89+
PaymentInterface::KEY_METHOD => $paymentMethodCode,
90+
PaymentInterface::KEY_PO_NUMBER => $poNumber,
91+
PaymentInterface::KEY_ADDITIONAL_DATA => [],
92+
]
93+
]);
94+
95+
try {
96+
$this->paymentMethodManagement->set($cart->getId(), $payment);
97+
} catch (LocalizedException $e) {
98+
throw new GraphQlInputException(__($e->getMessage()));
99+
}
100+
101+
return [
102+
'cart' => [
103+
'cart_id' => $maskedCartId,
104+
'model' => $cart,
105+
],
106+
];
107+
}
108+
}

app/code/Magento/QuoteGraphQl/Model/Resolver/SetShippingAddressesOnCart.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\QuoteGraphQl\Model\Resolver;
99

10+
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Framework\GraphQl\Config\Element\Field;
1112
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1213
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -67,7 +68,7 @@ public function __construct(
6768
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
6869
{
6970
$shippingAddresses = $this->arrayManager->get('input/shipping_addresses', $args);
70-
$maskedCartId = (string) $this->arrayManager->get('input/cart_id', $args);
71+
$maskedCartId = (string)$this->arrayManager->get('input/cart_id', $args);
7172

7273
if (!$maskedCartId) {
7374
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
@@ -79,7 +80,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7980

8081
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId());
8182

82-
$this->setShippingAddressesOnCart->execute($context, $cart, $shippingAddresses);
83+
try {
84+
$this->setShippingAddressesOnCart->execute($context, $cart, $shippingAddresses);
85+
} catch (LocalizedException $e) {
86+
throw new GraphQlInputException(__($e->getMessage()));
87+
}
8388

8489
return [
8590
'cart' => [

0 commit comments

Comments
 (0)