Skip to content

Commit d902e08

Browse files
authored
Merge pull request #1230 from magento-south/BUGS
Bug fixes: - MAGETWO-59135 [Github] Customer session is shared for different customers on two websites #4842 #6468 - MAGETWO-67623 [M2EE 2.0.10] - Customer Segment - Multiple Select Attribute: MySQL Query Issue - MAGETWO-47607 [Github] Sitemap generation in wrong folder when vhost is connected to pub folder - MAGETWO-63159 Content staging value for fields are not saved in database - MAGETWO-62975 [FT] Functional test Magento\Customer\Test\TestCase\RegisterCustomerFrontendEntityTest is failed - MAGETWO-56156 [GITHUB] Using API cannot create Tax Rate with a zero rate #4873
2 parents 3993417 + d6b7c51 commit d902e08

File tree

56 files changed

+2253
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2253
-24
lines changed

app/code/Magento/Config/Model/Config/Backend/Admin/Robots.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\App\ObjectManager;
1414

1515
/**
16-
* @api
16+
* @deprecated robots.txt file is no longer stored in filesystem. It generates as response on request.
1717
*/
1818
class Robots extends \Magento\Framework\App\Config\Value
1919
{
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Block;
7+
8+
/**
9+
* Class CustomerScopeData provide scope (website, store or store_group) information on front
10+
* Can be used, for example, on store front, in order to determine
11+
* that private cache invalid for current scope, by comparing
12+
* with appropriate value in store front private cache.
13+
* @api
14+
*/
15+
class CustomerScopeData extends \Magento\Framework\View\Element\Template
16+
{
17+
/**
18+
* @var \Magento\Framework\View\Element\Template\Context
19+
*/
20+
private $storeManager;
21+
22+
/**
23+
* @var \Magento\Framework\Json\EncoderInterface
24+
*/
25+
private $jsonEncoder;
26+
27+
/**
28+
* @param \Magento\Framework\View\Element\Template\Context $context
29+
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
30+
* @param array $data
31+
*/
32+
public function __construct(
33+
\Magento\Framework\View\Element\Template\Context $context,
34+
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
35+
array $data = []
36+
) {
37+
parent::__construct($context, $data);
38+
$this->storeManager = $context->getStoreManager();
39+
$this->jsonEncoder = $jsonEncoder;
40+
}
41+
42+
/**
43+
* Return id of current website
44+
*
45+
* Can be used when necessary to obtain website id of the current customer.
46+
*
47+
* @return integer
48+
*/
49+
public function getWebsiteId()
50+
{
51+
return (int)$this->_storeManager->getStore()->getWebsiteId();
52+
}
53+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class Customer implements SectionSourceInterface
1919
*/
2020
protected $currentCustomer;
2121

22+
/**
23+
* @var View
24+
*/
25+
private $customerViewHelper;
26+
2227
/**
2328
* @param CurrentCustomer $currentCustomer
2429
* @param View $customerViewHelper
@@ -39,10 +44,12 @@ public function getSectionData()
3944
if (!$this->currentCustomer->getCustomerId()) {
4045
return [];
4146
}
47+
4248
$customer = $this->currentCustomer->getCustomer();
4349
return [
4450
'fullname' => $this->customerViewHelper->getCustomerName($customer),
4551
'firstname' => $customer->getFirstname(),
52+
'websiteId' => $customer->getWebsiteId(),
4653
];
4754
}
4855
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Block;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\View\Element\Template\Context;
10+
use Magento\Store\Api\Data\StoreInterface;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Customer\Block\CustomerScopeData;
13+
use Magento\Framework\Json\EncoderInterface;
14+
15+
class CustomerScopeDataTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/** @var \Magento\Customer\Block\CustomerScopeData */
18+
private $model;
19+
20+
/** @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject */
21+
private $contextMock;
22+
23+
/** @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
24+
private $storeManagerMock;
25+
26+
/** @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
27+
private $scopeConfigMock;
28+
29+
/** @var \Magento\Framework\Json\EncoderInterface|\PHPUnit_Framework_MockObject_MockObject */
30+
private $encoderMock;
31+
32+
protected function setUp()
33+
{
34+
$this->contextMock = $this->getMockBuilder(Context::class)
35+
->disableOriginalConstructor()
36+
->getMock();
37+
38+
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
39+
->getMock();
40+
41+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
42+
->getMock();
43+
44+
$this->encoderMock = $this->getMockBuilder(EncoderInterface::class)
45+
->getMock();
46+
47+
$this->contextMock->expects($this->exactly(2))
48+
->method('getStoreManager')
49+
->willReturn($this->storeManagerMock);
50+
51+
$this->contextMock->expects($this->once())
52+
->method('getScopeConfig')
53+
->willReturn($this->scopeConfigMock);
54+
55+
$this->model = new CustomerScopeData(
56+
$this->contextMock,
57+
$this->encoderMock,
58+
[]
59+
);
60+
}
61+
62+
public function testGetWebsiteId()
63+
{
64+
$storeId = 1;
65+
66+
$storeMock = $this->getMockBuilder(StoreInterface::class)
67+
->setMethods(['getWebsiteId'])
68+
->getMockForAbstractClass();
69+
70+
$storeMock->expects($this->any())
71+
->method('getWebsiteId')
72+
->willReturn($storeId);
73+
74+
$this->storeManagerMock->expects($this->any())
75+
->method('getStore')
76+
->with(null)
77+
->willReturn($storeMock);
78+
79+
$this->assertEquals($storeId, $this->model->getWebsiteId());
80+
}
81+
}

app/code/Magento/Customer/view/frontend/layout/default.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
<block name="customer.customer.data"
4646
class="Magento\Customer\Block\CustomerData"
4747
template="Magento_Customer::js/customer-data.phtml"/>
48+
<block name="customer.data.invalidation.rules" class="Magento\Customer\Block\CustomerScopeData"
49+
template="Magento_Customer::js/customer-data/invalidation-rules.phtml"/>
4850
</referenceContainer>
4951
</body>
5052
</page>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
// @codingStandardsIgnoreFile
8+
?>
9+
<?php
10+
/* @var $block \Magento\Customer\Block\CustomerScopeData */
11+
?>
12+
<script type="text/x-magento-init">
13+
<?php
14+
/* @noEscape */
15+
echo \Zend_Json::encode([
16+
'*' => ['Magento_Customer/js/invalidation-processor' => [
17+
'invalidationRules' => [
18+
'website-rule' => [
19+
'Magento_Customer/js/invalidation-rules/website-rule' => [
20+
'scopeConfig' => [
21+
'websiteId' => $block->getWebsiteId(),
22+
]
23+
]
24+
]
25+
]
26+
]],
27+
]);
28+
?>
29+
</script>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'underscore',
7+
'uiElement',
8+
'Magento_Customer/js/customer-data'
9+
], function (_, Element, customerData) {
10+
'use strict';
11+
12+
return Element.extend({
13+
/**
14+
* Initialize object
15+
*/
16+
initialize: function () {
17+
this._super();
18+
this.process(customerData);
19+
},
20+
21+
/**
22+
* Process all rules in loop, each rule can invalidate some sections in customer data
23+
*
24+
* @param {Object} customerDataObject
25+
*/
26+
process: function (customerDataObject) {
27+
_.each(this.invalidationRules, function (rule, ruleName) {
28+
_.each(rule, function (ruleArgs, rulePath) {
29+
require([rulePath], function (Rule) {
30+
var currentRule = new Rule(ruleArgs);
31+
32+
if (!_.isFunction(currentRule.process)) {
33+
throw new Error('Rule ' + ruleName + ' should implement invalidationProcessor interface');
34+
}
35+
currentRule.process(customerDataObject);
36+
});
37+
});
38+
});
39+
}
40+
});
41+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'uiClass'
7+
], function (Element) {
8+
'use strict';
9+
10+
return Element.extend({
11+
12+
defaults: {
13+
scopeConfig: {}
14+
},
15+
16+
/**
17+
* Takes website id from current customer data and compare it with current website id
18+
* If customer belongs to another scope, we need to invalidate current section
19+
*
20+
* @param {Object} customerData
21+
*/
22+
process: function (customerData) {
23+
var customer = customerData.get('customer');
24+
25+
if (this.scopeConfig && customer() &&
26+
~~customer().websiteId !== ~~this.scopeConfig.websiteId && ~~customer().websiteId !== 0) {
27+
customerData.reload(['customer']);
28+
}
29+
}
30+
});
31+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Robots\Block;
7+
8+
use Magento\Framework\DataObject\IdentityInterface;
9+
use Magento\Framework\View\Element\AbstractBlock;
10+
use Magento\Framework\View\Element\Context;
11+
use Magento\Robots\Model\Config\Value;
12+
use Magento\Robots\Model\Robots;
13+
use Magento\Store\Model\StoreResolver;
14+
15+
/**
16+
* Robots Block Class.
17+
* Prepares base content for robots.txt and implements Page Cache functionality.
18+
*
19+
* @api
20+
*/
21+
class Data extends AbstractBlock implements IdentityInterface
22+
{
23+
/**
24+
* @var Robots
25+
*/
26+
private $robots;
27+
28+
/**
29+
* @var StoreResolver
30+
*/
31+
private $storeResolver;
32+
33+
/**
34+
* @param Context $context
35+
* @param Robots $robots
36+
* @param StoreResolver $storeResolver
37+
* @param array $data
38+
*/
39+
public function __construct(
40+
Context $context,
41+
Robots $robots,
42+
StoreResolver $storeResolver,
43+
array $data = []
44+
) {
45+
$this->robots = $robots;
46+
$this->storeResolver = $storeResolver;
47+
48+
parent::__construct($context, $data);
49+
}
50+
51+
/**
52+
* Retrieve base content for robots.txt file
53+
*
54+
* @return string
55+
*/
56+
protected function _toHtml()
57+
{
58+
return $this->robots->getData() . PHP_EOL;
59+
}
60+
61+
/**
62+
* Get unique page cache identities
63+
*
64+
* @return array
65+
*/
66+
public function getIdentities()
67+
{
68+
return [
69+
Value::CACHE_TAG . '_' . $this->storeResolver->getCurrentStoreId(),
70+
];
71+
}
72+
}

0 commit comments

Comments
 (0)