Skip to content

Commit 02e881b

Browse files
author
Viktor Tymchynskyi
committed
Merge remote-tracking branch 'magento2/merchant_beta' into MAGETWO-43092
2 parents 493e0d7 + 523c2eb commit 02e881b

File tree

10 files changed

+360
-17
lines changed

10 files changed

+360
-17
lines changed

app/code/Magento/Checkout/Block/Cart/Sidebar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function getShoppingCartUrl()
106106
*/
107107
public function getUpdateItemQtyUrl()
108108
{
109-
return $this->getUrl('checkout/sidebar/updateItemQty');
109+
return $this->getUrl('checkout/sidebar/updateItemQty', ['_secure' => $this->getRequest()->isSecure()]);
110110
}
111111

112112
/**
@@ -116,7 +116,7 @@ public function getUpdateItemQtyUrl()
116116
*/
117117
public function getRemoveItemUrl()
118118
{
119-
return $this->getUrl('checkout/sidebar/removeItem');
119+
return $this->getUrl('checkout/sidebar/removeItem', ['_secure' => $this->getRequest()->isSecure()]);
120120
}
121121

122122
/**

app/code/Magento/Checkout/Test/Unit/Block/Cart/SidebarTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,16 @@ class SidebarTest extends \PHPUnit_Framework_TestCase
4545
*/
4646
protected $checkoutSessionMock;
4747

48+
/**
49+
* @var \PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
protected $requestMock;
52+
4853
protected function setUp()
4954
{
5055
$this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
5156

57+
$this->requestMock = $this->getMock('\Magento\Framework\App\RequestInterface');
5258
$this->layoutMock = $this->getMock('\Magento\Framework\View\Layout', [], [], '', false);
5359
$this->checkoutSessionMock = $this->getMock('\Magento\Checkout\Model\Session', [], [], '', false);
5460
$this->urlBuilderMock = $this->getMock('\Magento\Framework\UrlInterface', [], [], '', false);
@@ -64,7 +70,7 @@ protected function setUp()
6470

6571
$contextMock = $this->getMock(
6672
'\Magento\Framework\View\Element\Template\Context',
67-
['getLayout', 'getUrlBuilder', 'getStoreManager', 'getScopeConfig'],
73+
['getLayout', 'getUrlBuilder', 'getStoreManager', 'getScopeConfig', 'getRequest'],
6874
[],
6975
'',
7076
false
@@ -81,6 +87,9 @@ protected function setUp()
8187
$contextMock->expects($this->once())
8288
->method('getScopeConfig')
8389
->will($this->returnValue($this->scopeConfigMock));
90+
$contextMock->expects($this->any())
91+
->method('getRequest')
92+
->will($this->returnValue($this->requestMock));
8493

8594
$this->model = $this->_objectManager->getObject(
8695
'Magento\Checkout\Block\Cart\Sidebar',
@@ -131,10 +140,14 @@ public function testGetConfig()
131140
$valueMap = [
132141
['checkout/cart', [], $shoppingCartUrl],
133142
['checkout', [], $checkoutUrl],
134-
['checkout/sidebar/updateItemQty', [], $updateItemQtyUrl],
135-
['checkout/sidebar/removeItem', [], $removeItemUrl]
143+
['checkout/sidebar/updateItemQty', ['_secure' => false], $updateItemQtyUrl],
144+
['checkout/sidebar/removeItem', ['_secure' => false], $removeItemUrl]
136145
];
137146

147+
$this->requestMock->expects($this->any())
148+
->method('isSecure')
149+
->willReturn(false);
150+
138151
$this->urlBuilderMock->expects($this->exactly(4))
139152
->method('getUrl')
140153
->willReturnMap($valueMap);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<argument name="secureUrlList" xsi:type="array">
1313
<item name="checkout_index" xsi:type="string">/checkout</item>
1414
</argument>
15+
<argument name="excludedUrlList" xsi:type="array">
16+
<item name="checkout_sidebar" xsi:type="string">/checkout/sidebar</item>
17+
</argument>
1518
</arguments>
1619
</type>
1720
<type name="Magento\Framework\View\Layout">

app/code/Magento/Customer/Controller/Section/Load.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class Load extends \Magento\Framework\App\Action\Action
2020
*/
2121
protected $resultJsonFactory;
2222

