Skip to content

Commit 09cf555

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-94005' into PANDA-2.2-develop-PR
2 parents 24daf3b + 36b67d5 commit 09cf555

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ protected function addGlobalAttribute(
156156
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
157157
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
158158
) {
159-
$storeId = $this->storeManager->getStore()->getId();
160-
161159
switch ($attribute->getBackendType()) {
162160
case 'decimal':
163161
case 'datetime':
@@ -166,10 +164,15 @@ protected function addGlobalAttribute(
166164
$collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner');
167165
break;
168166
default:
169-
$alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode();
167+
$alias = 'at_' . sha1($this->getId()) . $attribute->getAttributeCode();
168+
169+
$connection = $this->_productResource->getConnection();
170+
$storeId = $connection->getIfNullSql($alias . '.store_id', $this->storeManager->getStore()->getId());
171+
$linkField = $attribute->getEntity()->getLinkField();
172+
170173
$collection->getSelect()->join(
171-
[$alias => $collection->getTable('catalog_product_index_eav')],
172-
"($alias.entity_id = e.entity_id) AND ($alias.store_id = $storeId)" .
174+
[$alias => $collection->getTable('catalog_product_entity_varchar')],
175+
"($alias.$linkField = e.$linkField) AND ($alias.store_id = $storeId)" .
173176
" AND ($alias.attribute_id = {$attribute->getId()})",
174177
[]
175178
);

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ 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
*/
@@ -33,9 +38,9 @@ protected function setUp()
3338
$storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
3439
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
3540
$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([]);
41+
$this->productResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
42+
$this->productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf();
43+
$this->productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]);
3944
$productCategoryList = $this->getMockBuilder(\Magento\Catalog\Model\ProductCategoryList::class)
4045
->disableOriginalConstructor()
4146
->getMock();
@@ -45,7 +50,7 @@ protected function setUp()
4550
[
4651
'config' => $eavConfig,
4752
'storeManager' => $storeManager,
48-
'productResource' => $productResource,
53+
'productResource' => $this->productResource,
4954
'productCategoryList' => $productCategoryList,
5055
'data' => [
5156
'rule' => $ruleMock,
@@ -67,6 +72,14 @@ public function testAddToCollection()
6772
$this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true);
6873
$this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true);
6974
$this->attributeMock->expects($this->once())->method('getBackendType')->willReturn('multiselect');
75+
76+
$entityMock = $this->createMock(\Magento\Eav\Model\Entity\AbstractEntity::class);
77+
$entityMock->expects($this->once())->method('getLinkField')->willReturn('entitiy_id');
78+
$this->attributeMock->expects($this->once())->method('getEntity')->willReturn($entityMock);
79+
$connection = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
80+
81+
$this->productResource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connection);
82+
7083
$this->model->addToCollection($collectionMock);
7184
}
7285

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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,22 @@ protected function _getMappedSqlCondition(AbstractCondition $condition, $value =
154154
$this->_conditionOperatorMap[$conditionOperator]
155155
);
156156

157+
$bindValue = $condition->getBindArgumentValue();
158+
$expression = $value . $this->_connection->quoteInto($sql, $bindValue);
159+
160+
// values for multiselect attributes can be saved in comma separated format
161+
// below is a solution for matching such conditions with selected values
162+
if (in_array($conditionOperator, ['()', '{}']) && is_array($bindValue)) {
163+
foreach ($bindValue as $item) {
164+
$expression .= $this->_connection->quoteInto(
165+
" OR (FIND_IN_SET (?, {$this->_connection->quoteIdentifier($argument)}) > 0)",
166+
$item
167+
);
168+
}
169+
}
170+
157171
return $this->_expressionFactory->create(
158-
['expression' => $value . $this->_connection->quoteInto($sql, $condition->getBindArgumentValue())]
172+
['expression' => $expression]
159173
);
160174
}
161175

app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddMultipleStoreProductsToWishlistTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<title value="Add products to wishlist from different stores"/>
1313
<description value="All products added to wishlist should be visible on any store. Even if product visibility was set to 'Not Visible Individually' for this store"/>
1414
<group value="wishlist"/>
15+
<group value="skip" /><!-- Skipped; see MAGETWO-94100 -->
1516
</annotations>
1617
<before>
1718
<getData entity="DefaultRootCategoryGetter" stepKey="getDefaultRootCategory"/>

0 commit comments

Comments
 (0)