From 4551fb97520f9d8dc95f2c59f6edfe7ada084b25 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Fri, 3 Feb 2017 11:47:40 +0200 Subject: [PATCH 01/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- app/code/Magento/Customer/view/frontend/web/js/view/customer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Customer/view/frontend/web/js/view/customer.js b/app/code/Magento/Customer/view/frontend/web/js/view/customer.js index ca8dc96bd6fe0..0ce474ba43b5a 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/view/customer.js +++ b/app/code/Magento/Customer/view/frontend/web/js/view/customer.js @@ -13,6 +13,7 @@ define([ this._super(); this.customer = customerData.get('customer'); + customerData.reload(['customer']); } }); }); From 09c9004bfc522e02a62a2b687e7396400bdb5853 Mon Sep 17 00:00:00 2001 From: Sergii Kovalenko Date: Thu, 2 Mar 2017 13:01:45 +0200 Subject: [PATCH 02/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites --- .../Customer/CustomerData/Customer.php | 7 +++ .../view/frontend/requirejs-config.js | 5 +- .../view/frontend/web/js/customer-data.js | 9 +++- .../frontend/web/js/invalidation-processor.js | 27 ++++++++++ .../web/js/invalidation-rules/website-rule.js | 26 +++++++++ .../view/frontend/web/js/view/customer.js | 1 - .../Magento/Store/Block/ScopeProvider.php | 54 +++++++++++++++++++ .../Store/view/frontend/layout/default.xml | 17 ++++++ .../frontend/templates/js/scope-data.phtml | 13 +++++ 9 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js create mode 100644 app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js create mode 100644 app/code/Magento/Store/Block/ScopeProvider.php create mode 100644 app/code/Magento/Store/view/frontend/layout/default.xml create mode 100644 app/code/Magento/Store/view/frontend/templates/js/scope-data.phtml diff --git a/app/code/Magento/Customer/CustomerData/Customer.php b/app/code/Magento/Customer/CustomerData/Customer.php index 7a8b982ecdc6d..9022e3c7c123e 100644 --- a/app/code/Magento/Customer/CustomerData/Customer.php +++ b/app/code/Magento/Customer/CustomerData/Customer.php @@ -19,6 +19,11 @@ class Customer implements SectionSourceInterface */ protected $currentCustomer; + /** + * @var View + */ + private $customerViewHelper; + /** * @param CurrentCustomer $currentCustomer * @param View $customerViewHelper @@ -39,10 +44,12 @@ public function getSectionData() if (!$this->currentCustomer->getCustomerId()) { return []; } + $customer = $this->currentCustomer->getCustomer(); return [ 'fullname' => $this->customerViewHelper->getCustomerName($customer), 'firstname' => $customer->getFirstname(), + 'websiteId' => $customer->getWebsiteId(), ]; } } diff --git a/app/code/Magento/Customer/view/frontend/requirejs-config.js b/app/code/Magento/Customer/view/frontend/requirejs-config.js index 99442b69ac04e..c3d49a9e0b98a 100644 --- a/app/code/Magento/Customer/view/frontend/requirejs-config.js +++ b/app/code/Magento/Customer/view/frontend/requirejs-config.js @@ -11,7 +11,10 @@ var config = { changeEmailPassword: 'Magento_Customer/change-email-password', passwordStrengthIndicator: 'Magento_Customer/js/password-strength-indicator', zxcvbn: 'Magento_Customer/js/zxcvbn', - addressValidation: 'Magento_Customer/js/addressValidation' + addressValidation: 'Magento_Customer/js/addressValidation', + customerDataInvalidationRules: { + websiteRule: 'Magento_Customer/js/invalidation-rules/website-rule' + } } } }; diff --git a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js index f94ba2874ef01..cf7b9928d7d42 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js +++ b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js @@ -9,8 +9,9 @@ define([ 'ko', 'Magento_Customer/js/section-config', 'mage/storage', - 'jquery/jquery-storageapi' -], function ($, _, ko, sectionConfig) { + 'jquery/jquery-storageapi', + 'Magento_Customer/js/invalidation-processor' +], function ($, _, ko, sectionConfig, sectionInvalidator) { 'use strict'; var options, @@ -31,6 +32,7 @@ define([ storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage; /** + * @TODO: move to invalidation rules * @param {Object} invalidateOptions */ invalidateCacheBySessionTimeOut = function (invalidateOptions) { @@ -44,6 +46,7 @@ define([ }; /** + * @TODO: move to invalidation rules * Invalidate Cache By Close Cookie Session */ invalidateCacheByCloseCookieSession = function () { @@ -212,6 +215,8 @@ define([ } } + sectionInvalidator.process(this);//all invalidation rules should be move here + if (!_.isEmpty(privateContent)) { countryData = this.get('directory-data'); diff --git a/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js b/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js new file mode 100644 index 0000000000000..9d92c4a872c63 --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js @@ -0,0 +1,27 @@ +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +define([ + "customerDataInvalidationRules", + "underscore" +], function (invalidationRules, _) { + "use strict"; + + return { + /** + * Process all rules in loop, each rule can invalidate some sections in customer data + * + * @param {Object} customerData + */ + process: function (customerData) { + _.each(invalidationRules, function (rule, ruleName) { + if (!_.isFunction(rule.process)) { + throw new Error("Rule " + ruleName + " should implement invalidationProcessor interface"); + } + + rule.process(customerData); + }); + } + } +}); diff --git a/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js b/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js new file mode 100644 index 0000000000000..4a03320e34244 --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js @@ -0,0 +1,26 @@ +/** + * Copyright © 2013-2017 Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ +define([ + "underscore" +], function (_) { + 'use strict'; + + return { + /** + * Takes website id from current customer data and compare it with current website id + * If customer belongs to another scope, we need to invalidate current section + * + * @param {Object} customerData + */ + process: function (customerData) { + var customer = customerData.get('customer'), + scopeConfig = window.scopeConfig; + + if (scopeConfig && customer && customer.websiteId != scopeConfig.websiteId) { + customerData.invalidate(['customer']); + } + } + } +}); diff --git a/app/code/Magento/Customer/view/frontend/web/js/view/customer.js b/app/code/Magento/Customer/view/frontend/web/js/view/customer.js index d83cf769ccfc2..9b58b4cb18f43 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/view/customer.js +++ b/app/code/Magento/Customer/view/frontend/web/js/view/customer.js @@ -15,7 +15,6 @@ define([ this._super(); this.customer = customerData.get('customer'); - customerData.reload(['customer']); } }); }); diff --git a/app/code/Magento/Store/Block/ScopeProvider.php b/app/code/Magento/Store/Block/ScopeProvider.php new file mode 100644 index 0000000000000..bccad864be9ea --- /dev/null +++ b/app/code/Magento/Store/Block/ScopeProvider.php @@ -0,0 +1,54 @@ +storeManager = $storeManager; + $this->jsonEncoder = $jsonEncoder; + } + + /** + * @inheritdoc + * @return string - Return scope data in Json format + */ + public function getScopeConfig() + { + $scopeData = [ + 'websiteId' => $this->_storeManager->getStore()->getWebsiteId(), + ]; + + return $this->jsonEncoder->encode($scopeData); + } +} diff --git a/app/code/Magento/Store/view/frontend/layout/default.xml b/app/code/Magento/Store/view/frontend/layout/default.xml new file mode 100644 index 0000000000000..d3caaaea80872 --- /dev/null +++ b/app/code/Magento/Store/view/frontend/layout/default.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/app/code/Magento/Store/view/frontend/templates/js/scope-data.phtml b/app/code/Magento/Store/view/frontend/templates/js/scope-data.phtml new file mode 100644 index 0000000000000..895ec106b1169 --- /dev/null +++ b/app/code/Magento/Store/view/frontend/templates/js/scope-data.phtml @@ -0,0 +1,13 @@ + + From 9444eb65f2dbd1bc193170f2ac520e60bd90e0a4 Mon Sep 17 00:00:00 2001 From: Sergii Kovalenko Date: Thu, 2 Mar 2017 17:45:58 +0200 Subject: [PATCH 03/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites --- .../Customer/view/frontend/layout/default.xml | 2 ++ .../view/frontend/requirejs-config.js | 5 +---- .../js/customer-data/invalidation-rules.phtml | 20 ++++++++++++++++++ .../view/frontend/web/js/customer-data.js | 4 ++-- .../frontend/web/js/invalidation-processor.js | 21 +++++++++++++------ .../view/frontend/web/js/section-config.js | 3 ++- 6 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml diff --git a/app/code/Magento/Customer/view/frontend/layout/default.xml b/app/code/Magento/Customer/view/frontend/layout/default.xml index d80391c4973b6..51018a44f6f67 100644 --- a/app/code/Magento/Customer/view/frontend/layout/default.xml +++ b/app/code/Magento/Customer/view/frontend/layout/default.xml @@ -45,6 +45,8 @@ + diff --git a/app/code/Magento/Customer/view/frontend/requirejs-config.js b/app/code/Magento/Customer/view/frontend/requirejs-config.js index c3d49a9e0b98a..99442b69ac04e 100644 --- a/app/code/Magento/Customer/view/frontend/requirejs-config.js +++ b/app/code/Magento/Customer/view/frontend/requirejs-config.js @@ -11,10 +11,7 @@ var config = { changeEmailPassword: 'Magento_Customer/change-email-password', passwordStrengthIndicator: 'Magento_Customer/js/password-strength-indicator', zxcvbn: 'Magento_Customer/js/zxcvbn', - addressValidation: 'Magento_Customer/js/addressValidation', - customerDataInvalidationRules: { - websiteRule: 'Magento_Customer/js/invalidation-rules/website-rule' - } + addressValidation: 'Magento_Customer/js/addressValidation' } } }; diff --git a/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml b/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml new file mode 100644 index 0000000000000..5e8bd4c1dc389 --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml @@ -0,0 +1,20 @@ + + diff --git a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js index cf7b9928d7d42..656795a72bd1a 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js +++ b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js @@ -11,7 +11,7 @@ define([ 'mage/storage', 'jquery/jquery-storageapi', 'Magento_Customer/js/invalidation-processor' -], function ($, _, ko, sectionConfig, sectionInvalidator) { +], function ($, _, ko, sectionConfig) { 'use strict'; var options, @@ -215,7 +215,7 @@ define([ } } - sectionInvalidator.process(this);//all invalidation rules should be move here + //sectionInvalidator().process(this);//all invalidation rules should be move here if (!_.isEmpty(privateContent)) { countryData = this.get('directory-data'); diff --git a/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js b/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js index 9d92c4a872c63..5759270fa1b88 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js +++ b/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js @@ -3,19 +3,28 @@ * See COPYING.txt for license details. */ define([ - "customerDataInvalidationRules", - "underscore" -], function (invalidationRules, _) { + "underscore", + "uiClass", + "require" +], function (_, Class, require) { "use strict"; - return { + return Class.extend({ + defaults: { + invalidationRules: {} + }, + /** * Process all rules in loop, each rule can invalidate some sections in customer data * * @param {Object} customerData */ process: function (customerData) { - _.each(invalidationRules, function (rule, ruleName) { + var rule; + + _.each(this.invalidationRules, function (rulePath, ruleName) { + debugger; + rule = require(rulePath); if (!_.isFunction(rule.process)) { throw new Error("Rule " + ruleName + " should implement invalidationProcessor interface"); } @@ -23,5 +32,5 @@ define([ rule.process(customerData); }); } - } + }); }); diff --git a/app/code/Magento/Customer/view/frontend/web/js/section-config.js b/app/code/Magento/Customer/view/frontend/web/js/section-config.js index f8b6d7c1f83be..62e291c6d24e2 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/section-config.js +++ b/app/code/Magento/Customer/view/frontend/web/js/section-config.js @@ -3,7 +3,7 @@ * See COPYING.txt for license details. */ -define(['underscore'], function (_) { +define(['underscore', 'Magento_Customer/js/invalidation-processor'], function (_, invalidationRules) { 'use strict'; var baseUrls, sections, clientSideSections, canonize; @@ -33,6 +33,7 @@ define(['underscore'], function (_) { * @return {Array} */ getAffectedSections: function (url) { + debugger; var route = canonize(url), actions = _.find(sections, function (val, section) { var matched; From ae8f06b6ed7c3dcd3678854958ab3f4e68fd5779 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Mon, 24 Apr 2017 16:11:49 +0300 Subject: [PATCH 04/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../Customer/Block/CustomerScopeData.php | 47 +++++++++++++++++++ .../Customer/view/frontend/layout/default.xml | 2 +- .../js/customer-data/invalidation-rules.phtml | 15 ++++-- .../view/frontend/web/js/customer-data.js | 3 +- .../frontend/web/js/invalidation-processor.js | 33 +++++++------ .../web/js/invalidation-rules/website-rule.js | 24 ++++++---- .../view/frontend/web/js/section-config.js | 3 +- .../Store/view/frontend/layout/default.xml | 17 ------- .../frontend/templates/js/scope-data.phtml | 13 ----- 9 files changed, 96 insertions(+), 61 deletions(-) create mode 100644 app/code/Magento/Customer/Block/CustomerScopeData.php delete mode 100644 app/code/Magento/Store/view/frontend/layout/default.xml delete mode 100644 app/code/Magento/Store/view/frontend/templates/js/scope-data.phtml diff --git a/app/code/Magento/Customer/Block/CustomerScopeData.php b/app/code/Magento/Customer/Block/CustomerScopeData.php new file mode 100644 index 0000000000000..16e71c7b894dd --- /dev/null +++ b/app/code/Magento/Customer/Block/CustomerScopeData.php @@ -0,0 +1,47 @@ +storeManager = $storeManager; + $this->jsonEncoder = $jsonEncoder; + } + + /** + * @inheritdoc + * @return integer - Return customer website id + */ + public function getWebsiteId() + { + $this->_storeManager->getStore()->getWebsiteId(); + + return (int)$this->_storeManager->getStore()->getWebsiteId(); + } +} \ No newline at end of file diff --git a/app/code/Magento/Customer/view/frontend/layout/default.xml b/app/code/Magento/Customer/view/frontend/layout/default.xml index c92baf0e22eb3..94e46fda194b0 100644 --- a/app/code/Magento/Customer/view/frontend/layout/default.xml +++ b/app/code/Magento/Customer/view/frontend/layout/default.xml @@ -45,7 +45,7 @@ - diff --git a/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml b/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml index 5e8bd4c1dc389..3c1bb4341f406 100644 --- a/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml @@ -5,14 +5,23 @@ */ // @codingStandardsIgnoreFile - +?> + From c563d64ba136dfc94227aec568d689c0d17b448a Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Tue, 25 Apr 2017 16:21:36 +0300 Subject: [PATCH 05/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../Magento/Store/Block/ScopeProvider.php | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 app/code/Magento/Store/Block/ScopeProvider.php diff --git a/app/code/Magento/Store/Block/ScopeProvider.php b/app/code/Magento/Store/Block/ScopeProvider.php deleted file mode 100644 index bccad864be9ea..0000000000000 --- a/app/code/Magento/Store/Block/ScopeProvider.php +++ /dev/null @@ -1,54 +0,0 @@ -storeManager = $storeManager; - $this->jsonEncoder = $jsonEncoder; - } - - /** - * @inheritdoc - * @return string - Return scope data in Json format - */ - public function getScopeConfig() - { - $scopeData = [ - 'websiteId' => $this->_storeManager->getStore()->getWebsiteId(), - ]; - - return $this->jsonEncoder->encode($scopeData); - } -} From c509d13f6efc7199e071baf4a5b3ea0678788ed4 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Wed, 26 Apr 2017 15:56:08 +0300 Subject: [PATCH 06/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../view/frontend/web/js/invalidation-rules/website-rule.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js b/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js index 15babc0ec670a..02b053af3c933 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js +++ b/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js @@ -25,8 +25,7 @@ define([ process: function (customerData) { var customer = customerData.get('customer'); - if (this.scopeConfig && customer() && customer().websiteId != this.scopeConfig.websiteId) { - + if (this.scopeConfig && customer() && customer().websiteId != this.scopeConfig.website_id) { customerData.reload(['customer']); } } From 6d0f3d106c9ac08245df4ec26d99fdfee22cf589 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Wed, 26 Apr 2017 17:42:38 +0300 Subject: [PATCH 07/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../Customer/Block/CustomerScopeData.php | 14 +++- .../Test/Unit/Block/CustomerScopeDataTest.php | 82 +++++++++++++++++++ 2 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php diff --git a/app/code/Magento/Customer/Block/CustomerScopeData.php b/app/code/Magento/Customer/Block/CustomerScopeData.php index 16e71c7b894dd..5fdfe8fa777a9 100644 --- a/app/code/Magento/Customer/Block/CustomerScopeData.php +++ b/app/code/Magento/Customer/Block/CustomerScopeData.php @@ -5,6 +5,11 @@ */ namespace Magento\Customer\Block; +/** + * Class CustomerScopeData provide scope (website, store or store_group) information on front + * Can be used, for example, on store front, in order to determine that private cache invalid for current scope, by comparing + * with appropriate value in store front private cache. + */ class CustomerScopeData extends \Magento\Framework\View\Element\Template { /** @@ -35,13 +40,14 @@ public function __construct( } /** - * @inheritdoc - * @return integer - Return customer website id + * Return id of current website + * + * Can be used when necessary to obtain website id of the current customer. + * + * @return integer */ public function getWebsiteId() { - $this->_storeManager->getStore()->getWebsiteId(); - return (int)$this->_storeManager->getStore()->getWebsiteId(); } } \ No newline at end of file diff --git a/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php b/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php new file mode 100644 index 0000000000000..ddaa739110ddb --- /dev/null +++ b/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php @@ -0,0 +1,82 @@ +contextMock = $this->getMockBuilder(Context::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) + ->getMock(); + + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) + ->getMock(); + + $this->encoderMock = $this->getMockBuilder(EncoderInterface::class) + ->getMock(); + + $this->contextMock->expects($this->once()) + ->method('getStoreManager') + ->willReturn($this->storeManagerMock); + + $this->contextMock->expects($this->once()) + ->method('getScopeConfig') + ->willReturn($this->scopeConfigMock); + + $this->model = new CustomerScopeData( + $this->contextMock, + $this->storeManagerMock, + $this->encoderMock, + [] + ); + } + + public function testGetWebsiteId() + { + $storeId = 1; + + $storeMock = $this->getMockBuilder(StoreInterface::class) + ->setMethods(['getWebsiteId']) + ->getMockForAbstractClass(); + + $storeMock->expects($this->any()) + ->method('getWebsiteId') + ->willReturn($storeId); + + $this->storeManagerMock->expects($this->any()) + ->method('getStore') + ->with(null) + ->willReturn($storeMock); + + $this->assertEquals($storeId, $this->model->getWebsiteId()); + } +} \ No newline at end of file From 14b664e9e750e26d11ab5d7cee21064587ad9304 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Fri, 28 Apr 2017 12:08:26 +0300 Subject: [PATCH 08/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../frontend/web/js/invalidation-processor.js | 21 +++++---- .../js/invalidation-processor.test.js | 46 +++++++++++++++++++ 2 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/invalidation-processor.test.js diff --git a/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js b/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js index 6fb757b682f5b..9677d984e4b8c 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js +++ b/app/code/Magento/Customer/view/frontend/web/js/invalidation-processor.js @@ -8,7 +8,6 @@ define([ 'Magento_Customer/js/customer-data' ], function (_, Element, customerData) { "use strict"; - var invalidationRules; return Element.extend({ initialize: function () { @@ -24,16 +23,18 @@ define([ process: function (customerData) { _.each(this.invalidationRules, function (rule, ruleName) { _.each(rule, function (ruleArgs, rulePath) { - require([rulePath], function (Rule) { - var rule = new Rule(ruleArgs); + require([rulePath], this.initRule.bind(this)); + }, this); + }, this); + }, + + initRule: function () { + var rule = new Rule(ruleArgs); - if (!_.isFunction(rule.process)) { - throw new Error("Rule " + ruleName + " should implement invalidationProcessor interface"); - } - rule.process(customerData); - }); - }); - }); + if (!_.isFunction(rule.process)) { + throw new Error("Rule " + ruleName + " should implement invalidationProcessor interface"); + } + rule.process(customerData); } }); }); diff --git a/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/invalidation-processor.test.js b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/invalidation-processor.test.js new file mode 100644 index 0000000000000..45303b8d456c9 --- /dev/null +++ b/dev/tests/js/jasmine/tests/app/code/Magento/Customer/frontend/js/invalidation-processor.test.js @@ -0,0 +1,46 @@ +define([ + 'squire' +], function (Squire) { + 'use strict'; + + var injector = new Squire(), + mocks = { + 'Magento_Customer/js/customer-data': { + get: jasmine.createSpy().and.returnValue({}) + } + }, + processor; + + beforeEach(function (done) { + injector.mock(mocks); + injector.require(['Magento_Customer/js/invalidation-processor'], function (Constr) { + processor = new Constr({ + name: 'processor' + }); + done(); + }); + }); + + describe('Magento_Customer/js/invalidation-processor', function () { + + describe('"process" method', function () { + it('record status is 1', function () { + var requireTmp = require; + + processor.invalidationRules = { + 'website-rule': { + 'Magento_Customer/js/invalidation-rules/website-rule': { + process: jasmine.createSpy() + } + } + }; + + require = jasmine.createSpy(); + processor.process(); + + expect(require).toHaveBeenCalled(); + require = requireTmp; + }); + }); + }); +}); From a043b9c87755119bd5d9b3232845fdd5ae40c8ec Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Fri, 28 Apr 2017 12:16:04 +0300 Subject: [PATCH 09/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../Magento/Customer/view/frontend/web/js/customer-data.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js index d4258d1f222fa..81ffc12572c06 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/customer-data.js +++ b/app/code/Magento/Customer/view/frontend/web/js/customer-data.js @@ -34,7 +34,6 @@ define([ storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage; /** - * @TODO: move to invalidation rules * @param {Object} invalidateOptions */ invalidateCacheBySessionTimeOut = function (invalidateOptions) { @@ -48,7 +47,6 @@ define([ }; /** - * @TODO: move to invalidation rules * Invalidate Cache By Close Cookie Session */ invalidateCacheByCloseCookieSession = function () { @@ -216,9 +214,6 @@ define([ this.reload(storageInvalidation.keys(), false); } } - - //sectionInvalidator().process(this);//all invalidation rules should be move here - if (!_.isEmpty(privateContent)) { countryData = this.get('directory-data'); From c9dc6c0b9960422fedd1ae7fba2f0b89024d4b85 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Fri, 28 Apr 2017 13:11:27 +0300 Subject: [PATCH 10/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../Magento/Customer/Block/CustomerScopeData.php | 13 ++++++------- .../Test/Unit/Block/CustomerScopeDataTest.php | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Customer/Block/CustomerScopeData.php b/app/code/Magento/Customer/Block/CustomerScopeData.php index 5fdfe8fa777a9..97685d7139e20 100644 --- a/app/code/Magento/Customer/Block/CustomerScopeData.php +++ b/app/code/Magento/Customer/Block/CustomerScopeData.php @@ -7,7 +7,8 @@ /** * Class CustomerScopeData provide scope (website, store or store_group) information on front - * Can be used, for example, on store front, in order to determine that private cache invalid for current scope, by comparing + * Can be used, for example, on store front, in order to determine + * that private cache invalid for current scope, by comparing * with appropriate value in store front private cache. */ class CustomerScopeData extends \Magento\Framework\View\Element\Template @@ -24,18 +25,16 @@ class CustomerScopeData extends \Magento\Framework\View\Element\Template /** * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder * @param array $data */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, - \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Json\EncoderInterface $jsonEncoder, array $data = [] - ) - { + ) { parent::__construct($context, $data); - $this->storeManager = $storeManager; + $this->storeManager = $context->getStoreManager(); $this->jsonEncoder = $jsonEncoder; } @@ -50,4 +49,4 @@ public function getWebsiteId() { return (int)$this->_storeManager->getStore()->getWebsiteId(); } -} \ No newline at end of file +} diff --git a/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php b/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php index ddaa739110ddb..952527b10ad57 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php @@ -44,7 +44,7 @@ protected function setUp() $this->encoderMock = $this->getMockBuilder(EncoderInterface::class) ->getMock(); - $this->contextMock->expects($this->once()) + $this->contextMock->expects($this->exactly(2)) ->method('getStoreManager') ->willReturn($this->storeManagerMock); @@ -54,7 +54,6 @@ protected function setUp() $this->model = new CustomerScopeData( $this->contextMock, - $this->storeManagerMock, $this->encoderMock, [] ); From 5370b887a58ff4337e921a5607b936d3f1fc6d08 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Fri, 28 Apr 2017 13:23:00 +0300 Subject: [PATCH 11/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php b/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php index 952527b10ad57..dcbe4882231ca 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/CustomerScopeDataTest.php @@ -78,4 +78,4 @@ public function testGetWebsiteId() $this->assertEquals($storeId, $this->model->getWebsiteId()); } -} \ No newline at end of file +} From 23d29f9832fc1a33bf2bfffbae131b15ddb561d3 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Fri, 28 Apr 2017 13:39:31 +0300 Subject: [PATCH 12/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../templates/js/customer-data/invalidation-rules.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml b/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml index 3c1bb4341f406..ada96e90be7d1 100644 --- a/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/js/customer-data/invalidation-rules.phtml @@ -1,6 +1,6 @@ Date: Mon, 8 May 2017 11:21:48 +0300 Subject: [PATCH 13/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../view/frontend/web/js/invalidation-rules/website-rule.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js b/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js index 02b053af3c933..7ace530d8cba8 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js +++ b/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js @@ -13,9 +13,6 @@ define([ scopeConfig: {} }, - initialize: function () { - this._super(); - }, /** * Takes website id from current customer data and compare it with current website id * If customer belongs to another scope, we need to invalidate current section From 7eb51180a1bf460e1bba1205e07061f8dad112e0 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Mon, 8 May 2017 12:03:11 +0300 Subject: [PATCH 14/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- app/code/Magento/Customer/Block/CustomerScopeData.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Customer/Block/CustomerScopeData.php b/app/code/Magento/Customer/Block/CustomerScopeData.php index 97685d7139e20..244437e870b98 100644 --- a/app/code/Magento/Customer/Block/CustomerScopeData.php +++ b/app/code/Magento/Customer/Block/CustomerScopeData.php @@ -10,6 +10,7 @@ * Can be used, for example, on store front, in order to determine * that private cache invalid for current scope, by comparing * with appropriate value in store front private cache. + * @api */ class CustomerScopeData extends \Magento\Framework\View\Element\Template { From 0cef2c8c3a4693eeee88c6db003f3fb424801041 Mon Sep 17 00:00:00 2001 From: Oleksandr Osadchyi Date: Wed, 24 May 2017 10:47:52 +0300 Subject: [PATCH 15/59] MAGETWO-59135: [Github] Customer session is shared for different customers on two websites #4842 #6468 --- .../view/frontend/web/js/invalidation-rules/website-rule.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js b/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js index 7ace530d8cba8..02b053af3c933 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js +++ b/app/code/Magento/Customer/view/frontend/web/js/invalidation-rules/website-rule.js @@ -13,6 +13,9 @@ define([ scopeConfig: {} }, + initialize: function () { + this._super(); + }, /** * Takes website id from current customer data and compare it with current website id * If customer belongs to another scope, we need to invalidate current section From 8aec37b56c546e0dca6a15b371a903aa83475a7c Mon Sep 17 00:00:00 2001 From: Volodymyr Sevostianov Date: Thu, 25 May 2017 19:09:16 +0300 Subject: [PATCH 16/59] MAGETWO-67623: Customer Segment - Multiple Select Attribute: MySQL Query Issue --- .../Customer/Test/Handler/Customer/Webapi.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Webapi.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Webapi.php index e36a6a8615cf8..4c6279c838191 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Webapi.php +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Handler/Customer/Webapi.php @@ -70,6 +70,7 @@ class Webapi extends AbstractWebapi implements CustomerInterface 'default_shipping', 'addresses', 'disable_auto_group_change', + 'custom_attribute', ]; /** @@ -115,6 +116,29 @@ protected function prepareData(Customer $customer) unset($data['customer']['password_confirmation']); $data = $this->prepareAddressData($data); $data = $this->prepareExtensionAttributes($data); + $data = $this->prepareCustomAttributes($data); + return $data; + } + + /** + * Prepare Custom Attributes. + * + * @param array $data + * @return array + */ + protected function prepareCustomAttributes(array $data) + { + if (isset($data['customer']['custom_attribute'])) { + $data['customer']['custom_attribute']['attribute_code'] = $data['customer']['custom_attribute']['code']; + unset($data['customer']['custom_attribute']['code']); + if (is_array($data['customer']['custom_attribute']['value'])) { + $data['customer']['custom_attribute']['value'] = + implode(',', $data['customer']['custom_attribute']['value']); + } + $data['customer']['custom_attributes'][0] = $data['customer']['custom_attribute']; + unset($data['customer']['custom_attribute']); + } + return $data; } From 90a027ec2635115f2138410e527e6a634c0a4518 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Thu, 1 Jun 2017 18:28:47 +0300 Subject: [PATCH 17/59] MAGETWO-47607: [Github] Sitemap generation in wrong folder when vhost is connected to pub folder --- .../Model/Config/Backend/Admin/Robots.php | 3 + .../Magento/Robots/Controller/Index/Index.php | 62 +++++++++++++++ app/code/Magento/Robots/Controller/Router.php | 77 +++++++++++++++++++ app/code/Magento/Robots/LICENSE.txt | 48 ++++++++++++ app/code/Magento/Robots/LICENSE_AFL.txt | 48 ++++++++++++ app/code/Magento/Robots/README.md | 1 + app/code/Magento/Robots/composer.json | 22 ++++++ app/code/Magento/Robots/etc/frontend/di.xml | 21 +++++ .../Magento/Robots/etc/frontend/routes.xml | 15 ++++ app/code/Magento/Robots/etc/module.xml | 12 +++ app/code/Magento/Robots/registration.php | 11 +++ .../Model/Design/Config/DataProvider.php | 41 ++++++++++ app/code/Magento/Theme/etc/di.xml | 1 - .../ui_component/design_config_form.xml | 3 + 14 files changed, 364 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Robots/Controller/Index/Index.php create mode 100644 app/code/Magento/Robots/Controller/Router.php create mode 100644 app/code/Magento/Robots/LICENSE.txt create mode 100644 app/code/Magento/Robots/LICENSE_AFL.txt create mode 100644 app/code/Magento/Robots/README.md create mode 100644 app/code/Magento/Robots/composer.json create mode 100644 app/code/Magento/Robots/etc/frontend/di.xml create mode 100644 app/code/Magento/Robots/etc/frontend/routes.xml create mode 100644 app/code/Magento/Robots/etc/module.xml create mode 100644 app/code/Magento/Robots/registration.php diff --git a/app/code/Magento/Config/Model/Config/Backend/Admin/Robots.php b/app/code/Magento/Config/Model/Config/Backend/Admin/Robots.php index b8cd9a47476d5..a98e76285ce08 100644 --- a/app/code/Magento/Config/Model/Config/Backend/Admin/Robots.php +++ b/app/code/Magento/Config/Model/Config/Backend/Admin/Robots.php @@ -12,6 +12,9 @@ use Magento\Config\Model\Config\Reader\Source\Deployed\DocumentRoot; use Magento\Framework\App\ObjectManager; +/** + * @deprecated robots.txt file is no longer stored in filesystem. It generates as response on request. + */ class Robots extends \Magento\Framework\App\Config\Value { /** diff --git a/app/code/Magento/Robots/Controller/Index/Index.php b/app/code/Magento/Robots/Controller/Index/Index.php new file mode 100644 index 0000000000000..a4d32417698c4 --- /dev/null +++ b/app/code/Magento/Robots/Controller/Index/Index.php @@ -0,0 +1,62 @@ +resultRawFactory = $resultRawFactory; + $this->scopeConfig = $scopeConfig; + + parent::__construct($context); + } + + /** + * Generates robots.txt data and returns it as result + * + * @return \Magento\Framework\Controller\Result\Raw + */ + public function execute() + { + $content = $this->scopeConfig->getValue( + 'design/search_engine_robots/custom_instructions', + \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE + ); + + /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */ + $resultRaw = $this->resultRawFactory->create(); + $resultRaw->setContents($content); + return $resultRaw; + } +} diff --git a/app/code/Magento/Robots/Controller/Router.php b/app/code/Magento/Robots/Controller/Router.php new file mode 100644 index 0000000000000..f2c5f8528bd00 --- /dev/null +++ b/app/code/Magento/Robots/Controller/Router.php @@ -0,0 +1,77 @@ +actionFactory = $actionFactory; + $this->actionList = $actionList; + $this->routeConfig = $routeConfig; + } + + /** + * Checks if robots.txt file was requested and returns instance of matched application action class + * + * @param RequestInterface $request + * @return \Magento\Framework\App\ActionInterface|null + */ + public function match(RequestInterface $request) + { + $identifier = trim($request->getPathInfo(), '/'); + if ($identifier !== 'robots.txt') { + return null; + } + + $modules = $this->routeConfig->getModulesByFrontName('robots'); + if (empty($modules)) { + return null; + } + + $request->setModuleName('robots'); + $request->setControllerName('index'); + $request->setActionName('index'); + + $actionClassName = $this->actionList->get($modules[0], null, 'index', 'index'); + $actionInstance = $this->actionFactory->create($actionClassName); + return $actionInstance; + } +} diff --git a/app/code/Magento/Robots/LICENSE.txt b/app/code/Magento/Robots/LICENSE.txt new file mode 100644 index 0000000000000..49525fd99da9c --- /dev/null +++ b/app/code/Magento/Robots/LICENSE.txt @@ -0,0 +1,48 @@ + +Open Software License ("OSL") v. 3.0 + +This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Open Software License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/Robots/LICENSE_AFL.txt b/app/code/Magento/Robots/LICENSE_AFL.txt new file mode 100644 index 0000000000000..f39d641b18a19 --- /dev/null +++ b/app/code/Magento/Robots/LICENSE_AFL.txt @@ -0,0 +1,48 @@ + +Academic Free License ("AFL") v. 3.0 + +This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: + +Licensed under the Academic Free License version 3.0 + + 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: + + 1. to reproduce the Original Work in copies, either alone or as part of a collective work; + + 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; + + 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; + + 4. to perform the Original Work publicly; and + + 5. to display the Original Work publicly. + + 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. + + 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. + + 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. + + 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). + + 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. + + 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. + + 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. + + 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). + + 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. + + 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. + + 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. + + 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + + 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + + 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. + + 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/Robots/README.md b/app/code/Magento/Robots/README.md new file mode 100644 index 0000000000000..f86390d507048 --- /dev/null +++ b/app/code/Magento/Robots/README.md @@ -0,0 +1 @@ +The Robots module contains router to match application action class for robots.txt requests and realizes the possibility of obtaining content of robots.txt file depending on the current website. \ No newline at end of file diff --git a/app/code/Magento/Robots/composer.json b/app/code/Magento/Robots/composer.json new file mode 100644 index 0000000000000..2cf81fbb7af2d --- /dev/null +++ b/app/code/Magento/Robots/composer.json @@ -0,0 +1,22 @@ +{ + "name": "magento/module-robots", + "description": "N/A", + "require": { + "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", + "magento/framework": "100.2.*" + }, + "type": "magento2-module", + "version": "100.2.0-dev", + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\Robots\\": "" + } + } +} diff --git a/app/code/Magento/Robots/etc/frontend/di.xml b/app/code/Magento/Robots/etc/frontend/di.xml new file mode 100644 index 0000000000000..5670ee637beeb --- /dev/null +++ b/app/code/Magento/Robots/etc/frontend/di.xml @@ -0,0 +1,21 @@ + + + + + + + + Magento\Robots\Controller\Router + false + 10 + + + + + diff --git a/app/code/Magento/Robots/etc/frontend/routes.xml b/app/code/Magento/Robots/etc/frontend/routes.xml new file mode 100644 index 0000000000000..a30cbe320f673 --- /dev/null +++ b/app/code/Magento/Robots/etc/frontend/routes.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/app/code/Magento/Robots/etc/module.xml b/app/code/Magento/Robots/etc/module.xml new file mode 100644 index 0000000000000..9773aeff28545 --- /dev/null +++ b/app/code/Magento/Robots/etc/module.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/app/code/Magento/Robots/registration.php b/app/code/Magento/Robots/registration.php new file mode 100644 index 0000000000000..0e062e1139461 --- /dev/null +++ b/app/code/Magento/Robots/registration.php @@ -0,0 +1,11 @@ +getSearchEngineRobotsMetadata( + $scope, + $meta['other_settings']['children']['search_engine_robots']['children'] + ) + ); + } + return $meta; } + /** + * Retrieve modified Search Engine Robots metadata + * + * Disable Search Engine Robots fields in case when current scope is 'stores'. + * + * @param string $scope + * @param array $fields + * @return array + */ + private function getSearchEngineRobotsMetadata($scope, array $fields = []) + { + if ($scope == \Magento\Store\Model\ScopeInterface::SCOPE_STORES) { + $resetToDefaultsData = [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'disabled' => true, + 'is_disable_inheritance' => true, + ], + ], + ], + ]; + $fields = array_merge($fields, ['reset_to_defaults' => $resetToDefaultsData]); + foreach ($fields as &$field) { + $field['arguments']['data']['config']['disabled'] = true; + $field['arguments']['data']['config']['is_disable_inheritance'] = true; + } + } + return $fields; + } + /** * @deprecated * @return ScopeCodeResolver diff --git a/app/code/Magento/Theme/etc/di.xml b/app/code/Magento/Theme/etc/di.xml index 813a8b858b99f..279309b5d0495 100644 --- a/app/code/Magento/Theme/etc/di.xml +++ b/app/code/Magento/Theme/etc/di.xml @@ -219,7 +219,6 @@ design/search_engine_robots/custom_instructions - Magento\Config\Model\Config\Backend\Admin\Robots other_settings/search_engine_robots diff --git a/app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml b/app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml index c89c25e1a324a..aaf5ecf500a53 100644 --- a/app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml +++ b/app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml @@ -247,6 +247,7 @@ text default_robots + [WEBSITE]