23+
/**
24+
* @var Identifier
25+
*/
26+
protected $sectionIdentifier;
27+
2328
/**
2429
* @var SectionPoolInterface
2530
*/
@@ -28,15 +33,18 @@ class Load extends \Magento\Framework\App\Action\Action
2833
/**
2934
* @param Context $context
3035
* @param JsonFactory $resultJsonFactory
36+
* @param \Magento\Customer\CustomerData\Section\Identifier $sectionIdentifier
3137
* @param SectionPoolInterface $sectionPool
3238
*/
3339
public function __construct(
3440
Context $context,
3541
JsonFactory $resultJsonFactory,
42+
\Magento\Customer\CustomerData\Section\Identifier $sectionIdentifier,
3643
SectionPoolInterface $sectionPool
3744
) {
3845
parent::__construct($context);
3946
$this->resultJsonFactory = $resultJsonFactory;
47+
$this->sectionIdentifier = $sectionIdentifier;
4048
$this->sectionPool = $sectionPool;
4149
}
4250

@@ -51,7 +59,11 @@ public function execute()
5159
$sectionNames = $this->getRequest()->getParam('sections');
5260
$sectionNames = $sectionNames ? array_unique(\explode(',', $sectionNames)) : null;
5361

54-
$response = $this->sectionPool->getSectionsData($sectionNames);
62+
$updateSectionId = $this->getRequest()->getParam('update_section_id');
63+
if ('false' == $updateSectionId) {
64+
$updateSectionId = false;
65+
}
66+
$response = $this->sectionPool->getSectionsData($sectionNames, (bool)$updateSectionId);
5567
} catch (\Exception $e) {
5668
$resultJson->setStatusHeader(
5769
\Zend\Http\Response::STATUS_CODE_400,
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\CustomerData\Section;
7+
8+
/**
9+
* Customer section identifier
10+
*/
11+
class Identifier
12+
{
13+
const COOKIE_KEY = 'storage_data_id';
14+
15+
const SECTION_KEY = 'data_id';
16+
17+
const UPDATE_MARK = 'sections_updated';
18+
19+
/**
20+
* @var int
21+
*/
22+
protected $markId;
23+
24+
/**
25+
* @var \Magento\Framework\Stdlib\Cookie\PhpCookieManager
26+
*/
27+
protected $cookieManager;
28+
29+
/**
30+
* @var \Magento\Framework\Session\Config\ConfigInterface
31+
*/
32+
protected $sessionConfig;
33+
34+
/**
35+
* @param \Magento\Framework\Stdlib\Cookie\PhpCookieManager $cookieManager
36+
*/
37+
public function __construct(
38+
\Magento\Framework\Stdlib\Cookie\PhpCookieManager $cookieManager
39+
) {
40+
$this->cookieManager = $cookieManager;
41+
}
42+
43+
/**
44+
* Init mark(identifier) for sections
45+
*
46+
* @param bool $forceUpdate
47+
* @return int
48+
*/
49+
public function initMark($forceUpdate)
50+
{
51+
if ($forceUpdate) {
52+
$this->markId = time();
53+
return $this->markId;
54+
}
55+
56+
$cookieMarkId = false;
57+
if (!$this->markId) {
58+
$cookieMarkId = $this->cookieManager->getCookie(self::COOKIE_KEY);
59+
}
60+
61+
$this->markId = $cookieMarkId ? $cookieMarkId : time();
62+
63+
return $this->markId;
64+
}
65+
66+
/**
67+
* Mark sections with data id
68+
*
69+
* @param array $sectionsData
70+
* @param null $sectionNames
71+
* @param bool $updateIds
72+
* @return array
73+
*/
74+
public function markSections(array $sectionsData, $sectionNames = null, $updateIds = false)
75+
{
76+
if (!$sectionNames) {
77+
$sectionNames = array_keys($sectionsData);
78+
}
79+
$markId = $this->initMark($updateIds);
80+
81+
foreach ($sectionNames as $name) {
82+
if ($updateIds || !array_key_exists(self::SECTION_KEY, $sectionsData[$name])) {
83+
$sectionsData[$name][self::SECTION_KEY] = $markId;
84+
}
85+
}
86+
return $sectionsData;
87+
}
88+
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,36 @@ class SectionPool implements SectionPoolInterface
2727
*/
2828
protected $sectionSourceMap;
2929

30+
/**
31+
* @var \Magento\Customer\CustomerData\Section\Identifier
32+
*/
33+
protected $identifier;
34+
3035
/**
3136
* Construct
3237
*
3338
* @param ObjectManagerInterface $objectManager
39+
* @param \Magento\Customer\CustomerData\Section\Identifier $identifier
3440
* @param array $sectionSourceMap
3541
*/
36-
public function __construct(ObjectManagerInterface $objectManager, array $sectionSourceMap = [])
37-
{
42+
public function __construct(
43+
ObjectManagerInterface $objectManager,
44+
\Magento\Customer\CustomerData\Section\Identifier $identifier,
45+
array $sectionSourceMap = []
46+
) {
3847
$this->objectManager = $objectManager;
48+
$this->identifier = $identifier;
3949
$this->sectionSourceMap = $sectionSourceMap;
4050
}
4151

4252
/**
4353
* {@inheritdoc}
4454
*/
45-
public function getSectionsData(array $sectionNames = null)
55+
public function getSectionsData(array $sectionNames = null, $updateIds = false)
4656
{
47-
return $sectionNames ? $this->getSectionDataByNames($sectionNames) : $this->getAllSectionData();
57+
$sectionsData = $sectionNames ? $this->getSectionDataByNames($sectionNames) : $this->getAllSectionData();
58+
$sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $updateIds);
59+
return $sectionsData;
4860
}
4961

5062
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface SectionPoolInterface
1414
* Get section data by section names. If $sectionNames is null then return all sections data
1515
*
1616
* @param array $sectionNames
17+
* @param bool $updateIds
1718
* @return array
1819
*/
19-
public function getSectionsData(array $sectionNames = null);
20+
public function getSectionsData(array $sectionNames = null, $updateIds = false);
2021
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Test\Unit\CustomerData\Section;
8+
9+
use \Magento\Customer\CustomerData\Section\Identifier;
10+
11+
class IdentifierTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Customer\CustomerData\Section\Identifier
15+
*/
16+
protected $model;
17+
18+
/**
19+
* @var \PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
protected $cookieManMock;
22+
23+
/**
24+
* @var string
25+
*/
26+
protected $cookieMarkId;
27+
28+
protected function setUp()
29+
{
30+
$this->cookieManMock = $this->getMock('Magento\Framework\Stdlib\Cookie\PhpCookieManager', [], [], '', false);
31+
$this->cookieMarkId = '123456';
32+
$this->model = new Identifier(
33+
$this->cookieManMock
34+
);
35+
}
36+
37+
public function testInitMark()
38+
{
39+
$this->cookieManMock->expects($this->once())
40+
->method('getCookie')
41+
->with(Identifier::COOKIE_KEY)
42+
->willReturn($this->cookieMarkId);
43+
$this->assertEquals($this->cookieMarkId, $this->model->initMark(false));
44+
}
45+
46+
public function testMarkSectionsDontUpdate()
47+
{
48+
$sectionsData = [
49+
'section1' => [1],
50+
'section2' => [2],
51+
'section3' => [3],
52+
];
53+
54+
$expectedData = [
55+
'section1' => [1, 'data_id' => $this->cookieMarkId],
56+
'section2' => [2, 'data_id' => $this->cookieMarkId],
57+
'section3' => [3],
58+
];
59+
$sectionNames = ['section1', 'section2'];
60+
61+
$this->cookieManMock->expects($this->once())
62+
->method('getCookie')
63+
->with(Identifier::COOKIE_KEY)
64+
->willReturn($this->cookieMarkId);
65+
66+
// third parameter is true to avoid diving deeply into initMark()
67+
$result = $this->model->markSections($sectionsData, $sectionNames, false);
68+
$this->assertEquals($expectedData, $result);
69+
}
70+
71+
public function testMarkSectionsUpdate()
72+
{
73+
$sectionsData = [
74+
'section1' => [1, 'data_id' => 0],
75+
'section2' => [2, 'data_id' => 0],
76+
'section3' => [3],
77+
];
78+
$sectionNames = ['section1', 'section2'];
79+
80+
// third parameter is true to avoid diving deeply into initMark()
81+
$result = $this->model->markSections($sectionsData, $sectionNames, true);
82+
$this->assertArrayHasKey('data_id', $result['section1']);
83+
$this->assertNotEquals(0, $result['section1']['data_id']);
84+
$this->assertArrayHasKey('data_id', $result['section2']);
85+
$this->assertNotEquals(0, $result['section2']['data_id']);
86+
}
87+
}

0 commit comments

Comments
 (0)