Skip to content

Commit a81c586

Browse files
author
Ievgen Shakhsuvarov
committed
MAGETWO-37834: Unable to add product to shopping cart if Use Secure URLs in Frontend = Yes
1 parent 77e1bfd commit a81c586

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

app/code/Magento/Customer/Block/CustomerData.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,15 @@ public function getCookieLifeTime()
1818
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
1919
);
2020
}
21+
22+
/**
23+
* Get url for customer data ajax requests. Returns url with protocol matching used to request page.
24+
*
25+
* @param $route
26+
* @return string
27+
*/
28+
public function getCustomerDataUrl($route)
29+
{
30+
return $this->getUrl($route, ['_secure' => $this->getRequest()->isSecure()]);
31+
}
2132
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<argument name="secureUrlList" xsi:type="array">
1212
<item name="customer" xsi:type="string">/customer/</item>
1313
</argument>
14+
<argument name="excludedUrlList" xsi:type="array">
15+
<item name="customer_sections" xsi:type="string">/customer/section/load</item>
16+
</argument>
1417
</arguments>
1518
</type>
1619
<type name="Magento\Framework\View\Layout">

app/code/Magento/Customer/view/frontend/templates/js/customer-data.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<?php
1212
echo $this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode([
1313
'*' => ['Magento_Customer/js/customer-data' => [
14-
'sectionLoadUrl' => $block->getUrl('customer/section/load'),
14+
'sectionLoadUrl' => $block->getCustomerDataUrl('customer/section/load'),
1515
'cookieLifeTime' => $block->getCookieLifeTime(),
1616
]],
1717
]);

lib/internal/Magento/Framework/Url/SecurityInfo.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class SecurityInfo implements \Magento\Framework\Url\SecurityInfoInterface
1616
*/
1717
protected $secureUrlsList = [];
1818

19+
/**
20+
* List of patterns excluded form secure url list
21+
*/
22+
protected $excludedUrlsList = [];
23+
1924
/**
2025
* List of already checked urls
2126
*
@@ -25,10 +30,12 @@ class SecurityInfo implements \Magento\Framework\Url\SecurityInfoInterface
2530

2631
/**
2732
* @param string[] $secureUrlList
33+
* @param string[] $excludedUrlList
2834
*/
29-
public function __construct($secureUrlList = [])
35+
public function __construct($secureUrlList = [], $excludedUrlList = [])
3036
{
3137
$this->secureUrlsList = $secureUrlList;
38+
$this->excludedUrlsList = $excludedUrlList;
3239
}
3340

3441
/**
@@ -41,6 +48,11 @@ public function isSecure($url)
4148
{
4249
if (!isset($this->secureUrlsCache[$url])) {
4350
$this->secureUrlsCache[$url] = false;
51+
foreach ($this->excludedUrlsList as $match) {
52+
if (strpos($url, (string)$match) === 0) {
53+
return $this->secureUrlsCache[$url];
54+
}
55+
}
4456
foreach ($this->secureUrlsList as $match) {
4557
if (strpos($url, (string)$match) === 0) {
4658
$this->secureUrlsCache[$url] = true;

0 commit comments

Comments
 (0)