Skip to content

Commit

Permalink
Merge pull request #2 from Karlasa/2.3-develop-PR-port-16190
Browse files Browse the repository at this point in the history
[Forwardport] magento#16079 translation possibility for moreButtonText
  • Loading branch information
Karlasa authored Jun 19, 2018
2 parents e96dc9f + abcded5 commit 040e396
Show file tree
Hide file tree
Showing 583 changed files with 13,321 additions and 34,018 deletions.
75 changes: 57 additions & 18 deletions app/code/Magento/Authorizenet/Model/Directpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
*/
namespace Magento\Authorizenet\Model;

use Magento\Framework\HTTP\ZendClientFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Payment\Model\Method\ConfigInterface;
use Magento\Payment\Model\Method\TransparentInterface;
use Magento\Sales\Model\Order\Email\Sender\OrderSender;

/**
* Authorize.net DirectPost payment method model.
Expand Down Expand Up @@ -102,7 +101,7 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
protected $response;

/**
* @var OrderSender
* @var \Magento\Sales\Model\Order\Email\Sender\OrderSender
*/
protected $orderSender;

Expand All @@ -123,6 +122,16 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
*/
private $psrLogger;

/**
* @var \Magento\Sales\Api\PaymentFailuresInterface
*/
private $paymentFailures;

/**
* @var \Magento\Sales\Model\Order
*/
private $order;

