Skip to content

Commit 1bcf22b

Browse files
authored
Merge pull request #3982 from magento-borg/borg-qwerty-2.3
[borg] Bugfixes
2 parents 98cf302 + eb3bba5 commit 1bcf22b

File tree

10 files changed

+205
-43
lines changed

10 files changed

+205
-43
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/form.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $_product->getId() ?>" />
2323
<input type="hidden" name="selected_configurable_option" value="" />
2424
<input type="hidden" name="related_product" id="related-products-field" value="" />
25-
<input type="hidden" name="item" value="<?= /* @noEscape */ $block->getRequest()->getParam('id') ?>" />
25+
<input type="hidden" name="item" value="<?= $block->escapeHtmlAttr($block->getRequest()->getParam('id')) ?>" />
2626
<?= $block->getBlockHtml('formkey') ?>
2727
<?= $block->getChildHtml('form_top') ?>
2828
<?php if (!$block->hasOptions()):?>

app/code/Magento/Checkout/Model/Session.php

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
namespace Magento\Checkout\Model;
77

88
use Magento\Customer\Api\Data\CustomerInterface;
9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Quote\Model\Quote;
1011
use Magento\Quote\Model\QuoteIdMaskFactory;
12+
use Psr\Log\LoggerInterface;
1113

1214
/**
15+
* Represents the session data for the checkout process
16+
*
1317
* @api
1418
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1520
*/
1621
class Session extends \Magento\Framework\Session\SessionManager
1722
{
@@ -98,6 +103,11 @@ class Session extends \Magento\Framework\Session\SessionManager
98103
*/
99104
protected $quoteFactory;
100105

106+
/**
107+
* @var LoggerInterface|null
108+
*/
109+
private $logger;
110+
101111
/**
102112
* @param \Magento\Framework\App\Request\Http $request
103113
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
@@ -117,6 +127,8 @@ class Session extends \Magento\Framework\Session\SessionManager
117127
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository
118128
* @param QuoteIdMaskFactory $quoteIdMaskFactory
119129
* @param \Magento\Quote\Model\QuoteFactory $quoteFactory
130+
* @param LoggerInterface|null $logger
131+
* @throws \Magento\Framework\Exception\SessionException
120132
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
121133
*/
122134
public function __construct(
@@ -137,7 +149,8 @@ public function __construct(
137149
\Magento\Store\Model\StoreManagerInterface $storeManager,
138150
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
139151
QuoteIdMaskFactory $quoteIdMaskFactory,
140-
\Magento\Quote\Model\QuoteFactory $quoteFactory
152+
\Magento\Quote\Model\QuoteFactory $quoteFactory,
153+
LoggerInterface $logger = null
141154
) {
142155
$this->_orderFactory = $orderFactory;
143156
$this->_customerSession = $customerSession;
@@ -159,6 +172,8 @@ public function __construct(
159172
$cookieMetadataFactory,
160173
$appState
161174
);
175+
$this->logger = $logger ?: ObjectManager::getInstance()
176+
->get(LoggerInterface::class);
162177
}
163178

164179
/**
@@ -202,6 +217,8 @@ public function setLoadInactive($load = true)
202217
* Get checkout quote instance by current session
203218
*
204219
* @return Quote
220+
* @throws \Magento\Framework\Exception\LocalizedException
221+
* @throws \Magento\Framework\Exception\NoSuchEntityException
205222
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
206223
* @SuppressWarnings(PHPMD.NPathComplexity)
207224
*/
@@ -219,6 +236,15 @@ public function getQuote()
219236
$quote = $this->quoteRepository->getActive($this->getQuoteId());
220237
}
221238

239+
$customerId = $this->_customer
240+
? $this->_customer->getId()
241+
: $this->_customerSession->getCustomerId();
242+
243+
if ($quote->getData('customer_id') && (int)$quote->getData('customer_id') !== (int)$customerId) {
244+
$quote = $this->quoteFactory->create();
245+
$this->setQuoteId(null);
246+
}
247+
222248
/**
223249
* If current currency code of quote is not equal current currency code of store,
224250
* need recalculate totals of quote. It is possible if customer use currency switcher or
@@ -247,6 +273,7 @@ public function getQuote()
247273
$quote = $this->quoteRepository->getActiveForCustomer($customerId);
248274
$this->setQuoteId($quote->getId());
249275
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
276+
$this->logger->critical($e);
250277
}
251278
} else {
252279
$quote->setIsCheckoutCart(true);
@@ -285,6 +312,8 @@ public function getQuote()
285312
}
286313

287314
/**
315+
* Return the quote's key
316+
*
288317
* @return string
289318
* @codeCoverageIgnore
290319
*/
@@ -294,6 +323,8 @@ protected function _getQuoteIdKey()
294323
}
295324

