-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 2.3-develop into ENGCOM-4342-magento-magento2-21363
- Loading branch information
Showing
28 changed files
with
1,607 additions
and
392 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
app/code/Magento/Fedex/Plugin/Block/DataProviders/Tracking/ChangeTitle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Fedex\Plugin\Block\DataProviders\Tracking; | ||
|
||
use Magento\Fedex\Model\Carrier; | ||
use Magento\Shipping\Model\Tracking\Result\Status; | ||
use Magento\Shipping\Block\DataProviders\Tracking\DeliveryDateTitle as Subject; | ||
|
||
/** | ||
* Plugin to change delivery date title with FedEx customized value | ||
*/ | ||
class ChangeTitle | ||
{ | ||
/** | ||
* Title modification in case if FedEx used as carrier | ||
* | ||
* @param Subject $subject | ||
* @param \Magento\Framework\Phrase|string $result | ||
* @param Status $trackingStatus | ||
* @return \Magento\Framework\Phrase|string | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterGetTitle(Subject $subject, $result, Status $trackingStatus) | ||
{ | ||
if ($trackingStatus->getCarrier() === Carrier::CODE) { | ||
$result = __('Expected Delivery:'); | ||
} | ||
return $result; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/code/Magento/Fedex/Plugin/Block/Tracking/PopupDeliveryDate.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Fedex\Plugin\Block\Tracking; | ||
|
||
use Magento\Shipping\Block\Tracking\Popup; | ||
use Magento\Fedex\Model\Carrier; | ||
use Magento\Shipping\Model\Tracking\Result\Status; | ||
|
||
/** | ||
* Plugin to update delivery date value in case if Fedex used | ||
*/ | ||
class PopupDeliveryDate | ||
{ | ||
/** | ||
* Show only date for expected delivery in case if Fedex is a carrier | ||
* | ||
* @param Popup $subject | ||
* @param string $result | ||
* @param string $date | ||
* @param string $time | ||
* @return string | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterFormatDeliveryDateTime(Popup $subject, $result, $date, $time) | ||
{ | ||
if ($this->getCarrier($subject) === Carrier::CODE) { | ||
$result = $subject->formatDeliveryDate($date); | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Retrieve carrier name from tracking info | ||
* | ||
* @param Popup $subject | ||
* @return string | ||
*/ | ||
private function getCarrier(Popup $subject): string | ||
{ | ||
foreach ($subject->getTrackingInfo() as $trackingData) { | ||
foreach ($trackingData as $trackingInfo) { | ||
if ($trackingInfo instanceof Status) { | ||
$carrier = $trackingInfo->getCarrier(); | ||
return $carrier; | ||
} | ||
} | ||
} | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/code/Magento/QuoteGraphQl/Model/Resolver/SelectedPaymentMethod.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class SelectedPaymentMethod implements ResolverInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
if (!isset($value['model'])) { | ||
throw new LocalizedException(__('"model" value should be specified')); | ||
} | ||
|
||
/** @var \Magento\Quote\Model\Quote $cart */ | ||
$cart = $value['model']; | ||
|
||
$payment = $cart->getPayment(); | ||
if (!$payment) { | ||
return []; | ||
} | ||
|
||
return [ | ||
'code' => $payment->getMethod(), | ||
'purchase_order_number' => $payment->getPoNumber(), | ||
]; | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentMethodOnCart.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\QuoteGraphQl\Model\Resolver; | ||
|
||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Exception\GraphQlInputException; | ||
use Magento\Framework\GraphQl\Query\ResolverInterface; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Framework\Stdlib\ArrayManager; | ||
use Magento\Quote\Api\Data\PaymentInterface; | ||
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser; | ||
use Magento\Quote\Api\Data\PaymentInterfaceFactory; | ||
use Magento\Quote\Api\PaymentMethodManagementInterface; | ||
|
||
/** | ||
* Mutation resolver for setting payment method for shopping cart | ||
*/ | ||
class SetPaymentMethodOnCart implements ResolverInterface | ||
{ | ||
/** | ||
* @var GetCartForUser | ||
*/ | ||
private $getCartForUser; | ||
|
||
/** | ||
* @var ArrayManager | ||
*/ | ||
private $arrayManager; | ||
|
||
/** | ||
* @var PaymentMethodManagementInterface | ||
*/ | ||
private $paymentMethodManagement; | ||
|
||
/** | ||
* @var PaymentInterfaceFactory | ||
*/ | ||
private $paymentFactory; | ||
|
||
/** | ||
* @param GetCartForUser $getCartForUser | ||
* @param ArrayManager $arrayManager | ||
* @param PaymentMethodManagementInterface $paymentMethodManagement | ||
* @param PaymentInterfaceFactory $paymentFactory | ||
*/ | ||
public function __construct( | ||
GetCartForUser $getCartForUser, | ||
ArrayManager $arrayManager, | ||
PaymentMethodManagementInterface $paymentMethodManagement, | ||
PaymentInterfaceFactory $paymentFactory | ||
) { | ||
$this->getCartForUser = $getCartForUser; | ||
$this->arrayManager = $arrayManager; | ||
$this->paymentMethodManagement = $paymentMethodManagement; | ||
$this->paymentFactory = $paymentFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) | ||
{ | ||
$maskedCartId = (string)$this->arrayManager->get('input/cart_id', $args); | ||
if (!$maskedCartId) { | ||
throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); | ||
} | ||
|
||
$paymentMethod = $this->arrayManager->get('input/payment_method', $args); | ||
if (!$paymentMethod) { | ||
throw new GraphQlInputException(__('Required parameter "payment_method" is missing')); | ||
} | ||
|
||
$paymentMethodCode = (string) $this->arrayManager->get('input/payment_method/code', $args); | ||
if (!$paymentMethodCode) { | ||
throw new GraphQlInputException(__('Required parameter payment "code" is missing')); | ||
} | ||
|
||
$poNumber = $this->arrayManager->get('input/payment_method/purchase_order_number', $args); | ||
|
||
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId()); | ||
$payment = $this->paymentFactory->create([ | ||
'data' => [ | ||
PaymentInterface::KEY_METHOD => $paymentMethodCode, | ||
PaymentInterface::KEY_PO_NUMBER => $poNumber, | ||
PaymentInterface::KEY_ADDITIONAL_DATA => [], | ||
] | ||
]); | ||
|
||
try { | ||
$this->paymentMethodManagement->set($cart->getId(), $payment); | ||
} catch (LocalizedException $e) { | ||
throw new GraphQlInputException(__($e->getMessage())); | ||
} | ||
|
||
return [ | ||
'cart' => [ | ||
'cart_id' => $maskedCartId, | ||
'model' => $cart, | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.