Skip to content

Commit 774f7c3

Browse files
committed
Merge pull request #353 from magento-mpi/develop
[MPI] Bug Fixes
2 parents cb66950 + 591e7a7 commit 774f7c3

File tree

17 files changed

+570
-29
lines changed

17 files changed

+570
-29
lines changed

app/code/Magento/Sales/Block/Adminhtml/Order/Comments/View.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,26 @@ class View extends \Magento\Backend\Block\Template
1919
*/
2020
protected $_salesData = null;
2121

22+
/**
23+
* @var \Magento\Sales\Helper\Admin
24+
*/
25+
private $adminHelper;
26+
2227
/**
2328
* @param \Magento\Backend\Block\Template\Context $context
2429
* @param \Magento\Sales\Helper\Data $salesData
30+
* @param \Magento\Sales\Helper\Admin $adminHelper
2531
* @param array $data
2632
*/
2733
public function __construct(
2834
\Magento\Backend\Block\Template\Context $context,
2935
\Magento\Sales\Helper\Data $salesData,
36+
\Magento\Sales\Helper\Admin $adminHelper,
3037
array $data = []
3138
) {
3239
$this->_salesData = $salesData;
3340
parent::__construct($context, $data);
41+
$this->adminHelper = $adminHelper;
3442
}
3543

3644
/**
@@ -96,4 +104,16 @@ public function canSendCommentEmail()
96104
}
97105
return true;
98106
}
107+
108+
/**
109+
* Replace links in string
110+
*
111+
* @param array|string $data
112+
* @param null|array $allowedTags
113+
* @return string
114+
*/
115+
public function escapeHtml($data, $allowedTags = null)
116+
{
117+
return $this->adminHelper->escapeHtmlWithLinks($data, $allowedTags);
118+
}
99119
}

app/code/Magento/Sales/Block/Adminhtml/Order/View/History.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,29 @@ class History extends \Magento\Backend\Block\Template
2626
*/
2727
protected $_salesData = null;
2828

29+
/**
30+
* @var \Magento\Sales\Helper\Admin
31+
*/
32+
private $adminHelper;
33+
2934
/**
3035
* @param \Magento\Backend\Block\Template\Context $context
3136
* @param \Magento\Sales\Helper\Data $salesData
3237
* @param \Magento\Framework\Registry $registry
38+
* @param \Magento\Sales\Helper\Admin $adminHelper
3339
* @param array $data
3440
*/
3541
public function __construct(
3642
\Magento\Backend\Block\Template\Context $context,
3743
\Magento\Sales\Helper\Data $salesData,
3844
\Magento\Framework\Registry $registry,
45+
\Magento\Sales\Helper\Admin $adminHelper,
3946
array $data = []
4047
) {
4148
$this->_coreRegistry = $registry;
4249
$this->_salesData = $salesData;
4350
parent::__construct($context, $data);
51+
$this->adminHelper = $adminHelper;
4452
}
4553

4654
/**
@@ -122,4 +130,16 @@ public function isCustomerNotificationNotApplicable(\Magento\Sales\Model\Order\S
122130
{
123131
return $history->isCustomerNotificationNotApplicable();
124132
}
133+
134+
/**
135+
* Replace links in string
136+
*
137+
* @param array|string $data
138+
* @param null|array $allowedTags
139+
* @return string
140+
*/
141+
public function escapeHtml($data, $allowedTags = null)
142+
{
143+
return $this->adminHelper->escapeHtmlWithLinks($data, $allowedTags);
144+
}
125145
}

app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,26 @@ class History extends \Magento\Backend\Block\Template implements \Magento\Backen
2626
*/
2727
protected $_coreRegistry = null;
2828

29+
/**
30+
* @var \Magento\Sales\Helper\Admin
31+
*/
32+
private $adminHelper;
33+
2934
/**
3035
* @param \Magento\Backend\Block\Template\Context $context
3136
* @param \Magento\Framework\Registry $registry
37+
* @param \Magento\Sales\Helper\Admin $adminHelper
3238
* @param array $data
3339
*/
3440
public function __construct(
3541
\Magento\Backend\Block\Template\Context $context,
3642
\Magento\Framework\Registry $registry,
43+
\Magento\Sales\Helper\Admin $adminHelper,
3744
array $data = []
3845
) {
3946
$this->_coreRegistry = $registry;
4047
parent::__construct($context, $data);
48+
$this->adminHelper = $adminHelper;
4149
}
4250

