Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/code/Magento/Customer/Controller/Section/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ public function execute()
$sectionNames = $this->getRequest()->getParam('sections');
$sectionNames = $sectionNames ? array_unique(\explode(',', $sectionNames)) : null;

$updateSectionId = $this->getRequest()->getParam('update_section_id');
if ('false' === $updateSectionId) {
$updateSectionId = false;
$forceNewSectionTimestamp = $this->getRequest()->getParam('force_new_section_timestamp');
if ('false' === $forceNewSectionTimestamp) {
$forceNewSectionTimestamp = false;
}
$response = $this->sectionPool->getSectionsData($sectionNames, (bool)$updateSectionId);
$response = $this->sectionPool->getSectionsData($sectionNames, (bool)$forceNewSectionTimestamp);
} catch (\Exception $e) {
$resultJson->setStatusHeader(
\Zend\Http\Response::STATUS_CODE_400,
Expand Down
14 changes: 7 additions & 7 deletions app/code/Magento/Customer/CustomerData/Section/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public function __construct(
/**
* Init mark(identifier) for sections
*
* @param bool $forceUpdate
* @param bool $forceNewTimestamp
* @return int
*/
public function initMark($forceUpdate)
public function initMark($forceNewTimestamp)
{
if ($forceUpdate) {
if ($forceNewTimestamp) {
$this->markId = time();
return $this->markId;
}
Expand All @@ -68,18 +68,18 @@ public function initMark($forceUpdate)
*
* @param array $sectionsData
* @param null $sectionNames
* @param bool $updateIds
* @param bool $forceNewTimestamp
* @return array
*/
public function markSections(array $sectionsData, $sectionNames = null, $updateIds = false)
public function markSections(array $sectionsData, $sectionNames = null, $forceNewTimestamp = false)
{
if (!$sectionNames) {
$sectionNames = array_keys($sectionsData);
}
$markId = $this->initMark($updateIds);
$markId = $this->initMark($forceNewTimestamp);

foreach ($sectionNames as $name) {
if ($updateIds || !array_key_exists(self::SECTION_KEY, $sectionsData[$name])) {
if ($forceNewTimestamp || !array_key_exists(self::SECTION_KEY, $sectionsData[$name])) {
$sectionsData[$name][self::SECTION_KEY] = $markId;
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/CustomerData/SectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getSectionsData(array $sectionNames = null, $updateIds = false)
public function getSectionsData(array $sectionNames = null, $forceNewTimestamp = false)
{
$sectionsData = $sectionNames ? $this->getSectionDataByNames($sectionNames) : $this->getAllSectionData();
$sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $updateIds);
$sectionsData = $this->identifier->markSections($sectionsData, $sectionNames, $forceNewTimestamp);
return $sectionsData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interface SectionPoolInterface
* Get section data by section names. If $sectionNames is null then return all sections data
*
* @param array $sectionNames
* @param bool $updateIds
* @param bool $forceNewTimestamp
* @return array
*/
public function getSectionsData(array $sectionNames = null, $updateIds = false);
public function getSectionsData(array $sectionNames = null, $forceNewTimestamp = false);
}
24 changes: 12 additions & 12 deletions app/code/Magento/Customer/Test/Unit/Controller/Section/LoadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ protected function setUp()
}

/**
* @param $sectionNames
* @param $updateSectionID
* @param $sectionNamesAsArray
* @param $updateIds
* @param string $sectionNames
* @param bool $forceNewSectionTimestamp
* @param string[] $sectionNamesAsArray
* @param bool $forceNewTimestamp
* @dataProvider executeDataProvider
*/
public function testExecute($sectionNames, $updateSectionID, $sectionNamesAsArray, $updateIds)
public function testExecute($sectionNames, $forceNewSectionTimestamp, $sectionNamesAsArray, $forceNewTimestamp)
{
$this->resultJsonFactoryMock->expects($this->once())
->method('create')
Expand All @@ -101,12 +101,12 @@ public function testExecute($sectionNames, $updateSectionID, $sectionNamesAsArra

$this->httpRequestMock->expects($this->exactly(2))
->method('getParam')
->withConsecutive(['sections'], ['update_section_id'])
->willReturnOnConsecutiveCalls($sectionNames, $updateSectionID);
->withConsecutive(['sections'], ['force_new_section_timestamp'])
->willReturnOnConsecutiveCalls($sectionNames, $forceNewSectionTimestamp);

$this->sectionPoolMock->expects($this->once())
->method('getSectionsData')
->with($sectionNamesAsArray, $updateIds)
->with($sectionNamesAsArray, $forceNewTimestamp)
->willReturn([
'message' => 'some message',
'someKey' => 'someValue'
Expand All @@ -128,15 +128,15 @@ public function executeDataProvider()
return [
[
'sectionNames' => 'sectionName1,sectionName2,sectionName3',
'updateSectionID' => 'updateSectionID',
'forceNewSectionTimestamp' => 'forceNewSectionTimestamp',
'sectionNamesAsArray' => ['sectionName1', 'sectionName2', 'sectionName3'],
'updateIds' => true
'forceNewTimestamp' => true
],
[
'sectionNames' => null,
'updateSectionID' => null,
'forceNewSectionTimestamp' => null,
'sectionNamesAsArray' => null,
'updateIds' => false
'forceNewTimestamp' => false
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testGetSectionsDataAllSections()

$this->identifierMock->expects($this->once())
->method('markSections')
//check also default value for $updateIds = false
//check also default value for $forceTimestamp = false
->with($allSectionsData, $sectionNames, false)
->willReturn($identifierResult);
$modelResult = $this->model->getSectionsData($sectionNames);
Expand Down
12 changes: 6 additions & 6 deletions app/code/Magento/Customer/view/frontend/web/js/customer-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ define([

/**
* @param {Object} sectionNames
* @param {Number} updateSectionId
* @param {Boolean} forceNewSectionTimestamp
* @return {*}
*/
getFromServer: function (sectionNames, updateSectionId) {
getFromServer: function (sectionNames, forceNewSectionTimestamp) {
var parameters;

sectionNames = sectionConfig.filterClientSideSections(sectionNames);
parameters = _.isArray(sectionNames) ? {
sections: sectionNames.join(',')
} : [];
parameters['update_section_id'] = updateSectionId;
parameters['force_new_section_timestamp'] = forceNewSectionTimestamp;

return $.getJSON(options.sectionLoadUrl, parameters).fail(function (jqXHR) {
throw new Error(jqXHR);
Expand Down Expand Up @@ -324,11 +324,11 @@ define([

/**
* @param {Array} sectionNames
* @param {Number} updateSectionId
* @param {Boolean} forceNewSectionTimestamp
* @return {*}
*/
reload: function (sectionNames, updateSectionId) {
return dataProvider.getFromServer(sectionNames, updateSectionId).done(function (sections) {
reload: function (sectionNames, forceNewSectionTimestamp) {
return dataProvider.getFromServer(sectionNames, forceNewSectionTimestamp).done(function (sections) {
$(document).trigger('customer-data-reload', [sectionNames]);
buffer.update(sections);
});
Expand Down
Loading