Skip to content

Commit ca5c2ed

Browse files
author
Oleksii Korshenko
committed
MAGETWO-86663: 11897: Catalog product list widget not working with multiple sku. #1050
- Merge Pull Request magento-engcom/magento2ce#1050 from nmalevanec/magento2:11897 - Merged commits: 1. 8d62341 2. d5b596a
2 parents 83a9b9c + d5b596a commit ca5c2ed

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public function getDefaultOperatorInputByType()
137137
*/
138138
$this->_defaultOperatorInputByType['category'] = ['==', '!=', '{}', '!{}', '()', '!()'];
139139
$this->_arrayInputTypes[] = 'category';
140+
$this->_defaultOperatorInputByType['sku'] = ['==', '!=', '{}', '!{}', '()', '!()'];
140141
}
141142
return $this->_defaultOperatorInputByType;
142143
}
@@ -382,6 +383,9 @@ public function getInputType()
382383
if ($this->getAttributeObject()->getAttributeCode() == 'category_ids') {
383384
return 'category';
384385
}
386+
if ($this->getAttributeObject()->getAttributeCode() == 'sku') {
387+
return 'sku';
388+
}
385389
switch ($this->getAttributeObject()->getFrontendInput()) {
386390
case 'select':
387391
return 'select';
@@ -606,7 +610,12 @@ public function getBindArgumentValue()
606610
$this->getValueParsed()
607611
)->__toString()
608612
);
613+
} elseif ($this->getAttribute() === 'sku') {
614+
$value = $this->getData('value');
615+
$value = preg_split('#\s*[,;]\s*#', $value, null, PREG_SPLIT_NO_EMPTY);
616+
$this->setValueParsed($value);
609617
}
618+
610619
return parent::getBindArgumentValue();
611620
}
612621

@@ -704,7 +713,7 @@ protected function _getAttributeSetId($productId)
704713
public function getOperatorForValidate()
705714
{
706715
$operator = $this->getOperator();
707-
if ($this->getInputType() == 'category') {
716+
if (in_array($this->getInputType(), ['category', 'sku'])) {
708717
if ($operator == '==') {
709718
$operator = '{}';
710719
} elseif ($operator == '!=') {

dev/tests/integration/testsuite/Magento/CatalogWidget/Block/Product/ProductListTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,36 @@ public function testCreateCollection()
6767
. '`attribute`:`multiselect_attribute`,`operator`:`^[^]`,'
6868
. '`value`:[`' . implode(',', $multiselectAttributeOptionIds) . '`]^]^]';
6969
$this->block->setData('conditions_encoded', $encodedConditions);
70+
$this->performAssertions(1);
71+
}
72+
73+
/**
74+
* Test product list widget can process condition with multiple product sku.
75+
*
76+
* @magentoDataFixture Magento/Catalog/_files/multiple_products.php
77+
*/
78+
public function testCreateCollectionWithMultipleSkuCondition()
79+
{
80+
$encodedConditions = '^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,' .
81+
'`aggregator`:`all`,`value`:`1`,`new_child`:``^],`1--1`:^[`type`:`Magento||CatalogWidget||Model||Rule|' .
82+
'|Condition||Product`,`attribute`:`sku`,`operator`:`==`,`value`:`simple1, simple2`^]^]';
83+
$this->block->setData('conditions_encoded', $encodedConditions);
84+
$this->performAssertions(2);
85+
}
7086

71-
// Load products collection filtered using specified conditions and perform assesrions
87+
/**
88+
* Check product collection includes correct amount of products.
89+
*
90+
* @param int $count
91+
* @return void
92+
*/
93+
private function performAssertions(int $count)
94+
{
95+
// Load products collection filtered using specified conditions and perform assertions.
7296
$productCollection = $this->block->createCollection();
7397
$productCollection->load();
7498
$this->assertEquals(
75-
1,
99+
$count,
76100
$productCollection->count(),
77101
"Product collection was not filtered according to the widget condition."
78102
);

0 commit comments

Comments
 (0)