Skip to content
Permalink
Browse files

Merge pull request #4803 from magento-performance/MC-18719

Customer data invalidation fix
  • Loading branch information
vzabaznov committed Sep 23, 2019
2 parents 50a085d + f4a11e9 commit d6ef3ef017dc33c12d489c3e2923d3c2f3c4d6de
Showing with 110 additions and 101 deletions.
  1. +3 −3 app/code/Magento/Analytics/Test/Mftf/Test/AdminConfigurationTimeToSendDataTest.xml
  2. +1 −0 app/code/Magento/Checkout/etc/frontend/sections.xml
  3. +2 −2 app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js
  4. +39 −0 app/code/Magento/Customer/Block/SectionNamesProvider.php
  5. +10 −0 app/code/Magento/Customer/CustomerData/SectionPool.php
  6. +5 −0 app/code/Magento/Customer/etc/di.xml
  7. +6 −3 app/code/Magento/Customer/view/frontend/layout/default.xml
  8. +3 −1 app/code/Magento/Customer/view/frontend/templates/js/section-config.phtml
  9. +6 −25 app/code/Magento/Customer/view/frontend/web/js/customer-data.js
  10. +11 −1 app/code/Magento/Customer/view/frontend/web/js/section-config.js
  11. +3 −0 app/code/Magento/Persistent/etc/frontend/sections.xml
  12. +5 −0 app/code/Magento/Quote/Test/Mftf/Test/StorefrontGuestCheckoutDisabledProductTest.xml
  13. +1 −1 ...tests/app/Magento/CheckoutAgreements/Test/Block/Adminhtml/Block/Agreement/Edit/AgreementsForm.xml
  14. +1 −1 dev/tests/functional/tests/app/Magento/Customer/Test/Block/Form/CustomerForm.php
  15. +1 −1 dev/tests/functional/tests/app/Magento/Newsletter/Test/Block/Adminhtml/Queue/Edit/QueueForm.xml
  16. +1 −1 dev/tests/functional/tests/app/Magento/Reports/Test/Block/Adminhtml/Sales/Coupons/Filter.xml
  17. +1 −1 dev/tests/functional/tests/app/Magento/Reports/Test/Block/Adminhtml/Sales/TaxRule/Filter.xml
  18. +1 −1 dev/tests/functional/tests/app/Magento/Review/Test/Block/Adminhtml/Rating/Edit/RatingForm.xml
  19. +1 −1 dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Report/Filter/Form.xml
  20. +0 −45 lib/web/mage/validation.js
  21. +9 −14 lib/web/mage/validation/validation.js
@@ -25,9 +25,9 @@
<amOnPage url="{{AdminConfigGeneralAnalyticsPage.url}}" stepKey="amOnAdminConfig"/>
<selectOption selector="{{AdminConfigAdvancedReportingSection.advancedReportingService}}" userInput="Enable" stepKey="selectAdvancedReportingServiceEnabled"/>
<selectOption selector="{{AdminConfigAdvancedReportingSection.advancedReportingIndustry}}" userInput="Apps and Games" stepKey="selectAdvancedReportingIndustry"/>
<selectOption selector="{{AdminConfigAdvancedReportingSection.advancedReportingHour}}" userInput="11" stepKey="selectAdvancedReportingHour"/>
<selectOption selector="{{AdminConfigAdvancedReportingSection.advancedReportingMinute}}" userInput="11" stepKey="selectAdvancedReportingMinute"/>
<selectOption selector="{{AdminConfigAdvancedReportingSection.advancedReportingSeconds}}" userInput="00" stepKey="selectAdvancedReportingSeconds"/>
<selectOption selector="{{AdminConfigAdvancedReportingSection.advancedReportingHour}}" userInput="23" stepKey="selectAdvancedReportingHour"/>
<selectOption selector="{{AdminConfigAdvancedReportingSection.advancedReportingMinute}}" userInput="59" stepKey="selectAdvancedReportingMinute"/>
<selectOption selector="{{AdminConfigAdvancedReportingSection.advancedReportingSeconds}}" userInput="59" stepKey="selectAdvancedReportingSeconds"/>
<click selector="{{AdminMainActionsSection.save}}" stepKey="clickSaveConfigButton"/>
<see selector="{{AdminMessagesSection.success}}" userInput="You saved the configuration." stepKey="seeSuccess"/>
</test>
@@ -9,6 +9,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
<action name="checkout/cart/add">
<section name="cart"/>
<section name="directory-data"/>
</action>
<action name="checkout/cart/delete">
<section name="cart"/>
@@ -103,8 +103,8 @@ define([
});