/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
Expand All @@ -134,18 +143,19 @@ class Directpost extends \Magento\Authorizenet\Model\Authorizenet implements Tra
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Authorizenet\Helper\Data $dataHelper
* @param Directpost\Request\Factory $requestFactory
* @param Directpost\Response\Factory $responseFactory
* @param \Magento\Authorizenet\Model\Directpost\Request\Factory $requestFactory
* @param \Magento\Authorizenet\Model\Directpost\Response\Factory $responseFactory
* @param \Magento\Authorizenet\Model\TransactionService $transactionService
* @param \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
* @param OrderSender $orderSender
* @param \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender
* @param \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param \Magento\Sales\Api\PaymentFailuresInterface|null $paymentFailures
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -161,16 +171,17 @@ public function __construct(
\Magento\Authorizenet\Helper\Data $dataHelper,
\Magento\Authorizenet\Model\Directpost\Request\Factory $requestFactory,
\Magento\Authorizenet\Model\Directpost\Response\Factory $responseFactory,
TransactionService $transactionService,
ZendClientFactory $httpClientFactory,
\Magento\Authorizenet\Model\TransactionService $transactionService,
\Magento\Framework\HTTP\ZendClientFactory $httpClientFactory,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
\Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender,
\Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
\Magento\Sales\Api\PaymentFailuresInterface $paymentFailures = null
) {
$this->orderFactory = $orderFactory;
$this->storeManager = $storeManager;
Expand All @@ -179,6 +190,8 @@ public function __construct(
$this->orderSender = $orderSender;
$this->transactionRepository = $transactionRepository;
$this->_code = static::METHOD_CODE;
$this->paymentFailures = $paymentFailures ? : ObjectManager::getInstance()
->get(\Magento\Sales\Api\PaymentFailuresInterface::class);

parent::__construct(
$context,
Expand Down Expand Up @@ -561,13 +574,10 @@ public function process(array $responseData)
$this->validateResponse();

$response = $this->getResponse();
//operate with order
$orderIncrementId = $response->getXInvoiceNum();
$responseText = $this->dataHelper->wrapGatewayError($response->getXResponseReasonText());
$isError = false;
if ($orderIncrementId) {
/* @var $order \Magento\Sales\Model\Order */
$order = $this->orderFactory->create()->loadByIncrementId($orderIncrementId);
if ($this->getOrderIncrementId()) {
$order = $this->getOrderFromResponse();
//check payment method
$payment = $order->getPayment();
if (!$payment || $payment->getMethod() != $this->getCode()) {
Expand Down Expand Up @@ -632,9 +642,10 @@ public function checkResponseCode()
return true;
case self::RESPONSE_CODE_DECLINED:
case self::RESPONSE_CODE_ERROR:
throw new \Magento\Framework\Exception\LocalizedException(
$this->dataHelper->wrapGatewayError($this->getResponse()->getXResponseReasonText())
);
$errorMessage = $this->dataHelper->wrapGatewayError($this->getResponse()->getXResponseReasonText());
$order = $this->getOrderFromResponse();
$this->paymentFailures->handle((int)$order->getQuoteId(), $errorMessage);
throw new \Magento\Framework\Exception\LocalizedException($errorMessage);
default:
throw new \Magento\Framework\Exception\LocalizedException(
__('There was a payment authorization error.')
Expand Down Expand Up @@ -988,12 +999,40 @@ protected function getTransactionResponse($transactionId)
private function getPsrLogger()
{
if (null === $this->psrLogger) {
$this->psrLogger = \Magento\Framework\App\ObjectManager::getInstance()
$this->psrLogger = ObjectManager::getInstance()
->get(\Psr\Log\LoggerInterface::class);
}
return $this->psrLogger;
}

/**
* Fetch order by increment id from response.
*
* @return \Magento\Sales\Model\Order
*/
private function getOrderFromResponse(): \Magento\Sales\Model\Order
{
if (!$this->order) {
$this->order = $this->orderFactory->create();

if ($incrementId = $this->getOrderIncrementId()) {
$this->order = $this->order->loadByIncrementId($incrementId);
}
}

return $this->order;
}

/**
* Fetch order increment id from response.
*
* @return string
*/
private function getOrderIncrementId(): string
{
return $this->getResponse()->getXInvoiceNum();
}

/**
* Checks if filter action is Report Only. Transactions that trigger this filter are processed as normal,
* but are also reported in the Merchant Interface as triggering this filter.
Expand Down
51 changes: 44 additions & 7 deletions app/code/Magento/Authorizenet/Test/Unit/Model/DirectpostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Authorizenet\Test\Unit\Model;

use Magento\Sales\Api\PaymentFailuresInterface;
use Magento\Framework\Simplexml\Element;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Authorizenet\Model\Directpost;
Expand Down Expand Up @@ -74,6 +75,14 @@ class DirectpostTest extends \PHPUnit\Framework\TestCase
*/
protected $requestFactory;

/**
* @var PaymentFailuresInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $paymentFailures;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
Expand Down Expand Up @@ -104,6 +113,12 @@ protected function setUp()
->setMethods(['getTransactionDetails'])
->getMock();

$this->paymentFailures = $this->getMockBuilder(
PaymentFailuresInterface::class
)
->disableOriginalConstructor()
->getMock();

$this->requestFactory = $this->getRequestFactoryMock();
$httpClientFactoryMock = $this->getHttpClientFactoryMock();

Expand All @@ -117,7 +132,8 @@ protected function setUp()
'responseFactory' => $this->responseFactoryMock,
'transactionRepository' => $this->transactionRepositoryMock,
'transactionService' => $this->transactionServiceMock,
'httpClientFactory' => $httpClientFactoryMock
'httpClientFactory' => $httpClientFactoryMock,
'paymentFailures' => $this->paymentFailures,
]
);
}
Expand Down Expand Up @@ -313,12 +329,16 @@ public function checkResponseCodeSuccessDataProvider()
}

/**
* @param bool $responseCode
* Checks response failures behaviour.
*
* @param int $responseCode
* @param int $failuresHandlerCalls
* @return void
*
* @expectedException \Magento\Framework\Exception\LocalizedException
* @dataProvider checkResponseCodeFailureDataProvider
*/
public function testCheckResponseCodeFailure($responseCode)
public function testCheckResponseCodeFailure(int $responseCode, int $failuresHandlerCalls): void
{
$reasonText = 'reason text';

Expand All @@ -333,18 +353,35 @@ public function testCheckResponseCodeFailure($responseCode)
->with($reasonText)
->willReturn(__('Gateway error: %1', $reasonText));

$orderMock = $this->getMockBuilder(Order::class)
->disableOriginalConstructor()
->getMock();

$orderMock->expects($this->exactly($failuresHandlerCalls))
->method('getQuoteId')
->willReturn(1);

$this->paymentFailures->expects($this->exactly($failuresHandlerCalls))
->method('handle')
->with(1);

$reflection = new \ReflectionClass($this->directpost);
$order = $reflection->getProperty('order');
$order->setAccessible(true);
$order->setValue($this->directpost, $orderMock);

$this->directpost->checkResponseCode();
}

/**
* @return array
*/
public function checkResponseCodeFailureDataProvider()
public function checkResponseCodeFailureDataProvider(): array
{
return [
['responseCode' => Directpost::RESPONSE_CODE_DECLINED],
['responseCode' => Directpost::RESPONSE_CODE_ERROR],
['responseCode' => 999999]
['responseCode' => Directpost::RESPONSE_CODE_DECLINED, 1],
['responseCode' => Directpost::RESPONSE_CODE_ERROR, 1],
['responseCode' => 999999, 0],
];
}

Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/Backend/App/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
$this->_view->loadLayout(['default', 'adminhtml_denied'], true, true, false);
$this->_view->renderLayout();
$this->_request->setDispatched(true);

return $this->_response;
}

Expand All @@ -226,6 +227,11 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)

$this->_processLocaleSettings();

// Need to preload isFirstPageAfterLogin (see https://github.com/magento/magento2/issues/15510)
if ($this->_auth->isLoggedIn()) {
$this->_auth->getAuthStorage()->isFirstPageAfterLogin();
}

return parent::dispatch($request);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Dashboard extends \Magento\Backend\Block\Template
/**
* @var string
*/
protected $_template = 'dashboard/index.phtml';
protected $_template = 'Magento_Backend::dashboard/index.phtml';

/**
* @return void
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Dashboard/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
/**
* @var string
*/
protected $_template = 'dashboard/graph.phtml';
protected $_template = 'Magento_Backend::dashboard/graph.phtml';

/**
* Adminhtml dashboard data
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Dashboard/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Grid extends \Magento\Backend\Block\Widget\Grid\Extended
/**
* @var string
*/
protected $_template = 'dashboard/grid.phtml';
protected $_template = 'Magento_Backend::dashboard/grid.phtml';

/**
* Setting default for every grid on dashboard
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Dashboard/Sales.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Sales extends \Magento\Backend\Block\Dashboard\Bar
/**
* @var string
*/
protected $_template = 'dashboard/salebar.phtml';
protected $_template = 'Magento_Backend::dashboard/salebar.phtml';

/**
* @var \Magento\Framework\Module\Manager
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Dashboard/Totals.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Totals extends \Magento\Backend\Block\Dashboard\Bar
/**
* @var string
*/
protected $_template = 'dashboard/totalbar.phtml';
protected $_template = 'Magento_Backend::dashboard/totalbar.phtml';

/**
* @var \Magento\Framework\Module\Manager
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Backend/Block/GlobalSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function getWidgetInitOptions()
'filterProperty' => 'name',
'preventClickPropagation' => false,
'minLength' => 2,
'submitInputOnEnter' => false,
]
];
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Page/Copyright.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class Copyright extends \Magento\Backend\Block\Template
*
* @var string
*/
protected $_template = 'page/copyright.phtml';
protected $_template = 'Magento_Backend::page/copyright.phtml';
}
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Page/Footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Footer extends \Magento\Backend\Block\Template
/**
* @var string
*/
protected $_template = 'page/footer.phtml';
protected $_template = 'Magento_Backend::page/footer.phtml';

/**
* @var \Magento\Framework\App\ProductMetadataInterface
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Page/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Header extends \Magento\Backend\Block\Template
/**
* @var string
*/
protected $_template = 'page/header.phtml';
protected $_template = 'Magento_Backend::page/header.phtml';

/**
* Backend data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Fieldset extends \Magento\Backend\Block\Template implements RendererInterf
/**
* @var string
*/
protected $_template = 'store/switcher/form/renderer/fieldset.phtml';
protected $_template = 'Magento_Backend::store/switcher/form/renderer/fieldset.phtml';

/**
* Retrieve an element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Element extends \Magento\Backend\Block\Widget\Form\Renderer\Fieldset\Eleme
/**
* @var string
*/
protected $_template = 'store/switcher/form/renderer/fieldset/element.phtml';
protected $_template = 'Magento_Backend::store/switcher/form/renderer/fieldset/element.phtml';

/**
* Retrieve an element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ public function __construct(
$this->_storeManager = $storeManager;
$this->_currencyLocator = $currencyLocator;
$this->_localeCurrency = $localeCurrency;
$defaultBaseCurrencyCode = $this->_scopeConfig->getValue(
\Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
'default'
);
$defaultBaseCurrencyCode = $currencyLocator->getDefaultCurrency($this->_request);
$this->_defaultBaseCurrency = $currencyFactory->create()->load($defaultBaseCurrencyCode);
}

Expand Down
Loading

0 comments on commit 040e396

Please sign in to comment.