Skip to content

Commit f661c2c

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-63626
2 parents c3928e3 + 8d1339c commit f661c2c

File tree

33 files changed

+1135
-106
lines changed

33 files changed

+1135
-106
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ protected function _saveProductAttributes(array $attributesData)
12491249
$linkId = $this->_connection->fetchOne(
12501250
$this->_connection->select()
12511251
->from($this->getResource()->getTable('catalog_product_entity'))
1252-
->where('sku = ?', $sku)
1252+
->where('sku = ?', (string)$sku)
12531253
->columns($this->getProductEntityLinkField())
12541254
);
12551255

app/code/Magento/CatalogRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\CatalogRule\Model\ResourceModel\Rule;
77

8+
use Magento\Framework\Serialize\Serializer\Json;
9+
use Magento\Framework\App\ObjectManager;
10+
811
class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection
912
{
1013
/**
@@ -14,6 +17,11 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
1417
*/
1518
protected $_associatedEntitiesMap;
1619

20+
/**
21+
* @var Json
22+
*/
23+
protected $serializer;
24+
1725
/**
1826
* Collection constructor.
1927
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
@@ -22,17 +30,20 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
2230
* @param \Magento\Framework\Event\ManagerInterface $eventManager
2331
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
2432
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
33+
* @param Json|null $serializer
2534
*/
2635
public function __construct(
2736
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
2837
\Psr\Log\LoggerInterface $logger,
2938
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
3039
\Magento\Framework\Event\ManagerInterface $eventManager,
3140
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
32-
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
41+
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null,
42+
Json $serializer = null
3343
) {
3444
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
3545
$this->_associatedEntitiesMap = $this->getAssociatedEntitiesMap();
46+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
3647
}
3748

3849
/**
@@ -55,7 +66,7 @@ protected function _construct()
5566
*/
5667
public function addAttributeInConditionFilter($attributeCode)
5768
{
58-
$match = sprintf('%%%s%%', substr(serialize(['attribute' => $attributeCode]), 5, -1));
69+
$match = sprintf('%%%s%%', substr($this->serializer->serialize(['attribute' => $attributeCode]), 1, -1));
5970
$this->addFieldToFilter('conditions_serialized', ['like' => $match]);
6071

6172
return $this;
@@ -96,7 +107,6 @@ protected function mapAssociatedEntities($entityType, $objectField)
96107

97108
/**
98109
* @return $this
99-
* @throws \Exception
100110
*/
101111
protected function _afterLoad()
102112
{

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel implements RuleInterface, I
162162
* @param array $data
163163
* @param ExtensionAttributesFactory|null $extensionFactory
164164
* @param AttributeValueFactory|null $customAttributeFactory
165+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
165166
*
166167
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
167168
*/
@@ -186,7 +187,8 @@ public function __construct(
186187
array $relatedCacheTypes = [],
187188
array $data = [],
188189
ExtensionAttributesFactory $extensionFactory = null,
189-
AttributeValueFactory $customAttributeFactory = null
190+
AttributeValueFactory $customAttributeFactory = null,
191+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
190192
) {
191193
$this->_productCollectionFactory = $productCollectionFactory;
192194
$this->_storeManager = $storeManager;
@@ -210,7 +212,8 @@ public function __construct(
210212
$resourceCollection,
211213
$data,
212214
$extensionFactory,
213-
$customAttributeFactory
215+
$customAttributeFactory,
216+
$serializer
214217
);
215218
}
216219

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogRule\Setup;
8+
9+
use Magento\Framework\DB\FieldDataConverterFactory;
10+
use Magento\Framework\DB\DataConverter\SerializedToJson;
11+
use Magento\Framework\Setup\ModuleContextInterface;
12+
use Magento\Framework\Setup\ModuleDataSetupInterface;
13+
use Magento\Framework\Setup\UpgradeDataInterface;
14+
use Magento\Framework\EntityManager\MetadataPool;
15+
use Magento\CatalogRule\Api\Data\RuleInterface;
16+
17+
class UpgradeData implements UpgradeDataInterface
18+
{
19+
/**
20+
* @var FieldDataConverterFactory
21+
*/
22+
private $fieldDataConverterFactory;
23+
24+
/**
25+
* @var MetadataPool
26+
*/
27+
private $metadataPool;
28+
29+
/**
30+
* UpgradeData constructor.
31+
*
32+
* @param FieldDataConverterFactory $fieldDataConverterFactory
33+
* @param MetadataPool $metadataPool
34+
*/
35+
public function __construct(
36+
FieldDataConverterFactory $fieldDataConverterFactory,
37+
MetadataPool $metadataPool
38+
) {
39+
$this->fieldDataConverterFactory = $fieldDataConverterFactory;
40+
$this->metadataPool = $metadataPool;
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
47+
{
48+
$setup->startSetup();
49+
50+
if (version_compare($context->getVersion(), '2.0.3', '<')) {
51+
$this->convertSerializedDataToJson($setup);
52+
}
53+
54+
$setup->endSetup();
55+
}
56+
57+
/**
58+
* Convert metadata from serialized to JSON format:
59+
*
60+
* @param ModuleDataSetupInterface $setup
61+
*
62+
* @return void
63+
*/
64+
public function convertSerializedDataToJson($setup)
65+
{
66+
$fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class);
67+
$metadata = $this->metadataPool->getMetadata(RuleInterface::class);
68+
69+
$fieldDataConverter->convert(
70+
$setup->getConnection(),
71+
$setup->getTable('catalogrule'),
72+
$metadata->getLinkField(),
73+
'conditions_serialized'
74+
);
75+
$fieldDataConverter->convert(
76+
$setup->getConnection(),
77+
$setup->getTable('catalogrule'),
78+
$metadata->getLinkField(),
79+
'actions_serialized'
80+
);
81+
}
82+
}

app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,46 @@ protected function setUp()
149149
'resourceIterator' => $this->_resourceIterator,
150150
'extensionFactory' => $extensionFactoryMock,
151151
'customAttributeFactory' => $attributeValueFactoryMock,
152+
'serializer' => $this->getSerializerMock(),
152153
]
153154
);
154155
}
155156