if (
cartData().website_id !== window.checkout.websiteId &&
cartData().website_id !== undefined
cartData().website_id !== window.checkout.websiteId && cartData().website_id !== undefined ||
cartData().storeId !== window.checkout.storeId && cartData().storeId !== undefined
) {
customerData.reload(['cart'], false);
}
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Block;

use Magento\Customer\CustomerData\SectionPool;
use Magento\Framework\View\Element\Block\ArgumentInterface;

/**
* ViewModel to get sections names array.
*/
class SectionNamesProvider implements ArgumentInterface
{
/**
* @var SectionPool
*/
private $sectionPool;

/**
* @param SectionPool $sectionPool
*/
public function __construct(
SectionPool $sectionPool
) {
$this->sectionPool = $sectionPool;
}

/**
* Return array of section names based on config.
*
* @return array
*/
public function getSectionNames()
{
return $this->sectionPool->getSectionNames();
}
}
@@ -62,6 +62,16 @@ public function getSectionsData(array $sectionNames = null, $forceNewTimestamp =
return $sectionsData;
}

/**
* Return array of section names.
*
* @return array
*/
public function getSectionNames()
{
return array_keys($this->sectionSourceMap);
}

/**
* Get section sources by section names
*
@@ -157,6 +157,11 @@
<argument name="sectionConfig" xsi:type="object">SectionInvalidationConfigData</argument>
</arguments>
</type>
<type name="Magento\Customer\Block\SectionNamesProvider">
<arguments>
<argument name="sectionConfig" xsi:type="object">SectionInvalidationConfigData</argument>
</arguments>
</type>
<preference for="Magento\Customer\CustomerData\JsLayoutDataProviderPoolInterface"
type="Magento\Customer\CustomerData\JsLayoutDataProviderPool"/>
<type name="Magento\Framework\Webapi\ServiceTypeToEntityTypeMap">
@@ -41,9 +41,12 @@
</arguments>
</block>
<block name="customer.section.config" class="Magento\Customer\Block\SectionConfig"
template="Magento_Customer::js/section-config.phtml"/>
<block name="customer.customer.data"
class="Magento\Customer\Block\CustomerData"
template="Magento_Customer::js/section-config.phtml">
<arguments>
<argument name="sectionNamesProvider" xsi:type="object">Magento\Customer\Block\SectionNamesProvider</argument>
</arguments>
</block>
<block name="customer.customer.data" class="Magento\Customer\Block\CustomerData"
template="Magento_Customer::js/customer-data.phtml"/>
<block name="customer.data.invalidation.rules" class="Magento\Customer\Block\CustomerScopeData"
template="Magento_Customer::js/customer-data/invalidation-rules.phtml"/>
@@ -15,7 +15,9 @@
"baseUrls": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode(array_unique([
$block->getUrl(null, ['_secure' => true]),
$block->getUrl(null, ['_secure' => false]),
])) ?>
])) ?>,
"sectionNames": <?= /* @noEscape */ $this->helper(\Magento\Framework\Json\Helper\Data::class)
->jsonEncode($block->getData('sectionNamesProvider')->getSectionNames()) ?>
}
}
}
@@ -198,30 +198,9 @@ define([
* Customer data initialization
*/
init: function () {
var privateContentVersion = 'private_content_version',
privateContent = $.cookieStorage.get(privateContentVersion),
localPrivateContent = $.localStorage.get(privateContentVersion),
needVersion = 'need_version',
expiredSectionNames = this.getExpiredSectionNames();

if (privateContent &&
!$.cookieStorage.isSet(privateContentVersion) &&
!$.localStorage.isSet(privateContentVersion)
) {
$.cookieStorage.set(privateContentVersion, needVersion);
$.localStorage.set(privateContentVersion, needVersion);
this.reload([], false);
} else if (localPrivateContent !== privateContent) {
if (!$.cookieStorage.isSet(privateContentVersion)) {
privateContent = needVersion;
$.cookieStorage.set(privateContentVersion, privateContent);
}
$.localStorage.set(privateContentVersion, privateContent);
_.each(dataProvider.getFromStorage(storage.keys()), function (sectionData, sectionName) {
buffer.notify(sectionName, sectionData);
});
this.reload([], false);
} else if (expiredSectionNames.length > 0) {
var expiredSectionNames = this.getExpiredSectionNames();

if (expiredSectionNames.length > 0) {
_.each(dataProvider.getFromStorage(storage.keys()), function (sectionData, sectionName) {
buffer.notify(sectionName, sectionData);
});
@@ -341,7 +320,9 @@ define([
var sectionDataIds,
sectionsNamesForInvalidation;

sectionsNamesForInvalidation = _.contains(sectionNames, '*') ? buffer.keys() : sectionNames;
sectionsNamesForInvalidation = _.contains(sectionNames, '*') ? sectionConfig.getSectionNames() :
sectionNames;

$(document).trigger('customer-data-invalidate', [sectionsNamesForInvalidation]);
buffer.remove(sectionsNamesForInvalidation);
sectionDataIds = $.cookieStorage.get('section_data_ids') || {};
@@ -6,7 +6,7 @@
define(['underscore'], function (_) {
'use strict';

var baseUrls, sections, clientSideSections, canonize;
var baseUrls, sections, clientSideSections, sectionNames, canonize;

/**
* @param {String} url
@@ -70,6 +70,15 @@ define(['underscore'], function (_) {
return _.contains(clientSideSections, sectionName);
},

/**
* Returns array of section names.
*
* @returns {Array}
*/
getSectionNames: function () {
return sectionNames;
},

/**
* @param {Object} options
* @constructor
@@ -78,6 +87,7 @@ define(['underscore'], function (_) {
baseUrls = options.baseUrls;
sections = options.sections;
clientSideSections = options.clientSideSections;
sectionNames = options.sectionNames;
}
};
});
@@ -10,4 +10,7 @@
<action name="persistent/index/unsetCookie">
<section name="persistent"/>
</action>
<action name="customer/account/logout">
<section name="persistent"/>
</action>
</config>
@@ -73,6 +73,9 @@
<requiredEntity createDataKey="createConfigProduct"/>
<requiredEntity createDataKey="createConfigChildProduct2"/>
</createData>
<magentoCLI command="config:set customer/online_customers/section_data_lifetime 1"
stepKey="setConfigForCartLifetime"/>
<magentoCLI command="cache:flush" stepKey="flushCache" />
</before>
<after>
<deleteData createDataKey="createSimpleProduct" stepKey="deleteProduct"/>
@@ -116,6 +119,7 @@
</actionGroup>
<closeTab stepKey="closeTab"/>
<!-- Check cart -->
<wait time="60" stepKey="waitForCartToBeUpdated"/>
<reloadPage stepKey="reloadPage"/>
<waitForPageLoad stepKey="waitForCheckoutPageReload"/>
<click selector="{{StorefrontMiniCartSection.show}}" stepKey="clickMiniCart"/>
@@ -143,6 +147,7 @@
</actionGroup>
<closeTab stepKey="closeTab2"/>
<!--Check cart-->
<wait time="60" stepKey="waitForCartToBeUpdated2"/>
<reloadPage stepKey="reloadPage2"/>
<waitForPageLoad stepKey="waitForCheckoutPageReload2"/>
<click selector="{{StorefrontMiniCartSection.show}}" stepKey="clickMiniCart2"/>
@@ -18,7 +18,7 @@
<input>select</input>
</mode>
<stores>
<selector>[name="stores[0]"]</selector>
<selector>[name="stores[]"]</selector>
<input>multiselectgrouplist</input>
</stores>
<checkbox_text />
@@ -29,7 +29,7 @@ class CustomerForm extends Form
*
* @var string
*/
protected $customerAttribute = "[orig-name='%s[]']";
protected $customerAttribute = "[name='%s[]']";

/**
* Validation text message for a field.
@@ -11,7 +11,7 @@
<selector>input[name='start_at']</selector>
</queue_start_at>
<stores>
<selector>select[name="stores[0]"]</selector>
<selector>select[name="stores[]"]</selector>
<input>multiselectgrouplist</input>
</stores>
<newsletter_subject>
@@ -29,7 +29,7 @@
<input>select</input>
</price_rule_type>
<order_statuses>
<selector>[name="order_statuses[0]"]</selector>
<selector>[name="order_statuses[]"]</selector>
<input>multiselect</input>
</order_statuses>
<rules_list>
@@ -23,7 +23,7 @@
<input>select</input>
</show_order_statuses>
<order_statuses>
<selector>[name="order_statuses[0]"]</selector>
<selector>[name="order_statuses[]"]</selector>
<input>multiselect</input>
</order_statuses>
<show_empty_rows>
@@ -12,7 +12,7 @@
<strategy>css selector</strategy>
<fields>
<stores>
<selector>[name="stores[0]"]</selector>
<selector>[name="stores[]"]</selector>
<input>multiselectgrouplist</input>
</stores>
<is_active>
@@ -26,7 +26,7 @@
<input>select</input>
</show_order_statuses>
<order_statuses>
<selector>[name="order_statuses[0]"]</selector>
<selector>[name="order_statuses[]"]</selector>
<input>multiselect</input>
</order_statuses>
<show_actual_columns>
@@ -1925,7 +1925,6 @@
* @protected
*/
_create: function () {
this._prepareArrayInputs();
this.validate = this.element.validate(this.options);

// ARIA (adding aria-required attribute)
@@ -1938,50 +1937,6 @@
this._listenFormValidate();
},

/**
* Validation creation.
*
* @protected
*/
_prepareArrayInputs: function () {
/* Store original names for array inputs */
var originalElements = [],
originalSubmitHandler = this.options.submitHandler;

/* For all array inputs, assign index so that validation is proper */
this.element.find('[name$="[]"]').each(function (key, input) {
var originalName, name;

input = $(input);
originalName = input.attr('name');
name = originalName.replace('[]', '[' + key + ']');
$(input).attr('name', name);
$(input).attr('orig-name', originalName);
originalElements.push({
element: $(input),
name: originalName
});
});

if (originalElements.length) {
/**
* Before submitting the actual form, remove the previously assigned indices
* @param {Object} form
*/
this.options.submitHandler = function (form) {
originalElements.forEach(function (element) {
element.element.attr('name', element.name);
element.element.removeAttr('orig-name');
});

console.error(this.submit);

/* Call the originalSubmitHandler if it's a function */
typeof originalSubmitHandler === 'function' ? originalSubmitHandler(form) : form.submit();
};
}
},

/**
* Validation listening.
*
@@ -49,23 +49,18 @@
'validate-one-checkbox-required-by-name': [
function (value, element, params) {
var checkedCount = 0,
selector,
container,
origNameSelector,
nameSelector;
container;

if (element.type === 'checkbox') {
/* If orig-name attribute is present, use it for validation. Else use name */
origNameSelector = '[orig-name="' + element.getAttribute('orig-name') + '"]';
nameSelector = '[name="' + element.name + '"]';
selector = element.getAttribute('orig-name') ? origNameSelector : nameSelector;
$(selector).each(function () {
if ($(this).is(':checked')) {
checkedCount += 1;

return false;
$('[name="' + element.name + '"]').each(
function () {
if ($(this).is(':checked')) {
checkedCount += 1;

return false;
}
}
});
);
}
container = '#' + params;

0 comments on commit d6ef3ef

Please sign in to comment.
You can’t perform that action at this time.