Skip to content

Commit

Permalink
Merge pull request #1230 from magento-south/BUGS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
slavvka authored Jun 29, 2017
2 parents 3993417 + d6b7c51 commit d902e08
Show file tree
Hide file tree
Showing 56 changed files with 2,253 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Magento\Framework\App\ObjectManager;

/**
* @api
* @deprecated robots.txt file is no longer stored in filesystem. It generates as response on request.
*/
class Robots extends \Magento\Framework\App\Config\Value
{
Expand Down
53 changes: 53 additions & 0 deletions app/code/Magento/Customer/Block/CustomerScopeData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
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.
* @api
*/
class CustomerScopeData extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Framework\View\Element\Template\Context
*/
private $storeManager;

/**
* @var \Magento\Framework\Json\EncoderInterface
*/
private $jsonEncoder;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
array $data = []
) {
parent::__construct($context, $data);
$this->storeManager = $context->getStoreManager();
$this->jsonEncoder = $jsonEncoder;
}

/**
* Return id of current website
*
* Can be used when necessary to obtain website id of the current customer.
*
* @return integer
*/
public function getWebsiteId()
{
return (int)$this->_storeManager->getStore()->getWebsiteId();
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/Customer/CustomerData/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class Customer implements SectionSourceInterface
*/
protected $currentCustomer;

/**
* @var View
*/
private $customerViewHelper;

/**
* @param CurrentCustomer $currentCustomer
* @param View $customerViewHelper
Expand All @@ -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(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Test\Unit\Block;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Customer\Block\CustomerScopeData;
use Magento\Framework\Json\EncoderInterface;

class CustomerScopeDataTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\Customer\Block\CustomerScopeData */
private $model;

/** @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject */
private $contextMock;

/** @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
private $storeManagerMock;

/** @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
private $scopeConfigMock;

/** @var \Magento\Framework\Json\EncoderInterface|\PHPUnit_Framework_MockObject_MockObject */
private $encoderMock;

protected function setUp()
{
$this->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->exactly(2))
->method('getStoreManager')
->willReturn($this->storeManagerMock);

$this->contextMock->expects($this->once())
->method('getScopeConfig')
->willReturn($this->scopeConfigMock);

$this->model = new CustomerScopeData(
$this->contextMock,
$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());
}
}
2 changes: 2 additions & 0 deletions app/code/Magento/Customer/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<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"/>
</referenceContainer>
</body>
</page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile
?>
<?php
/* @var $block \Magento\Customer\Block\CustomerScopeData */
?>
<script type="text/x-magento-init">
<?php
/* @noEscape */
echo \Zend_Json::encode([
'*' => ['Magento_Customer/js/invalidation-processor' => [
'invalidationRules' => [
'website-rule' => [
'Magento_Customer/js/invalidation-rules/website-rule' => [
'scopeConfig' => [
'websiteId' => $block->getWebsiteId(),
]
]
]
]
]],
]);
?>
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'underscore',
'uiElement',
'Magento_Customer/js/customer-data'
], function (_, Element, customerData) {
'use strict';

return Element.extend({
/**
* Initialize object
*/
initialize: function () {
this._super();
this.process(customerData);
},

/**
* Process all rules in loop, each rule can invalidate some sections in customer data
*
* @param {Object} customerDataObject
*/
process: function (customerDataObject) {
_.each(this.invalidationRules, function (rule, ruleName) {
_.each(rule, function (ruleArgs, rulePath) {
require([rulePath], function (Rule) {
var currentRule = new Rule(ruleArgs);

if (!_.isFunction(currentRule.process)) {
throw new Error('Rule ' + ruleName + ' should implement invalidationProcessor interface');
}
currentRule.process(customerDataObject);
});
});
});
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'uiClass'
], function (Element) {
'use strict';

return Element.extend({

defaults: {
scopeConfig: {}
},

/**
* 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');

if (this.scopeConfig && customer() &&
~~customer().websiteId !== ~~this.scopeConfig.websiteId && ~~customer().websiteId !== 0) {
customerData.reload(['customer']);
}
}
});
});
72 changes: 72 additions & 0 deletions app/code/Magento/Robots/Block/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Robots\Block;

use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Framework\View\Element\Context;
use Magento\Robots\Model\Config\Value;
use Magento\Robots\Model\Robots;
use Magento\Store\Model\StoreResolver;

/**
* Robots Block Class.
* Prepares base content for robots.txt and implements Page Cache functionality.
*
* @api
*/
class Data extends AbstractBlock implements IdentityInterface
{
/**
* @var Robots
*/
private $robots;

/**
* @var StoreResolver
*/
private $storeResolver;

/**
* @param Context $context
* @param Robots $robots
* @param StoreResolver $storeResolver
* @param array $data
*/
public function __construct(
Context $context,
Robots $robots,
StoreResolver $storeResolver,
array $data = []
) {
$this->robots = $robots;
$this->storeResolver = $storeResolver;

parent::__construct($context, $data);
}

/**
* Retrieve base content for robots.txt file
*
* @return string
*/
protected function _toHtml()
{
return $this->robots->getData() . PHP_EOL;
}

/**
* Get unique page cache identities
*
* @return array
*/
public function getIdentities()
{
return [
Value::CACHE_TAG . '_' . $this->storeResolver->getCurrentStoreId(),
];
}
}
Loading

0 comments on commit d902e08

Please sign in to comment.