157+
/**
158+
* Get mock for serializer
159+
*
160+
* @return \PHPUnit_Framework_MockObject_MockObject
161+
*/
162+
private function getSerializerMock()
163+
{
164+
$serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
165+
->disableOriginalConstructor()
166+
->setMethods(['serialize', 'unserialize'])
167+
->getMock();
168+
169+
$serializerMock->expects($this->any())
170+
->method('serialize')
171+
->will(
172+
$this->returnCallback(
173+
function ($value) {
174+
return json_encode($value);
175+
}
176+
)
177+
);
178+
179+
$serializerMock->expects($this->any())
180+
->method('unserialize')
181+
->will(
182+
$this->returnCallback(
183+
function ($value) {
184+
return json_decode($value, true);
185+
}
186+
)
187+
);
188+
189+
return $serializerMock;
190+
}
191+
156192
/**
157193
* @dataProvider dataProviderCallbackValidateProduct
158194
* @param bool $validate

app/code/Magento/CatalogRule/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_CatalogRule" setup_version="2.0.2">
9+
<module name="Magento_CatalogRule" setup_version="2.0.3">
1010
<sequence>
1111
<module name="Magento_Rule"/>
1212
<module name="Magento_Catalog"/>

app/code/Magento/CatalogWidget/Model/Rule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel
3232
* @param ExtensionAttributesFactory|null $extensionFactory
3333
* @param AttributeValueFactory|null $customAttributeFactory
3434
*
35+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
3536
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3637
*/
3738
public function __construct(
@@ -44,7 +45,8 @@ public function __construct(
4445
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
4546
array $data = [],
4647
ExtensionAttributesFactory $extensionFactory = null,
47-
AttributeValueFactory $customAttributeFactory = null
48+
AttributeValueFactory $customAttributeFactory = null,
49+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
4850
) {
4951
$this->conditionsFactory = $conditionsFactory;
5052
parent::__construct(
@@ -56,7 +58,8 @@ public function __construct(
5658
$resourceCollection,
5759
$data,
5860
$extensionFactory,
59-
$customAttributeFactory
61+
$customAttributeFactory,
62+
$serializer
6063
);
6164
}
6265

app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ protected function _getFormFilter()
242242
if ($filterCode) {
243243
$filterClass = 'Magento\Framework\Data\Form\Filter\\' . ucfirst($filterCode);
244244
if ($filterCode == 'date') {
245-
$filter = new $filterClass($this->_dateFilterFormat(), $this->_localeResolver->getLocale());
245+
$filter = new $filterClass($this->_dateFilterFormat(), $this->_localeResolver);
246246
} else {
247247
$filter = new $filterClass();
248248
}

app/code/Magento/Eav/Test/Unit/Model/Attribute/Data/AbstractDataTest.php

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ public function extractedDataDataProvider()
9595
* @param string $expectedResult
9696
* @param array $params
9797
* @param bool $requestScopeOnly
98+
* @param string|null $filter
9899
* @dataProvider getRequestValueDataProvider
99100
*/
100-
public function testGetRequestValue($requestScope, $value, $params, $requestScopeOnly, $expectedResult)
101+
public function testGetRequestValue($requestScope, $value, $params, $requestScopeOnly, $expectedResult, $filter)
101102
{
102103
$requestMock = $this->getMock(
103104
\Magento\Framework\App\Request\Http::class,
@@ -112,8 +113,17 @@ public function testGetRequestValue($requestScope, $value, $params, $requestScop
112113
]));
113114
$requestMock->expects($this->any())->method('getParams')->will($this->returnValue($params));
114115

115-
$attributeMock = $this->getMock(\Magento\Eav\Model\Attribute::class, [], [], '', false);
116+
$attributeMock = $this->getMock(
117+
\Magento\Eav\Model\Attribute::class,
118+
['getInputFilter', 'getAttributeCode'],
119+
[],
120+
'',
121+
false
122+
);
116123
$attributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue('attributeCode'));
124+
if ($filter) {
125+
$attributeMock->expects($this->any())->method('getInputFilter')->will($this->returnValue($filter));
126+
}
117127

118128
$this->model->setAttribute($attributeMock);
119129
$this->model->setRequestScope($requestScope);
@@ -133,41 +143,55 @@ public function getRequestValueDataProvider()
133143
'params' => [],
134144
'requestScopeOnly' => true,
135145
'expectedResult' => 'value',
146+
'filter' => null,
136147
],
137148
[
138149
'requestScope' => 'scope/scope',
139150
'value' => 'value',
140151
'params' => ['scope' => ['scope' => ['attributeCode' => 'data']]],
141152
'requestScopeOnly' => true,
142-
'expectedResult' => 'data'
153+
'expectedResult' => 'data',
154+
'filter' => null,
143155
],
144156
[
145157
'requestScope' => 'scope/scope',
146158
'value' => 'value',
147159
'params' => ['scope' => ['scope' => []]],
148160
'requestScopeOnly' => true,
149-
'expectedResult' => false
161+
'expectedResult' => false,
162+
'filter' => null,
150163
],
151164
[
152165
'requestScope' => 'scope/scope',
153166
'value' => 'value',
154167
'params' => ['scope'],
155168
'requestScopeOnly' => true,
156-
'expectedResult' => false
169+
'expectedResult' => false,
170+
'filter' => null,
157171
],
158172
[
159173
'requestScope' => 'scope',
160174
'value' => 'value',
161175
'params' => ['otherScope' => 1],
162176
'requestScopeOnly' => true,
163-
'expectedResult' => false
177+
'expectedResult' => false,
178+
'filter' => null,
164179
],
165180
[
166181
'requestScope' => 'scope',
167182
'value' => 'value',
168183
'params' => ['otherScope' => 1],
169184
'requestScopeOnly' => false,
170-
'expectedResult' => 'value'
185+
'expectedResult' => 'value',
186+
'filter' => null,
187+
],
188+
[
189+
'requestScope' => 'scope',
190+
'value' => '1970-01-01',
191+
'params' => [],
192+
'requestScopeOnly' => false,
193+
'expectedResult' => '1970-01-01',
194+
'filter' => 'date'
171195
]
172196
];
173197
}

0 commit comments

Comments
 (0)