296325
/**
326+
* Set the current session's quote id
327+
*
297328
* @param int $quoteId
298329
* @return void
299330
* @codeCoverageIgnore
@@ -304,6 +335,8 @@ public function setQuoteId($quoteId)
304335
}
305336

306337
/**
338+
* Return the current quote's ID
339+
*
307340
* @return int
308341
* @codeCoverageIgnore
309342
*/
@@ -357,6 +390,8 @@ public function loadCustomerQuote()
357390
}
358391

359392
/**
393+
* Associate data to a specified step of the checkout process
394+
*
360395
* @param string $step
361396
* @param array|string $data
362397
* @param bool|string|null $value
@@ -383,6 +418,8 @@ public function setStepData($step, $data, $value = null)
383418
}
384419

385420
/**
421+
* Return the data associated to a specified step
422+
*
386423
* @param string|null $step
387424
* @param string|null $data
388425
* @return array|string|bool
@@ -406,8 +443,7 @@ public function getStepData($step = null, $data = null)
406443
}
407444

408445
/**
409-
* Destroy/end a session
410-
* Unset all data associated with object
446+
* Destroy/end a session and unset all data associated with it
411447
*
412448
* @return $this
413449
*/
@@ -443,6 +479,8 @@ public function clearHelperData()
443479
}
444480

445481
/**
482+
* Revert the state of the checkout to the beginning
483+
*
446484
* @return $this
447485
* @codeCoverageIgnore
448486
*/
@@ -453,6 +491,8 @@ public function resetCheckout()
453491
}
454492

455493
/**
494+
* Replace the quote in the session with a specified object
495+
*
456496
* @param Quote $quote
457497
* @return $this
458498
*/
@@ -499,13 +539,17 @@ public function restoreQuote()
499539
$this->_eventManager->dispatch('restore_quote', ['order' => $order, 'quote' => $quote]);
500540
return true;
501541
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
542+
$this->logger->critical($e);
502543
}
503544
}
545+
504546
return false;
505547
}
506548

507549
/**
508-
* @param $isQuoteMasked bool
550+
* Flag whether or not the quote uses a masked quote id
551+
*
552+
* @param bool $isQuoteMasked
509553
* @return void
510554
* @codeCoverageIgnore
511555
*/
@@ -515,6 +559,8 @@ protected function setIsQuoteMasked($isQuoteMasked)
515559
}
516560

517561
/**
562+
* Return if the quote has a masked quote id
563+
*
518564
* @return bool|null
519565
* @codeCoverageIgnore
520566
*/

app/code/Magento/CurrencySymbol/view/adminhtml/templates/grid.phtml

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,44 @@
55
*/
66

