Skip to content

Commit 409af85

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into MAGETWO-83706
2 parents cf4a8f9 + a50cda7 commit 409af85

File tree

14 files changed

+200
-43
lines changed

14 files changed

+200
-43
lines changed

app/code/Magento/Catalog/Model/Category.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ class Category extends \Magento\Catalog\Model\AbstractModel implements
112112
*/
113113
protected $_url;
114114

115+
/**
116+
* @var ResourceModel\Category
117+
*/
118+
protected $_resource;
119+
115120
/**
116121
* URL rewrite model
117122
*
@@ -332,6 +337,16 @@ protected function getCustomAttributesCodes()
332337
return $this->customAttributesCodes;
333338
}
334339

340+
/**
341+
* @throws \Magento\Framework\Exception\LocalizedException
342+
* @return \Magento\Catalog\Model\ResourceModel\Category
343+
* @deprecated because resource models should be used directly
344+
*/
345+
protected function _getResource()
346+
{
347+
return parent::_getResource();
348+
}
349+
335350
/**
336351
* Get flat resource model flag
337352
*

app/code/Magento/Catalog/Model/Product.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
118118
*/
119119
protected $_urlModel = null;
120120

121+
/**
122+
* @var ResourceModel\Product
123+
*/
124+
protected $_resource;
125+
121126
/**
122127
* @var string
123128
*/
@@ -482,6 +487,18 @@ protected function _construct()
482487
$this->_init(\Magento\Catalog\Model\ResourceModel\Product::class);
483488
}
484489

490+
/**
491+
* Get resource instance
492+
*
493+
* @throws \Magento\Framework\Exception\LocalizedException
494+
* @return \Magento\Catalog\Model\ResourceModel\Product
495+
* @deprecated because resource models should be used directly
496+
*/
497+
protected function _getResource()
498+
{
499+
return parent::_getResource();
500+
}
501+
485502
/**
486503
* Get a list of custom attribute codes that belongs to product attribute set. If attribute set not specified for
487504
* product will return all attribute codes

app/code/Magento/Catalog/Pricing/Price/ConfiguredRegularPrice.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public function setItem(ItemInterface $item)
7070
public function getValue()
7171
{
7272
$basePrice = parent::getValue();
73-
return $this->item
73+
74+
return ($this->item && $basePrice !== false)
7475
? $basePrice + $this->configuredOptions->getItemOptionsValue($basePrice, $this->item)
7576
: $basePrice;
7677
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $viewModel = $block->getData('viewModel');
1111
"breadcrumbs": {
1212
"categoryUrlSuffix": "<?= $block->escapeHtml($viewModel->getCategoryUrlSuffix()); ?>",
1313
"useCategoryPathInUrl": <?= (int)$viewModel->isCategoryUsedInProductUrl(); ?>,
14-
"product": "<?= $block->escapeHtml($viewModel->getProductName()); ?>"
14+
"product": "<?= $block->escapeHtml($block->escapeJsQuote($viewModel->getProductName(), '"')); ?>"
1515
}
1616
}'>
1717
</div>

app/code/Magento/Checkout/Controller/Cart.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,7 @@ protected function getBackUrl($defaultUrl = null)
118118
return $returnUrl;
119119
}
120120

121-
$shouldRedirectToCart = $this->_scopeConfig->getValue(
122-
'checkout/cart/redirect_to_cart',
123-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
124-
);
125-
126-
if ($shouldRedirectToCart || $this->getRequest()->getParam('in_cart')) {
121+
if ($this->shouldRedirectToCart() || $this->getRequest()->getParam('in_cart')) {
127122
if ($this->getRequest()->getActionName() == 'add' && !$this->getRequest()->getParam('in_cart')) {
128123
$this->_checkoutSession->setContinueShoppingUrl($this->_redirect->getRefererUrl());
129124
}
@@ -132,4 +127,15 @@ protected function getBackUrl($defaultUrl = null)
132127

133128
return $defaultUrl;
134129
}
130+
131+
/**
132+
* @return bool
133+
*/
134+
private function shouldRedirectToCart()
135+
{
136+
return $this->_scopeConfig->isSetFlag(
137+
'checkout/cart/redirect_to_cart',
138+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
139+
);
140+
}
135141
}

app/code/Magento/Checkout/Controller/Cart/Add.php

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,21 @@ public function execute()
122122

