Skip to content

Commit 1a4aa5b

Browse files
authored
Merge pull request #1281 from magento-south/PRS
Fixed isssues: - MAGETWO-70299 Error during Sample Data deploying using " auto_increment_increment = 3" as Mysql option (2.2) - MAGETWO-54708 bin/magento setup:performance:generate-fixtures fails if you have mysql auto_increment > 1 - MAGETWO-62637 Attribute "product status" has website scope but could be different per store view - MAGETWO-70327 Customer admin grid incorrectly filters by Date of Birth field
2 parents aa4ae30 + 5a01fe1 commit 1a4aa5b

File tree

30 files changed

+2942
-191
lines changed

30 files changed

+2942
-191
lines changed

app/code/Magento/Braintree/Test/Unit/Ui/Component/Report/Filters/Type/DateRangeTest.php

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,14 @@ protected function setUp()
6969
->disableOriginalConstructor()
7070
->getMock();
7171

72-
$this->dataProviderMock = $this->getMockForAbstractClass(DataProviderInterface::class);
73-
7472
$this->contextMock->expects($this->any())
7573
->method('getNamespace')
7674
->willReturn(DateRange::NAME);
7775
$this->contextMock->expects($this->any())
7876
->method('addComponentDefinition')
7977
->with(DateRange::NAME, ['extends' => DateRange::NAME]);
8078

81-
$this->contextMock->expects($this->any())
82-
->method('getDataProvider')
83-
->willReturn($this->dataProviderMock);
79+
$this->dataProviderMock = $this->getMockForAbstractClass(DataProviderInterface::class);
8480
}
8581

8682
/**
@@ -95,16 +91,21 @@ protected function setUp()
9591
*/
9692
public function testPrepare($name, $filterData, $expectedCondition)
9793
{
98-
$this->contextMock->expects($this->any())
99-
->method('getFiltersParams')
100-
->willReturn($filterData);
101-
94+
/** @var FormDate PHPUnit_Framework_MockObject_MockObject|$uiComponent */
10295
$uiComponent = $this->getMockBuilder(FormDate::class)->disableOriginalConstructor()->getMock();
10396

10497
$uiComponent->expects($this->any())
10598
->method('getContext')
10699
->willReturn($this->contextMock);
107100

101+
$this->contextMock->expects($this->any())
102+
->method('getFiltersParams')
103+
->willReturn($filterData);
104+
105+
$this->contextMock->expects($this->any())
106+
->method('getDataProvider')
107+
->willReturn($this->dataProviderMock);
108+
108109
if ($expectedCondition !== null) {
109110
if (is_string($filterData[$name])) {
110111
$uiComponent->expects(static::once())
@@ -115,11 +116,11 @@ public function testPrepare($name, $filterData, $expectedCondition)
115116
$uiComponent->method('convertDate')
116117
->willReturnMap([
117118
[
118-
$filterData[$name]['from'],
119+
$filterData[$name]['from'], 0, 0, 0, true,
119120
new \DateTime($filterData[$name]['from'], new \DateTimeZone('UTC'))
120121
],
121122
[
122-
$filterData[$name]['to'],
123+
$filterData[$name]['to'], 23, 59, 59, true,
123124
new \DateTime($filterData[$name]['to'] . ' 23:59:00', new \DateTimeZone('UTC'))
124125
],
125126
]);
@@ -158,23 +159,6 @@ public function testPrepare($name, $filterData, $expectedCondition)
158159
->with($filterMock);
159160
break;
160161
}
161-
} else {
162-
$uiComponent->method('convertDate')
163-
->willReturnMap([
164-
[
165-
$filterData[$name]['from'],
166-
new \DateTime($filterData[$name]['from'], new \DateTimeZone('UTC'))
167-
],
168-
[
169-
$filterData[$name]['to'],
170-
new \DateTime($filterData[$name]['to'] . ' 23:59:00', new \DateTimeZone('UTC'))
171-
],
172-
]);
173-
174-
$filterMock = $this->getFilterMockWithoutExpectedCondition();
175-
$this->dataProviderMock->expects(static::exactly(2))
176-
->method('addFilter')
177-
->with($filterMock);
178162
}
179163

180164
$this->uiComponentFactory->expects($this->any())
@@ -226,31 +210,6 @@ private function getFilterMock($name, $expectedType, $expectedDate, &$i)
226210
return $filterMock;
227211
}
228212