4351
/**
@@ -192,8 +200,9 @@ public function isItemNotified(array $item, $isSimpleCheck = true)
192200
*/
193201
public function getItemComment(array $item)
194202
{
195-
$allowedTags = ['b', 'br', 'strong', 'i', 'u'];
196-
return isset($item['comment']) ? $this->escapeHtml($item['comment'], $allowedTags) : '';
203+
$allowedTags = ['b', 'br', 'strong', 'i', 'u', 'a'];
204+
return isset($item['comment'])
205+
? $this->adminHelper->escapeHtmlWithLinks($item['comment'], $allowedTags) : '';
197206
}
198207

199208
/**

app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,25 @@ class Detail extends \Magento\Backend\Block\Widget\Container
2626
*/
2727
protected $_coreRegistry = null;
2828

29+
/**
30+
* @var \Magento\Sales\Helper\Admin
31+
*/
32+
private $adminHelper;
33+
2934
/**
3035
* @param \Magento\Backend\Block\Widget\Context $context
3136
* @param \Magento\Framework\Registry $registry
37+
* @param \Magento\Sales\Helper\Admin $adminHelper
3238
* @param array $data
3339
*/
3440
public function __construct(
3541
\Magento\Backend\Block\Widget\Context $context,
3642
\Magento\Framework\Registry $registry,
43+
\Magento\Sales\Helper\Admin $adminHelper,
3744
array $data = []
3845
) {
3946
$this->_coreRegistry = $registry;
47+
$this->adminHelper = $adminHelper;
4048
parent::__construct($context, $data);
4149
}
4250

@@ -97,7 +105,10 @@ public function getHeaderText()
97105
*/
98106
protected function _toHtml()
99107
{
100-
$this->setTxnIdHtml($this->escapeHtml($this->_txn->getTxnId()));
108+
$this->setTxnIdHtml($this->adminHelper->escapeHtmlWithLinks(
109+
$this->_txn->getHtmlTxnId(),
110+
['a']
111+
));
101112

102113
$this->setParentTxnIdUrlHtml(
103114
$this->escapeHtml($this->getUrl('sales/transactions/view', ['txn_id' => $this->_txn->getParentId()]))

app/code/Magento/Sales/Helper/Admin.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,29 @@ class Admin extends \Magento\Framework\App\Helper\AbstractHelper
2222
*/
2323
protected $priceCurrency;
2424

25+
/**
26+
* @var \Magento\Framework\Escaper
27+
*/
28+
protected $escaper;
29+
2530
/**
2631
* @param \Magento\Framework\App\Helper\Context $context
2732
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
2833
* @param \Magento\Sales\Model\Config $salesConfig
2934
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
35+
* @param \Magento\Framework\Escaper $escaper
3036
*/
3137
public function __construct(
3238
\Magento\Framework\App\Helper\Context $context,
3339
\Magento\Store\Model\StoreManagerInterface $storeManager,
3440
\Magento\Sales\Model\Config $salesConfig,
35-
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
41+
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
42+
\Magento\Framework\Escaper $escaper
3643
) {
3744
$this->priceCurrency = $priceCurrency;
3845
$this->_storeManager = $storeManager;
3946
$this->_salesConfig = $salesConfig;
47+
$this->escaper = $escaper;
4048
parent::__construct($context);
4149
}
4250

@@ -127,4 +135,29 @@ public function applySalableProductTypesFilter($collection)
127135
}
128136
return $collection;
129137
}
138+
139+
/**
140+
* Escape string preserving links
141+
*
142+
* @param string $data
143+
* @param null|array $allowedTags
144+
* @return string
145+
*/
146+
public function escapeHtmlWithLinks($data, $allowedTags = null)
147+
{
148+
if (!empty($data) && is_array($allowedTags) && in_array('a', $allowedTags)) {
149+
$links = [];
150+
$i = 1;
151+
$data = str_replace('%', '%%', $data);
152+
$regexp = '@(<a[^>]*>(?:[^<]|<[^/]|</[^a]|</a[^>])*</a>)@';
153+
while (preg_match($regexp, $data, $matches)) {
154+
$links[] = $matches[1];
155+
$data = str_replace($matches[1], '%' . $i . '$s', $data);
156+
++$i;
157+
}
158+
$data = $this->escaper->escapeHtml($data, $allowedTags);
159+
return vsprintf($data, $links);
160+
}
161+
return $this->escaper->escapeHtml($data, $allowedTags);
162+
}
130163
}