123123
if (!$this->_checkoutSession->getNoCartRedirect(true)) {
124124
if (!$this->cart->getQuote()->getHasError()) {
125-
$message = __(
126-
'You added %1 to your shopping cart.',
127-
$product->getName()
128-
);
129-
$this->messageManager->addSuccessMessage($message);
125+
if ($this->shouldRedirectToCart()) {
126+
$message = __(
127+
'You added %1 to your shopping cart.',
128+
$product->getName()
129+
);
130+
$this->messageManager->addSuccessMessage($message);
131+
} else {
132+
$this->messageManager->addComplexSuccessMessage(
133+
'addCartSuccessMessage',
134+
[
135+
'product_name' => $product->getName(),
136+
'cart_url' => $this->getCartUrl(),
137+
]
138+
);
139+
}
130140
}
131141
return $this->goBack(null, $product);
132142
}
@@ -147,8 +157,7 @@ public function execute()
147157
$url = $this->_checkoutSession->getRedirectUrl(true);
148158

149159
if (!$url) {
150-
$cartUrl = $this->_objectManager->get(\Magento\Checkout\Helper\Cart::class)->getCartUrl();
151-
$url = $this->_redirect->getRedirectUrl($cartUrl);
160+
$url = $this->_redirect->getRedirectUrl($this->getCartUrl());
152161
}
153162

154163
return $this->goBack($url);
@@ -188,4 +197,23 @@ protected function goBack($backUrl = null, $product = null)
188197
$this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result)
189198
);
190199
}
200+
201+
/**
202+
* @return string
203+
*/
204+
private function getCartUrl()
205+
{
206+
return $this->_url->getUrl('checkout/cart', ['_secure' => true]);
207+
}
208+
209+
/**
210+
* @return bool
211+
*/
212+
private function shouldRedirectToCart()
213+
{
214+
return $this->_scopeConfig->isSetFlag(
215+
'checkout/cart/redirect_to_cart',
216+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
217+
);
218+
}
191219
}

app/code/Magento/Checkout/Controller/Index/Index.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,16 @@ public function execute()
5151
*/
5252
private function isSecureRequest(): bool
5353
{
54-
$secure = false;
5554
$request = $this->getRequest();
5655

57-
if ($request->isSecure()) {
58-
$secure = true;
59-
}
56+
$referrer = $request->getHeader('referer');
57+
$secure = false;
6058

61-
if ($request->getHeader('referer')) {
62-
$scheme = parse_url($request->getHeader('referer'), PHP_URL_SCHEME);
59+
if ($referrer) {
60+
$scheme = parse_url($referrer, PHP_URL_SCHEME);
6361
$secure = $scheme === 'https';
6462
}
6563

66-
return $secure;
64+
return $secure && $request->isSecure();
6765
}
6866
}

app/code/Magento/Checkout/Test/Unit/Controller/Index/IndexTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,26 +236,27 @@ public function testRegenerateSessionIdOnExecute(bool $secure, string $referer,
236236
public function sessionRegenerationDataProvider(): array
237237
{
238238
return [
239+
[
240+
'secure' => false,
241+
'referer' => 'https://test.domain.com/',
242+
'expectedCall' => self::once()
243+
],
239244
[
240245
'secure' => true,
241246
'referer' => false,
242-
'expectedCall' => self::never()
247+
'expectedCall' => self::once()
243248
],
244249
[
245250
'secure' => true,
246-
'referer' => 'https://test.domain.com/',
247-
'expectedCall' => self::never()
251+
'referer' => 'http://test.domain.com/',
252+
'expectedCall' => self::once()
248253
],
254+
// This is the only case in which session regeneration can be skipped
249255
[
250-
'secure' => false,
256+
'secure' => true,
251257
'referer' => 'https://test.domain.com/',
252258
'expectedCall' => self::never()
253259
],
254-
[
255-
'secure' => true,
256-
'referer' => 'http://test.domain.com/',
257-
'expectedCall' => self::once()
258-
]
259260
];
260261
}
261262

app/code/Magento/Checkout/etc/frontend/di.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,16 @@
8383
</argument>
8484
</arguments>
8585
</type>
86+
<type name="Magento\Framework\View\Element\Message\MessageConfigurationsPool">
87+
<arguments>
88+
<argument name="configurationsMap" xsi:type="array">
89+
<item name="addCartSuccessMessage" xsi:type="array">
90+
<item name="renderer" xsi:type="const">\Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE</item>
91+
<item name="data" xsi:type="array">
92+
<item name="template" xsi:type="string">Magento_Checkout::messages/addCartSuccessMessage.phtml</item>
93+
</item>
94+
</item>
95+
</argument>
96+
</arguments>
97+
</type>
8698
</config>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
// @codingStandardsIgnoreFile
7+
/** @var \Magento\Framework\View\Element\Template $block */
8+
?>
9+
10+
<?= $block->escapeHtml(__(
11+
'You added %1 to your <a href="%2">shopping cart</a>.',
12+
$block->getData('product_name'),
13+
$block->getData('cart_url')
14+
), ['a']);

0 commit comments

Comments
 (0)