Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MAGETWO-94005' into PANDA-2.2-de…
Browse files Browse the repository at this point in the history
…velop-PR
  • Loading branch information
RuslanKostiv1 committed Aug 10, 2018
2 parents 24daf3b + 36b67d5 commit 09cf555
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 13 deletions.
13 changes: 8 additions & 5 deletions app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ protected function addGlobalAttribute(
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
) {
$storeId = $this->storeManager->getStore()->getId();

switch ($attribute->getBackendType()) {
case 'decimal':
case 'datetime':
Expand All @@ -166,10 +164,15 @@ protected function addGlobalAttribute(
$collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner');
break;
default:
$alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode();
$alias = 'at_' . sha1($this->getId()) . $attribute->getAttributeCode();

$connection = $this->_productResource->getConnection();
$storeId = $connection->getIfNullSql($alias . '.store_id', $this->storeManager->getStore()->getId());
$linkField = $attribute->getEntity()->getLinkField();

$collection->getSelect()->join(
[$alias => $collection->getTable('catalog_product_index_eav')],
"($alias.entity_id = e.entity_id) AND ($alias.store_id = $storeId)" .
[$alias => $collection->getTable('catalog_product_entity_varchar')],
"($alias.$linkField = e.$linkField) AND ($alias.store_id = $storeId)" .
" AND ($alias.attribute_id = {$attribute->getId()})",
[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class ProductTest extends \PHPUnit\Framework\TestCase
*/
private $model;

/**
* @var \Magento\Catalog\Model\ResourceModel\Product|\PHPUnit_Framework_MockObject_MockObject
*/
private $productResource;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
Expand All @@ -33,9 +38,9 @@ protected function setUp()
$storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);
$storeManager->expects($this->any())->method('getStore')->willReturn($storeMock);
$productResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
$productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf();
$productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]);
$this->productResource = $this->createMock(\Magento\Catalog\Model\ResourceModel\Product::class);
$this->productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf();
$this->productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]);
$productCategoryList = $this->getMockBuilder(\Magento\Catalog\Model\ProductCategoryList::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -45,7 +50,7 @@ protected function setUp()
[
'config' => $eavConfig,
'storeManager' => $storeManager,
'productResource' => $productResource,
'productResource' => $this->productResource,
'productCategoryList' => $productCategoryList,
'data' => [
'rule' => $ruleMock,
Expand All @@ -67,6 +72,14 @@ public function testAddToCollection()
$this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true);
$this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true);
$this->attributeMock->expects($this->once())->method('getBackendType')->willReturn('multiselect');

$entityMock = $this->createMock(\Magento\Eav\Model\Entity\AbstractEntity::class);
$entityMock->expects($this->once())->method('getLinkField')->willReturn('entitiy_id');
$this->attributeMock->expects($this->once())->method('getEntity')->willReturn($entityMock);
$connection = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);

$this->productResource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connection);

$this->model->addToCollection($collectionMock);
}

Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Rule/Model/Condition/AbstractCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ public function getValueParsed()
{
if (!$this->hasValueParsed()) {
$value = $this->getData('value');
if (is_array($value) && isset($value[0]) && is_string($value[0])) {
$value = $value[0];
if (is_array($value) && count($value) === 1) {
$value = reset($value);
}
if ($this->isArrayOperatorType() && $value) {
if (!is_array($value) && $this->isArrayOperatorType() && $value) {
$value = preg_split('#\s*[,;]\s*#', $value, null, PREG_SPLIT_NO_EMPTY);
}
$this->setValueParsed($value);
Expand Down
16 changes: 15 additions & 1 deletion app/code/Magento/Rule/Model/Condition/Sql/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,22 @@ protected function _getMappedSqlCondition(AbstractCondition $condition, $value =
$this->_conditionOperatorMap[$conditionOperator]
);

$bindValue = $condition->getBindArgumentValue();
$expression = $value . $this->_connection->quoteInto($sql, $bindValue);

// values for multiselect attributes can be saved in comma separated format
// below is a solution for matching such conditions with selected values
if (in_array($conditionOperator, ['()', '{}']) && is_array($bindValue)) {
foreach ($bindValue as $item) {
$expression .= $this->_connection->quoteInto(
" OR (FIND_IN_SET (?, {$this->_connection->quoteIdentifier($argument)}) > 0)",
$item
);
}
}

return $this->_expressionFactory->create(
['expression' => $value . $this->_connection->quoteInto($sql, $condition->getBindArgumentValue())]
['expression' => $expression]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<title value="Add products to wishlist from different stores"/>
<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"/>
<group value="wishlist"/>
<group value="skip" /><!-- Skipped; see MAGETWO-94100 -->
</annotations>
<before>
<getData entity="DefaultRootCategoryGetter" stepKey="getDefaultRootCategory"/>
Expand Down

0 comments on commit 09cf555

Please sign in to comment.