app/code/Magento/Sales/Model/Order/Payment.php

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -948,28 +948,31 @@ public function accept()
948948
/**
949949
* Accept order with payment method instance
950950
*
951+
* @param bool $isOnline
951952
* @return $this
953+
* @throws \Magento\Framework\Exception\LocalizedException
952954
*/
953-
public function deny()
955+
public function deny($isOnline = true)
954956
{
955-
$transactionId = $this->getLastTransId();
957+
$transactionId = $isOnline ? $this->getLastTransId() : $this->getTransactionId();
956958

957-
/** @var \Magento\Payment\Model\Method\AbstractMethod $method */
958-
$method = $this->getMethodInstance();
959-
$method->setStore(
960-
$this->getOrder()->getStoreId()
961-
);
962-
if ($method->denyPayment($this)) {
959+
$result = $isOnline ?
960+
$this->getMethodInstance()->setStore($this->getOrder()->getStoreId())->denyPayment($this) :
961+
(bool)$this->getNotificationResult();
962+
963+
if ($result) {
963964
$invoice = $this->_getInvoiceForTransactionId($transactionId);
964965
$message = $this->_appendTransactionToMessage(
965966
$transactionId,
966967
$this->_prependMessage(__('Denied the payment online'))
967968
);
968969
$this->cancelInvoiceAndRegisterCancellation($invoice, $message);
969970
} else {
971+
$txt = $isOnline ?
972+
'There is no need to deny this payment.' : 'Registered notification about denied payment.';
970973
$message = $this->_appendTransactionToMessage(
971974
$transactionId,
972-
$this->_prependMessage(__('There is no need to deny this payment.'))
975+
$this->_prependMessage(__($txt))
973976
);
974977
$this->setOrderStatePaymentReview($message, $transactionId);
975978
}
@@ -979,17 +982,21 @@ public function deny()
979982
/**
980983
* Performs registered payment update.
981984
*
982-
* @throws \Magento\Framework\Exception\LocalizedException
985+
* @param bool $isOnline
983986
* @return $this
987+
* @throws \Magento\Framework\Exception\LocalizedException
984988
*/
985-
public function update()
989+
public function update($isOnline = true)
986990
{
987-
$transactionId = $this->getLastTransId();
991+
$transactionId = $isOnline ? $this->getLastTransId() : $this->getTransactionId();
988992
$invoice = $this->_getInvoiceForTransactionId($transactionId);
989993

990-
$method = $this->getMethodInstance();
991-
$method->setStore($this->getOrder()->getStoreId());
992-
$method->fetchTransactionInfo($this, $transactionId);
994+
995+
if ($isOnline) {
996+
$method = $this->getMethodInstance();
997+
$method->setStore($this->getOrder()->getStoreId());
998+
$method->fetchTransactionInfo($this, $transactionId);
999+
}
9931000

9941001
if ($this->getIsTransactionApproved()) {
9951002
$message = $this->_appendTransactionToMessage(
@@ -1443,7 +1450,7 @@ protected function _isTransactionExists($txnId = null)
14431450
protected function _appendTransactionToMessage($transaction, $message)
14441451
{
14451452
if ($transaction) {
1446-
$txnId = is_object($transaction) ? $transaction->getTxnId() : $transaction;
1453+
$txnId = is_object($transaction) ? $transaction->getHtmlTxnId() : $transaction;
14471454
$message .= ' ' . __('Transaction ID: "%1"', $txnId);
14481455
}
14491456
return $message;
@@ -1463,8 +1470,8 @@ protected function _prependMessage($messagePrependTo)
14631470
if (is_string($preparedMessage)) {
14641471
return $preparedMessage . ' ' . $messagePrependTo;
14651472
} elseif (is_object(
1466-
$preparedMessage
1467-
) && $preparedMessage instanceof \Magento\Sales\Model\Order\Status\History
1473+
$preparedMessage
1474+
) && $preparedMessage instanceof \Magento\Sales\Model\Order\Status\History
14681475
) {
14691476
$comment = $preparedMessage->getComment() . ' ' . $messagePrependTo;
14701477
$preparedMessage->setComment($comment);
@@ -1688,8 +1695,8 @@ protected function _getInvoiceForTransactionId($transactionId)
16881695
}
16891696
foreach ($this->getOrder()->getInvoiceCollection() as $invoice) {
16901697
if ($invoice->getState() == \Magento\Sales\Model\Order\Invoice::STATE_OPEN && $invoice->load(
1691-
$invoice->getId()
1692-
)
1698+
$invoice->getId()
1699+
)
16931700
) {
16941701
$invoice->setTransactionId($transactionId);
16951702
return $invoice;

app/code/Magento/Sales/Model/Order/Payment/Transaction.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,17 @@ public function getTxnId()
980980
return $this->getData(TransactionInterface::TXN_ID);
981981
}
982982

983+
/**
984+
* Get HTML format for transaction id
985+
*
986+
* @return string
987+
*/
988+
public function getHtmlTxnId()
989+
{
990+
$this->_eventManager->dispatch($this->_eventPrefix . '_html_txn_id', $this->_getEventData());
991+
return isset($this->_data['html_txn_id']) ? $this->_data['html_txn_id'] : $this->getTxnId();
992+
}
993+
983994
/**
984995
* Returns parent_txn_id
985996
*

0 commit comments

Comments
 (0)