Skip to content

Commit ff3a3a2

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-94060' into PANDA-2.3-develop-PR
2 parents 05f9df7 + d371176 commit ff3a3a2

File tree

6 files changed

+72
-13
lines changed

6 files changed

+72
-13
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ public function loadAttributeOptions()
101101

102102
/**
103103
* {@inheritdoc}
104+
*
105+
* @param array &$attributes
106+
* @return void
104107
*/
105108
protected function _addSpecialAttributes(array &$attributes)
106109
{
@@ -163,8 +166,6 @@ protected function addGlobalAttribute(
163166
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
164167
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
165168
) {
166-
$storeId = $this->storeManager->getStore()->getId();
167-
168169
switch ($attribute->getBackendType()) {
169170
case 'decimal':
170171
case 'datetime':
@@ -173,10 +174,15 @@ protected function addGlobalAttribute(
173174
$collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner');
174175
break;
175176
default:
176-
$alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode();
177+
$alias = 'at_' . sha1($this->getId()) . $attribute->getAttributeCode();
178+
179+
$connection = $this->_productResource->getConnection();
180+
$storeId = $connection->getIfNullSql($alias . '.store_id', $this->storeManager->getStore()->getId());
181+
$linkField = $attribute->getEntity()->getLinkField();
182+
177183
$collection->getSelect()->join(
178-
[$alias => $collection->getTable('catalog_product_index_eav')],
179-
"($alias.entity_id = e.entity_id) AND ($alias.store_id = $storeId)" .
184+
[$alias => $collection->getTable('catalog_product_entity_varchar')],
185+
"($alias.$linkField = e.$linkField) AND ($alias.store_id = $storeId)" .
180186
" AND ($alias.attribute_id = {$attribute->getId()})",
181187
[]
182188
);
@@ -225,6 +231,8 @@ protected function addNotGlobalAttribute(
225231

226232
/**
227233
* {@inheritdoc}
234+
*
235+
* @return string
228236
*/
229237
public function getMappedSqlField()
230238
{
@@ -244,6 +252,9 @@ public function getMappedSqlField()
244252

245253
/**
246254
* {@inheritdoc}
255+
*
256+
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
257+
* @return $this
247258
*/
248259
public function collectValidatedAttributes($productCollection)
249260
{

app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ class ProductTest extends \PHPUnit\Framework\TestCase
1717
*/
1818
private $model;
1919

20+
/**
21+
* @var \Magento\Catalog\Model\ResourceModel\Product|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
private $productResource;
24+
2025
/**
2126
* @var \PHPUnit_Framework_MockObject_MockObject
2227
*/
2328
private $attributeMock;
2429

30+
/**
31+
* @inheritdoc
32+
*
33+
* @return void
34+
*/
2535
protected function setUp()
2636
{
2737
$objectManagerHelper = new ObjectManager($this);
@@ -33,9 +43,9 @@ protected function setUp()
3343
$storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
3444
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
3545
$storeManager->expects($this->any())->method('getStore')->willReturn($storeMock);
36-
$productResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
37-
$productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf();
38-
$productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]);
46+
$this->productResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
47+
$this->productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf();
48+
$this->productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]);
3949
$productCategoryList = $this->getMockBuilder(\Magento\Catalog\Model\ProductCategoryList::class)
4050
->disableOriginalConstructor()
4151
->getMock();
@@ -45,7 +55,7 @@ protected function setUp()
4555
[
4656
'config' => $eavConfig,
4757
'storeManager' => $storeManager,
48-
'productResource' => $productResource,
58+
'productResource' => $this->productResource,
4959
'productCategoryList' => $productCategoryList,
5060
'data' => [
5161
'rule' => $ruleMock,
@@ -55,6 +65,11 @@ protected function setUp()
5565
);
5666
}
5767

68+
/**
69+
* Test addToCollection method.
70+
*
71+
* @return void
72+
*/
5873
public function testAddToCollection()
5974
{
6075
$collectionMock = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
@@ -67,9 +82,22 @@ public function testAddToCollection()
6782
$this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true);
6883
$this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true);
6984
$this->attributeMock->expects($this->once())->method('getBackendType')->willReturn('multiselect');
85+
86+
$entityMock = $this->createMock(\Magento\Eav\Model\Entity\AbstractEntity::class);
87+
$entityMock->expects($this->once())->method('getLinkField')->willReturn('entitiy_id');
88+
$this->attributeMock->expects($this->once())->method('getEntity')->willReturn($entityMock);
89+
$connection = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
90+
91+
$this->productResource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connection);
92+
7093
$this->model->addToCollection($collectionMock);
7194
}
7295

96+
/**
97+
* Test getMappedSqlField method.
98+
*
99+
* @return void
100+
*/
73101
public function testGetMappedSqlFieldSku()
74102
{
75103
$this->model->setAttribute('sku');

app/code/Magento/ConfigurableProduct/Test/Mftf/Test/StorefrontConfigurableProductWithFileCustomOptionTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<severity value="CRITICAL"/>
1818
<testCaseId value="MAGETWO-93059"/>
1919
<group value="ConfigurableProduct"/>
20+
<group value="skip"/><!-- MAGETWO-94170 -->
2021
</annotations>
2122

2223
<before>

app/code/Magento/Rule/Model/Condition/AbstractCondition.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,10 @@ public function getValueParsed()
355355
{
356356
if (!$this->hasValueParsed()) {
357357
$value = $this->getData('value');
358-
if (is_array($value) && isset($value[0]) && is_string($value[0])) {
359-
$value = $value[0];
358+
if (is_array($value) && count($value) === 1) {
359+
$value = reset($value);
360360
}
361-
if ($this->isArrayOperatorType() && $value) {
361+
if (!is_array($value) && $this->isArrayOperatorType() && $value) {
362362
$value = preg_split('#\s*[,;]\s*#', $value, null, PREG_SPLIT_NO_EMPTY);
363363
}
364364
$this->setValueParsed($value);

app/code/Magento/Rule/Model/Condition/Sql/Builder.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,22 @@ protected function _getMappedSqlCondition(
163163
$this->_conditionOperatorMap[$conditionOperator]
164164
);
165165

166+
$bindValue = $condition->getBindArgumentValue();
167+
$expression = $value . $this->_connection->quoteInto($sql, $bindValue);
168+
169+
// values for multiselect attributes can be saved in comma-separated format
170+
// below is a solution for matching such conditions with selected values
171+
if (is_array($bindValue) && \in_array($conditionOperator, ['()', '{}'], true)) {
172+
foreach ($bindValue as $item) {
173+
$expression .= $this->_connection->quoteInto(
174+
" OR (FIND_IN_SET (?, {$this->_connection->quoteIdentifier($argument)}) > 0)",
175+
$item
176+
);
177+
}
178+
}
179+
166180
return $this->_expressionFactory->create(
167-
['expression' => $value . $this->_connection->quoteInto($sql, $condition->getBindArgumentValue())]
181+
['expression' => $expression]
168182
);
169183
}
170184

@@ -174,6 +188,7 @@ protected function _getMappedSqlCondition(
174188
* @param bool $isDefaultStoreUsed
175189
* @return string
176190
* @SuppressWarnings(PHPMD.NPathComplexity)
191+
* @throws \Magento\Framework\Exception\LocalizedException
177192
*/
178193
protected function _getMappedSqlCombination(
179194
Combine $combine,

dev/tests/functional/tests/app/Magento/Checkout/Test/TestCase/OnePageCheckoutTest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
<constraint name="Magento\Checkout\Test\Constraint\AssertOrderSuccessPlacedMessage" />
5050
<constraint name="Magento\Sales\Test\Constraint\AssertOrderGrandTotal" />
5151
<constraint name="Magento\Sales\Test\Constraint\AssertOrderAddresses" />
52+
<!-- MAGETWO-94169 -->
53+
<data name="tag" xsi:type="string">stable:no</data>
54+
<data name="issue" xsi:type="string">MAGETWO-94169: [MTF] - OnePageCheckoutUsingNonDefaultAddress_0 fails on 2.3-develop</data>
55+
<!-- MAGETWO-94169 -->
5256
</variation>
5357
<variation name="OnePageCheckoutUsingNewAddress" summary="Checkout as Customer using New address" ticketId="MAGETWO-42601">
5458
<data name="tag" xsi:type="string">severity:S1</data>

0 commit comments

Comments
 (0)