diff --git a/app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/PageActionsTest.php b/app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/PageActionsTest.php index 21c1d2ec4994e..fdc87499f58ae 100644 --- a/app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/PageActionsTest.php +++ b/app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/PageActionsTest.php @@ -50,8 +50,8 @@ public function testPrepareItemsByPageId() 'href' => 'test/url/delete', 'label' => __('Delete'), 'confirm' => [ - 'title' => __('Delete "${ $.$data.title }"'), - 'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?') + 'title' => __('Delete ${ $.$data.title }'), + 'message' => __('Are you sure you wan\'t to delete a ${ $.$data.title } record?') ], ] ], diff --git a/app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php b/app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php index b5b914db4cf5b..08379991a92b5 100644 --- a/app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php +++ b/app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php @@ -75,8 +75,8 @@ public function prepareDataSource(array & $dataSource) 'href' => $this->urlBuilder->getUrl(self::CMS_URL_PATH_DELETE, ['page_id' => $item['page_id']]), 'label' => __('Delete'), 'confirm' => [ - 'title' => __('Delete "${ $.$data.title }"'), - 'message' => __('Are you sure you wan\'t to delete a "${ $.$data.title }" record?') + 'title' => __('Delete ${ $.$data.title }'), + 'message' => __('Are you sure you wan\'t to delete a ${ $.$data.title } record?') ] ]; } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php b/app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php index c05b79c32ce78..126f6e04bdd13 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php @@ -79,10 +79,12 @@ protected function _construct() ['label' => __('Back'), 'onclick' => "setLocation('{$backUrl}')", 'class' => 'back'] ); - if ($this->_authorization->isAllowed( - 'Magento_Sales::transactions_fetch' - ) && $this->orderPaymentRepository->get($this->_txn->getId())->getMethodInstance()->canFetchTransactionInfo() - ) { + $fetchTransactionAllowed = $this->_authorization->isAllowed('Magento_Sales::transactions_fetch'); + $canFetchTransaction = $this->orderPaymentRepository->get($this->_txn->getPaymentId()) + ->getMethodInstance() + ->canFetchTransactionInfo(); + + if ($fetchTransactionAllowed && $canFetchTransaction) { $fetchUrl = $this->getUrl('sales/*/fetch', ['_current' => true]); $this->buttonList->add( 'fetch', diff --git a/app/code/Magento/Sales/Model/Order/Payment.php b/app/code/Magento/Sales/Model/Order/Payment.php index 3811b28fa58fd..a99674102d75c 100644 --- a/app/code/Magento/Sales/Model/Order/Payment.php +++ b/app/code/Magento/Sales/Model/Order/Payment.php @@ -9,6 +9,7 @@ namespace Magento\Sales\Model\Order; use Magento\Framework\Pricing\PriceCurrencyInterface; +use Magento\Sales\Api\OrderRepositoryInterface; use Magento\Sales\Model\Order\Payment\Info; use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Model\Order; @@ -97,6 +98,11 @@ class Payment extends Info implements OrderPaymentInterface */ protected $orderPaymentProcessor; + /** + * @var OrderRepositoryInterface + */ + protected $orderRepository; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -109,6 +115,8 @@ class Payment extends Info implements OrderPaymentInterface * @param \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository * @param \Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface $transactionManager * @param Transaction\BuilderInterface $transactionBuilder + * @param Payment\Processor $paymentProcessor + * @param OrderRepositoryInterface $orderRepository * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param array $data @@ -127,6 +135,7 @@ public function __construct( ManagerInterface $transactionManager, \Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface $transactionBuilder, \Magento\Sales\Model\Order\Payment\Processor $paymentProcessor, + OrderRepositoryInterface $orderRepository, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [] @@ -137,6 +146,7 @@ public function __construct( $this->transactionManager = $transactionManager; $this->transactionBuilder = $transactionBuilder; $this->orderPaymentProcessor = $paymentProcessor; + $this->orderRepository = $orderRepository; parent::__construct( $context, $registry, @@ -178,11 +188,16 @@ public function setOrder(Order $order) * Retrieve order model object * * @codeCoverageIgnore + * @deprecated * * @return Order */ public function getOrder() { + if (!$this->_order && $this->getParentId()) { + $this->_order = $this->orderRepository->get($this->getParentId()); + } + return $this->_order; } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php index bae07f65c98ee..2a0b28329abf4 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php @@ -17,6 +17,7 @@ */ class PaymentTest extends \PHPUnit_Framework_TestCase { + private $mockContext; /** * @var Payment */ @@ -91,9 +92,13 @@ class PaymentTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Sales\Model\Order\Payment\Processor|\PHPUnit_Framework_MockObject_MockObject */ - protected $paymentProcessor; + /** + * @var \Magento\Sales\Model\OrderRepository|\PHPUnit_Framework_MockObject_MockObject + */ + protected $orderRepository; + /** * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) @@ -105,11 +110,11 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $context = $this->getMockBuilder('Magento\Framework\Model\Context') + $this->mockContext = $this->getMockBuilder('Magento\Framework\Model\Context') ->disableOriginalConstructor() ->getMock(); - $context->expects($this->once()) + $this->mockContext->expects($this->atLeastOnce()) ->method('getEventDispatcher') ->will($this->returnValue($this->eventManagerMock)); @@ -132,6 +137,7 @@ protected function setUp() ->setMethods(['get', 'getByTransactionType', 'getByTransactionId']) ->getMock(); $this->paymentProcessor = $this->getMock('Magento\Sales\Model\Order\Payment\Processor', [], [], '', false); + $this->orderRepository = $this->getMock('Magento\Sales\Model\OrderRepository', ['get'], [], '', false); $this->priceCurrencyMock->expects($this->any()) ->method('format') @@ -259,7 +265,10 @@ function ($value) { false ); - $this->initPayment($context); + $this->payment = $this->initPayment(); + $this->payment->setMethod('any'); + $this->payment->setOrder($this->orderMock); + $this->transactionId = 100; } protected function tearDown() @@ -1212,6 +1221,26 @@ public function testPay() $this->assertEquals($expects['base_shipping_captured'], $this->payment->getData('base_shipping_captured')); } + public function testGetOrder() + { + $payment = $this->initPayment(); + $this->orderRepository->expects($this->once())->method('get')->willReturn($this->orderMock); + $payment->setParentId(1211); + $this->assertSame($this->orderMock, $payment->getOrder()); + } + + public function testGetOrderDefault() + { + $this->orderRepository->expects($this->never())->method('get'); + $this->assertSame($this->orderMock, $this->payment->getOrder()); + } + + public function testGetOrderNull() + { + $payment = $this->initPayment(); + $this->orderRepository->expects($this->never())->method('get'); + $this->assertNull($payment->getOrder()); + } public function testCancelInvoice() { @@ -1408,29 +1437,22 @@ public function boolProvider() ]; } - /** - * @param $context - */ - protected function initPayment($context) + protected function initPayment() { - $this->payment = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject( + return (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject( 'Magento\Sales\Model\Order\Payment', [ - 'context' => $context, + 'context' => $this->mockContext, 'creditmemoFactory' => $this->creditmemoFactoryMock, 'paymentData' => $this->helperMock, 'priceCurrency' => $this->priceCurrencyMock, 'transactionRepository' => $this->transactionRepositoryMock, 'transactionManager' => $this->transactionManagerMock, 'transactionBuilder' => $this->transactionBuilderMock, - 'paymentProcessor' => $this->paymentProcessor + 'paymentProcessor' => $this->paymentProcessor, + 'orderRepository' => $this->orderRepository ] ); - - $this->payment->setMethod('any'); - $this->payment->setOrder($this->orderMock); - - $this->transactionId = 100; } protected function assertOrderUpdated( diff --git a/app/code/Magento/Sales/view/frontend/templates/order/comments.phtml b/app/code/Magento/Sales/view/frontend/templates/order/comments.phtml index 4027cb5b2337a..671a90b078929 100644 --- a/app/code/Magento/Sales/view/frontend/templates/order/comments.phtml +++ b/app/code/Magento/Sales/view/frontend/templates/order/comments.phtml @@ -18,7 +18,7 @@