77
// @codingStandardsIgnoreFile
8-
98
?>
109
<?php
1110
/**
1211
* @var $block \Magento\CurrencySymbol\Block\Adminhtml\System\Currencysymbol
1312
*/
1413
?>
15-
16-
<form id="currency-symbols-form" action="<?= /* @escapeNotVerified */ $block->getFormActionUrl() ?>" method="post">
17-
<input name="form_key" type="hidden" value="<?= /* @escapeNotVerified */ $block->getFormKey() ?>" />
14+
<form id="currency-symbols-form" action="<?= $block->escapeHtmlAttr($block->getFormActionUrl()) ?>" method="post">
15+
<input name="form_key" type="hidden" value="<?= $block->escapeHtmlAttr($block->getFormKey()) ?>" />
1816
<fieldset class="admin__fieldset">
1917
<?php foreach ($block->getCurrencySymbolsData() as $code => $data): ?>
2018
<div class="admin__field _required">
21-
<label class="admin__field-label" for="custom_currency_symbol<?= /* @escapeNotVerified */ $code ?>">
22-
<span><?= /* @escapeNotVerified */ $code ?> (<?= /* @escapeNotVerified */ $data['displayName'] ?>)</span>
19+
<label class="admin__field-label" for="custom_currency_symbol<?= $block->escapeHtmlAttr($code) ?>">
20+
<span><?= $block->escapeHtml($code) ?> (<?= $block->escapeHtml($data['displayName']) ?>)</span>
2321
</label>
2422
<div class="admin__field-control">
25-
<input id="custom_currency_symbol<?= /* @escapeNotVerified */ $code ?>"
23+
<input id="custom_currency_symbol<?= $block->escapeHtmlAttr($code) ?>"
2624
class="required-entry admin__control-text <?= $data['inherited'] ? 'disabled' : '' ?>"
2725
type="text"
2826
value="<?= $block->escapeHtmlAttr($data['displaySymbol']) ?>"
29-
name="custom_currency_symbol[<?= /* @escapeNotVerified */ $code ?>]">
27+
name="custom_currency_symbol[<?= $block->escapeHtmlAttr($code) ?>]">
3028
<div class="admin__field admin__field-option">
31-
<input id="custom_currency_symbol_inherit<?= /* @escapeNotVerified */ $code ?>"
29+
<input id="custom_currency_symbol_inherit<?= $block->escapeHtmlAttr($code) ?>"
3230
class="admin__control-checkbox" type="checkbox"
33-
onclick="toggleUseDefault(<?= /* @escapeNotVerified */ '\'' . $code . '\',\'' . $block->escapeJs($data['parentSymbol']) . '\'' ?>)"
31+
onclick="toggleUseDefault(<?= '\'' . $block->escapeHtmlAttr($block->escapeJs($code)) . '\',\'' . $block->escapeJs($data['parentSymbol']) . '\'' ?>)"
3432
<?= $data['inherited'] ? ' checked="checked"' : '' ?>
3533
value="1"
36-
name="inherit_custom_currency_symbol[<?= /* @escapeNotVerified */ $code ?>]">
37-
<label class="admin__field-label" for="custom_currency_symbol_inherit<?= /* @escapeNotVerified */ $code ?>"><span><?= /* @escapeNotVerified */ $block->getInheritText() ?></span></label>
34+
name="inherit_custom_currency_symbol[<?= $block->escapeHtmlAttr($code) ?>]">
35+
<label class="admin__field-label" for="custom_currency_symbol_inherit<?= $block->escapeHtmlAttr($code) ?>"><span><?= $block->escapeHtml($block->getInheritText()) ?></span></label>
3836
</div>
3937
</div>
4038
</div>
4139
<?php endforeach; ?>
4240
</fieldset>
4341
</form>
44-
<script>
45-
require(['jquery', "mage/mage", 'prototype'], function(jQuery){
46-
47-
jQuery('#currency-symbols-form').mage('form').mage('validation');
48-
49-
function toggleUseDefault(code, value)
42+
<script type="text/x-magento-init">
5043
{
51-
checkbox = jQuery('#custom_currency_symbol_inherit'+code);
52-
input = jQuery('#custom_currency_symbol'+code);
53-
54-
if (checkbox.is(':checked')) {
55-
input.addClass('disabled');
56-
input.val(value);
57-
input.prop('readonly', true);
58-
} else {
59-
input.removeClass('disabled');
60-
input.prop('readonly', false);
44+
"#currency-symbols-form": {
45+
"Magento_CurrencySymbol/js/symbols-form": {}
6146
}
6247
}
63-
window.toggleUseDefault = toggleUseDefault;
64-
});
6548
</script>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'mage/mage'
9+
], function ($) {
10+
'use strict';
11+
12+
return function (config, element) {
13+
$(element)
14+
.mage('form')
15+
.mage('validation');
16+
17+
/**
18+
* Toggle the field to use the default value
19+
*
20+
* @param {String} code
21+
* @param {String} value
22+
*/
23+
function toggleUseDefault(code, value) {
24+
var checkbox = $('#custom_currency_symbol_inherit' + code),
25+
input = $('#custom_currency_symbol' + code);
26+
27+
if (checkbox.is(':checked')) {
28+
input.addClass('disabled');
29+
input.val(value);
30+
input.prop('readonly', true);
31+
} else {
32+
input.removeClass('disabled');
33+
input.prop('readonly', false);
34+
}
35+
}
36+
37+
window.toggleUseDefault = toggleUseDefault;
38+
};
39+
});