229-
/**
230-
* Gets Filter mock without expected condition
231-
*
232-
* @return Filter|\PHPUnit_Framework_MockObject_MockObject
233-
*/
234-
private function getFilterMockWithoutExpectedCondition()
235-
{
236-
$this->filterBuilderMock->expects(static::exactly(2))
237-
->method('setConditionType')
238-
->willReturnSelf();
239-
$this->filterBuilderMock->expects(static::exactly(2))
240-
->method('setField')
241-
->willReturnSelf();
242-
$this->filterBuilderMock->expects(static::exactly(2))
243-
->method('setValue')
244-
->willReturnSelf();
245-
246-
$filterMock = $this->getMock(Filter::class);
247-
$this->filterBuilderMock->expects(static::exactly(2))
248-
->method('create')
249-
->willReturn($filterMock);
250-
251-
return $filterMock;
252-
}
253-
254213
/**
255214
* @return array
256215
*/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Cron;
8+
9+
use Magento\Catalog\Model\ResourceModel\Attribute\WebsiteAttributesSynchronizer;
10+
11+
/**
12+
* Class SynchronizeWebsiteAttributes
13+
* @package Magento\Catalog\Cron
14+
*/
15+
class SynchronizeWebsiteAttributes
16+
{
17+
/**
18+
* @var WebsiteAttributesSynchronizer
19+
*/
20+
private $synchronizer;
21+
22+
/**
23+
* SynchronizeWebsiteAttributes constructor.
24+
* @param WebsiteAttributesSynchronizer $synchronizer
25+
*/
26+
public function __construct(WebsiteAttributesSynchronizer $synchronizer)
27+
{
28+
$this->synchronizer = $synchronizer;
29+
}
30+
31+
/**
32+
* Synchronizes website attribute values if needed
33+
* @return void
34+
*/
35+
public function execute()
36+
{
37+
if ($this->synchronizer->isSynchronizationRequired()) {
38+
$this->synchronizer->synchronize();
39+
}
40+
}
41+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model\ResourceModel\Attribute;
8+
9+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
10+
use Magento\Framework\EntityManager\EntityMetadataInterface;
11+
use Magento\Store\Api\Data\StoreInterface;
12+
use Magento\Store\Model\Store;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute as CatalogEavAttribute;
15+
use Magento\Store\Model\Website;
16+
use Magento\Framework\Model\Entity\ScopeInterface;
17+
18+
/**
19+
* Builds scope-related conditions for catalog attributes
20+
*
21+
* Class ConditionBuilder
22+
* @package Magento\Catalog\Model\ResourceModel\Attribute
23+
*/
24+
class ConditionBuilder
25+
{
26+
/**
27+
* @var StoreManagerInterface
28+
*/
29+
private $storeManager;
30+
31+
/**
32+
* ConditionBuilder constructor
33+
* @param StoreManagerInterface $storeManager
34+
*/
35+
public function __construct(StoreManagerInterface $storeManager)
36+
{
37+
$this->storeManager = $storeManager;
38+
}
39+
40+
/**
41+
* Returns conditions for existing attribute actions (update/delete) if attribute scope is "website"
42+
*
43+
* @param AbstractAttribute $attribute
44+
* @param EntityMetadataInterface $metadata
45+
* @param ScopeInterface[] $scopes
46+
* @param string $linkFieldValue
47+
* @return array
48+
*/
49+
public function buildExistingAttributeWebsiteScope(
50+
AbstractAttribute $attribute,
51+
EntityMetadataInterface $metadata,
52+
array $scopes,
53+
$linkFieldValue
54+
) {
55+
$website = $this->getWebsiteForWebsiteScope($scopes);
56+
if (!$website) {
57+
return [];
58+
}
59+
$storeIds = $website->getStoreIds();
60+
61+
$condition = [
62+
$metadata->getLinkField() . ' = ?' => $linkFieldValue,
63+
'attribute_id = ?' => $attribute->getAttributeId(),
64+
];
65+
66+
$conditions = [];
67+
foreach ($storeIds as $storeId) {
68+
$identifier = $metadata->getEntityConnection()->quoteIdentifier(Store::STORE_ID);
69+
$condition[$identifier . ' = ?'] = $storeId;
70+
$conditions[] = $condition;
71+
}
72+
73+
return $conditions;
74+
}
75+
76+
/**
77+
* Returns conditions for new attribute action (insert) if attribute scope is "website"
78+
*
79+
* @param AbstractAttribute $attribute
80+
* @param EntityMetadataInterface $metadata
81+
* @param ScopeInterface[] $scopes
82+
* @param string $linkFieldValue
83+
* @return array
84+
*/
85+
public function buildNewAttributesWebsiteScope(
86+
AbstractAttribute $attribute,
87+
EntityMetadataInterface $metadata,
88+
array $scopes,
89+
$linkFieldValue
90+
) {
91+
$website = $this->getWebsiteForWebsiteScope($scopes);
92+
if (!$website) {
93+
return [];
94+
}
95+
$storeIds = $website->getStoreIds();
96+
97+
$condition = [
98+
$metadata->getLinkField() => $linkFieldValue,
99+
'attribute_id' => $attribute->getAttributeId(),
100+
];
101+
102+
$conditions = [];
103+
foreach ($storeIds as $storeId) {
104+
$condition[Store::STORE_ID] = $storeId;
105+
$conditions[] = $condition;
106+
}
107+
108+
return $conditions;
109+
}
110+
111+
/**
112+
* @param array $scopes
113+
* @return null|Website
114+
*/
115+
private function getWebsiteForWebsiteScope(array $scopes)
116+
{
117+
$store = $this->getStoreFromScopes($scopes);
118+
return $store ? $store->getWebsite() : null;
119+
}
120+
121+
/**
122+
* @param ScopeInterface[] $scopes
123+
* @return StoreInterface|null
124+
*/
125+
private function getStoreFromScopes(array $scopes)
126+
{
127+
foreach ($scopes as $scope) {
128+
if (Store::STORE_ID === $scope->getIdentifier()) {
129+
return $this->storeManager->getStore($scope->getValue());
130+
}
131+
}
132+
133+
return null;
134+
}
135+
}

0 commit comments

Comments
 (0)