Skip to content

Commit

Permalink
Merge pull request #7 from suryakant-krish/2.2-develop-PR-port-19640
Browse files Browse the repository at this point in the history
[Backport] Fixed icon alignment: Frontend Component theme sort by arrow icon vertical alignment issue. magento#19639
  • Loading branch information
suryakant-krish authored Dec 13, 2018
2 parents dd51440 + 1a7ef7c commit d51f907
Show file tree
Hide file tree
Showing 191 changed files with 4,300 additions and 575 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ $fraudDetails = $payment->getAdditionalInformation('fraud_details');
<?php endif; ?>

<?php if(!empty($fraudDetails['fraud_filters'])): ?>
<b><?= $block->escapeHtml(__('Fraud Filters')) ?>:
</b></br>
<strong><?= $block->escapeHtml(__('Fraud Filters')) ?>:
</strong></br>
<?php foreach($fraudDetails['fraud_filters'] as $filter): ?>
<?= $block->escapeHtml($filter['name']) ?>:
<?= $block->escapeHtml($filter['action']) ?>
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/Braintree/Controller/Paypal/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function __construct(

/**
* @inheritdoc
*
* @throws LocalizedException
*/
public function execute()
Expand All @@ -71,7 +72,10 @@ public function execute()
return $resultRedirect->setPath('checkout/onepage/success', ['_secure' => true]);
} catch (\Exception $e) {
$this->logger->critical($e);
$this->messageManager->addExceptionMessage($e, $e->getMessage());
$this->messageManager->addExceptionMessage(
$e,
'The order #' . $quote->getReservedOrderId() . ' cannot be processed.'
);
}

return $resultRedirect->setPath('checkout/cart', ['_secure' => true]);
Expand Down
30 changes: 21 additions & 9 deletions app/code/Magento/Braintree/Model/Paypal/Helper/OrderPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*/
namespace Magento\Braintree\Model\Paypal\Helper;

use Magento\Quote\Model\Quote;
use Magento\Braintree\Model\Paypal\OrderCancellationService;
use Magento\Checkout\Api\AgreementsValidatorInterface;
use Magento\Checkout\Helper\Data;
use Magento\Checkout\Model\Type\Onepage;
use Magento\Customer\Model\Group;
use Magento\Customer\Model\Session;
use Magento\Checkout\Model\Type\Onepage;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Checkout\Api\AgreementsValidatorInterface;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Model\Quote;

/**
* Class OrderPlace
Expand Down Expand Up @@ -41,23 +42,29 @@ class OrderPlace extends AbstractHelper
private $checkoutHelper;

/**
* Constructor
*
* @var OrderCancellationService
*/
private $orderCancellationService;

/**
* @param CartManagementInterface $cartManagement
* @param AgreementsValidatorInterface $agreementsValidator
* @param Session $customerSession
* @param Data $checkoutHelper
* @param OrderCancellationService $orderCancellationService
*/
public function __construct(
CartManagementInterface $cartManagement,
AgreementsValidatorInterface $agreementsValidator,
Session $customerSession,
Data $checkoutHelper
Data $checkoutHelper,
OrderCancellationService $orderCancellationService
) {
$this->cartManagement = $cartManagement;
$this->agreementsValidator = $agreementsValidator;
$this->customerSession = $customerSession;
$this->checkoutHelper = $checkoutHelper;
$this->orderCancellationService = $orderCancellationService;
}

/**
Expand All @@ -66,7 +73,7 @@ public function __construct(
* @param Quote $quote
* @param array $agreement
* @return void
* @throws LocalizedException
* @throws \Exception
*/
public function execute(Quote $quote, array $agreement)
{
Expand All @@ -81,7 +88,12 @@ public function execute(Quote $quote, array $agreement)
$this->disabledQuoteAddressValidation($quote);

$quote->collectTotals();
$this->cartManagement->placeOrder($quote->getId());
try {
$this->cartManagement->placeOrder($quote->getId());
} catch (\Exception $e) {
$this->orderCancellationService->execute($quote->getReservedOrderId());
throw $e;
}
}

/**
Expand Down
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);
}
}
79 changes: 79 additions & 0 deletions app/code/Magento/Braintree/Plugin/OrderCancellation.php
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;
}
}
}
Loading

0 comments on commit d51f907

Please sign in to comment.