app/code/Magento/Dhl/Model/Carrier.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ protected function _getWeight($weight, $maxWeight = false, $configWeightUnit = f
715715
* @return array
716716
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
717717
* @SuppressWarnings(PHPMD.NPathComplexity)
718+
* phpcs:disable Generic.Metrics.NestingLevel.TooHigh
718719
*/
719720
protected function _getAllItems()
720721
{
@@ -985,7 +986,7 @@ protected function _getQuotes()
985986
protected function _getQuotesFromServer($request)
986987
{
987988
$client = $this->_httpClientFactory->create();
988-
$client->setUri((string)$this->getConfigData('gateway_url'));
989+
$client->setUri($this->getGatewayURL());
989990
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
990991
$client->setRawData(utf8_encode($request));
991992

@@ -1307,7 +1308,7 @@ public function proccessAdditionalValidation(\Magento\Framework\DataObject $requ
13071308
public function processAdditionalValidation(\Magento\Framework\DataObject $request)
13081309
{
13091310
//Skip by item validation if there is no items in request
1310-
if (!count($this->getAllItems($request))) {
1311+
if (empty($this->getAllItems($request))) {
13111312
$this->_errors[] = __('There is no items in this order');
13121313
}
13131314

@@ -1578,7 +1579,7 @@ protected function _doRequest()
15781579
try {
15791580
/** @var \Magento\Framework\HTTP\ZendClient $client */
15801581
$client = $this->_httpClientFactory->create();
1581-
$client->setUri((string)$this->getConfigData('gateway_url'));
1582+
$client->setUri($this->getGatewayURL());
15821583
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
15831584
$client->setRawData($request);
15841585
$responseBody = $client->request(\Magento\Framework\HTTP\ZendClient::POST)->getBody();
@@ -1745,7 +1746,7 @@ protected function _getXMLTracking($trackings)
17451746
try {
17461747
/** @var \Magento\Framework\HTTP\ZendClient $client */
17471748
$client = $this->_httpClientFactory->create();
1748-
$client->setUri((string)$this->getConfigData('gateway_url'));
1749+
$client->setUri($this->getGatewayURL());
17491750
$client->setConfig(['maxredirects' => 0, 'timeout' => 30]);
17501751
$client->setRawData($request);
17511752
$responseBody = $client->request(\Magento\Framework\HTTP\ZendClient::POST)->getBody();
@@ -1775,7 +1776,7 @@ protected function _parseXmlTrackingResponse($trackings, $response)
17751776
$errorTitle = __('Unable to retrieve tracking');
17761777
$resultArr = [];
17771778

1778-
if (strlen(trim($response)) > 0) {
1779+
if (!empty(trim($response))) {
17791780
$xml = $this->parseXml($response, \Magento\Shipping\Model\Simplexml\Element::class);
17801781
if (!is_object($xml)) {
17811782
$errorTitle = __('Response is in the wrong format');
@@ -1944,6 +1945,7 @@ protected function _prepareShippingLabelContent(\SimpleXMLElement $xml)
19441945
}
19451946
$result->setTrackingNumber((string)$xml->AirwayBillNumber);
19461947
$labelContent = (string)$xml->LabelImage->OutputImage;
1948+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
19471949
$result->setShippingLabelContent(base64_decode($labelContent));
19481950
} catch (\Exception $e) {
19491951
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()));
@@ -2021,4 +2023,18 @@ private function buildSoftwareVersion(): string
20212023
{
20222024
return substr($this->productMetadata->getVersion(), 0, 10);
20232025
}
2026+
2027+
/**
2028+
* Get the gateway URL
2029+
*
2030+
* @return string
2031+
*/
2032+
private function getGatewayURL(): string
2033+
{
2034+
if ($this->getConfigData('sandbox_mode')) {
2035+
return (string)$this->getConfigData('sandbox_url');
2036+
} else {
2037+
return (string)$this->getConfigData('gateway_url');
2038+
}
2039+
}
20242040
}

0 commit comments

Comments
 (0)