forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from suryakant-krish/2.2-develop-PR-port-19640
[Backport] Fixed icon alignment: Frontend Component theme sort by arrow icon vertical alignment issue. magento#19639
- Loading branch information
Showing
191 changed files
with
4,300 additions
and
575 deletions.
There are no files selected for viewing
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
76 changes: 76 additions & 0 deletions
76
app/code/Magento/Braintree/Model/Paypal/OrderCancellationService.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,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Braintree\Model\Paypal; | ||
|
||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Sales\Api\Data\OrderInterface; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
|
||
/** | ||
* The service to cancel an order and void authorization transaction. | ||
*/ | ||
class OrderCancellationService | ||
{ | ||
/** | ||
* @var OrderRepositoryInterface | ||
*/ | ||
private $orderRepository; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @param OrderRepositoryInterface $orderRepository | ||
*/ | ||
public function __construct( | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
OrderRepositoryInterface $orderRepository | ||
) { | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
$this->orderRepository = $orderRepository; | ||
} | ||
|
||
/** | ||
* Cancels an order and authorization transaction. | ||
* | ||
* @param string $incrementId | ||
* @return bool | ||
*/ | ||
public function execute($incrementId): bool | ||
{ | ||
$order = $this->getOrder($incrementId); | ||
if ($order === null) { | ||
return false; | ||
} | ||
|
||
// `\Magento\Sales\Model\Service\OrderService::cancel` cannot be used for cancellation as the service uses | ||
// the order repository with outdated payment method instance (ex. contains Vault instead of Braintree) | ||
$order->cancel(); | ||
$this->orderRepository->save($order); | ||
return true; | ||
} | ||
|
||
/** | ||
* Gets order by increment ID. | ||
* | ||
* @param string $incrementId | ||
* @return OrderInterface|null | ||
*/ | ||
private function getOrder(string $incrementId) | ||
{ | ||
$searchCriteria = $this->searchCriteriaBuilder->addFilter(OrderInterface::INCREMENT_ID, $incrementId) | ||
->create(); | ||
|
||
$items = $this->orderRepository->getList($searchCriteria) | ||
->getItems(); | ||
|
||
return array_pop($items); | ||
} | ||
} |
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,79 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Braintree\Plugin; | ||
|
||
use Magento\Braintree\Model\Paypal\OrderCancellationService; | ||
use Magento\Braintree\Model\Ui\ConfigProvider; | ||
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PayPalConfigProvider; | ||
use Magento\Quote\Api\CartManagementInterface; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Api\Data\PaymentInterface; | ||
|
||
/** | ||
* Cancels an order and an authorization transaction. | ||
*/ | ||
class OrderCancellation | ||
{ | ||
/** | ||
* @var OrderCancellationService | ||
*/ | ||
private $orderCancellationService; | ||
|
||
/** | ||
* @var CartRepositoryInterface | ||
*/ | ||
private $quoteRepository; | ||
|
||
/** | ||
* @param OrderCancellationService $orderCancellationService | ||
* @param CartRepositoryInterface $quoteRepository | ||
*/ | ||
public function __construct( | ||
OrderCancellationService $orderCancellationService, | ||
CartRepositoryInterface $quoteRepository | ||
) { | ||
$this->orderCancellationService = $orderCancellationService; | ||
$this->quoteRepository = $quoteRepository; | ||
} | ||
|
||
/** | ||
* Cancels an order if an exception occurs during the order creation. | ||
* | ||
* @param CartManagementInterface $subject | ||
* @param \Closure $proceed | ||
* @param int $cartId | ||
* @param PaymentInterface $payment | ||
* @return int | ||
* @throws \Exception | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function aroundPlaceOrder( | ||
CartManagementInterface $subject, | ||
\Closure $proceed, | ||
$cartId, | ||
PaymentInterface $payment = null | ||
) { | ||
try { | ||
return $proceed($cartId, $payment); | ||
} catch (\Exception $e) { | ||
$quote = $this->quoteRepository->get((int) $cartId); | ||
$payment = $quote->getPayment(); | ||
$paymentCodes = [ | ||
ConfigProvider::CODE, | ||
ConfigProvider::CC_VAULT_CODE, | ||
PayPalConfigProvider::PAYPAL_CODE, | ||
PayPalConfigProvider::PAYPAL_VAULT_CODE | ||
]; | ||
if (in_array($payment->getMethod(), $paymentCodes)) { | ||
$incrementId = $quote->getReservedOrderId(); | ||
$this->orderCancellationService->execute($incrementId); | ||
} | ||
|
||
throw $e; | ||
} | ||
} | ||
} |
Oops, something went wrong.