Skip to content

Commit 184593e

Browse files
committed
MAGETWO-85781: Configurable product Final Price ignores Catalog Rule
- Remove union two tables to get category ids;
1 parent f83eec1 commit 184593e

File tree

3 files changed

+54
-81
lines changed

3 files changed

+54
-81
lines changed

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

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,13 @@ class ProductTest extends \PHPUnit_Framework_TestCase
3939

4040
protected function setUp()
4141
{
42-
$this->config = $this->getMock('Magento\Eav\Model\Config', ['getAttribute'], [], '', false);
43-
$this->productModel = $this->getMock(
44-
'Magento\Catalog\Model\Product',
45-
[
46-
'__wakeup',
47-
'hasData',
48-
'getData',
49-
'getId',
50-
'getStoreId',
51-
'getResource',
52-
'addAttributeToSelect',
53-
],
54-
[],
55-
'',
56-
false
57-
);
42+
$this->config = $this->getMockBuilder(\Magento\Eav\Model\Config::class)
43+
->disableOriginalConstructor()
44+
->setMethods(['getAttribute'])
45+
->getMock();
46+
$this->productModel = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
47+
->disableOriginalConstructor()
48+
->getMock();
5849
$this->category = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Category::class)
5950
->disableOriginalConstructor()
6051
->getMock();
@@ -69,23 +60,9 @@ protected function setUp()
6960
->disableOriginalConstructor()
7061
->setMethods(['from', 'where'])
7162
->getMock();
72-
73-
$this->eavAttributeResource = $this->getMock(
74-
'\Magento\Catalog\Model\ResourceModel\Eav\Attribute',
75-
[
76-
'__wakeup',
77-
'isAllowedForRuleCondition',
78-
'getDataUsingMethod',
79-
'getAttributeCode',
80-
'getFrontendLabel',
81-
'isScopeGlobal',
82-
'getBackendType',
83-
'getFrontendInput'
84-
],
85-
[],
86-
'',
87-
false
88-
);
63+
$this->eavAttributeResource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
64+
->disableOriginalConstructor()
65+
->getMock();
8966

9067
$this->productResource->expects($this->any())->method('loadAllAttributes')
9168
->will($this->returnSelf());
@@ -102,7 +79,7 @@ protected function setUp()
10279

10380
$this->objectManagerHelper = new ObjectManagerHelper($this);
10481
$this->product = $this->objectManagerHelper->getObject(
105-
'Magento\CatalogRule\Model\Rule\Condition\Product',
82+
\Magento\CatalogRule\Model\Rule\Condition\Product::class,
10683
[
10784
'config' => $this->config,
10885
'product' => $this->productModel,

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

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
87
/**
98
* CatalogWidget Rule Product Condition data model
109
*/
1110
namespace Magento\CatalogWidget\Model\Rule\Condition;
1211

12+
use \Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
13+
use \Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute;
14+
use \Magento\Store\Model\StoreManagerInterface;
15+
use \Magento\Catalog\Api\ProductRepositoryInterface;
16+
use \Magento\Framework\Locale\FormatInterface;
17+
use \Magento\Catalog\Model\ResourceModel\Category;
18+
use \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection as AttributeSetCollection;
19+
use \Magento\Catalog\Model\ProductFactory;
20+
use \Magento\Eav\Model\Config;
21+
use \Magento\Rule\Model\Condition\Context;
22+
use \Magento\Backend\Helper\Data as BackendData;
23+
1324
/**
1425
* Class Product
15-
*
16-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1726
*/
1827
class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct
1928
{
@@ -30,36 +39,36 @@ class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct
3039
/**
3140
* Store manager
3241
*
33-
* @var \Magento\Store\Model\StoreManagerInterface
42+
* @var StoreManagerInterface
3443
*/
3544
protected $storeManager;
3645

3746
/**
38-
* @param \Magento\Rule\Model\Condition\Context $context
39-
* @param \Magento\Backend\Helper\Data $backendData
40-
* @param \Magento\Eav\Model\Config $config
41-
* @param \Magento\Catalog\Model\ProductFactory $productFactory
42-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
47+
* @param Context $context
48+
* @param BackendData $backendData
49+
* @param Config $config
50+
* @param ProductFactory $productFactory
51+
* @param ProductRepositoryInterface $productRepository
4352
* @param \Magento\Catalog\Model\ResourceModel\Product $productResource
44-
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $attrSetCollection
45-
* @param \Magento\Framework\Locale\FormatInterface $localeFormat
46-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
53+
* @param AttributeSetCollection $attrSetCollection
54+
* @param FormatInterface $localeFormat
55+
* @param StoreManagerInterface $storeManager
4756
* @param array $data
48-
* @param \Magento\Catalog\Model\ResourceModel\Category $category
57+
* @param Category $category
4958
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5059
*/
5160
public function __construct(
52-
\Magento\Rule\Model\Condition\Context $context,
53-
\Magento\Backend\Helper\Data $backendData,
54-
\Magento\Eav\Model\Config $config,
55-
\Magento\Catalog\Model\ProductFactory $productFactory,
56-
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
61+
Context $context,
62+
BackendData $backendData,
63+
Config $config,
64+
ProductFactory $productFactory,
65+
ProductRepositoryInterface $productRepository,
5766
\Magento\Catalog\Model\ResourceModel\Product $productResource,
58-
\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $attrSetCollection,
59-
\Magento\Framework\Locale\FormatInterface $localeFormat,
60-
\Magento\Store\Model\StoreManagerInterface $storeManager,
67+
AttributeSetCollection $attrSetCollection,
68+
FormatInterface $localeFormat,
69+
StoreManagerInterface $storeManager,
6170
array $data = [],
62-
\Magento\Catalog\Model\ResourceModel\Category $category = null
71+
Category $category = null
6372
) {
6473
$this->storeManager = $storeManager;
6574
parent::__construct(
@@ -111,7 +120,7 @@ protected function _addSpecialAttributes(array &$attributes)
111120
/**
112121
* Add condition to collection
113122
*
114-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
123+
* @param ProductCollection $collection
115124
* @return $this
116125
*/
117126
public function addToCollection($collection)
@@ -142,14 +151,12 @@ public function addToCollection($collection)
142151
}
143152

144153
/**
145-
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
146-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
154+
* @param EavAttribute $attribute
155+
* @param ProductCollection $collection
147156
* @return $this
148157
*/
149-
protected function addGlobalAttribute(
150-
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
151-
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
152-
) {
158+
protected function addGlobalAttribute(EavAttribute $attribute, ProductCollection $collection)
159+
{
153160
$storeId = $this->storeManager->getStore()->getId();
154161

155162
switch ($attribute->getBackendType()) {
@@ -175,14 +182,12 @@ protected function addGlobalAttribute(
175182
}
176183

177184
/**
178-
* @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
179-
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
185+
* @param EavAttribute $attribute
186+
* @param ProductCollection $collection
180187
* @return $this
181188
*/
182-
protected function addNotGlobalAttribute(
183-
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute,
184-
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
185-
) {
189+
protected function addNotGlobalAttribute(EavAttribute $attribute, ProductCollection $collection)
190+
{
186191
$storeId = $this->storeManager->getStore()->getId();
187192
$values = $collection->getAllAttributeValues($attribute);
188193
$validEntities = [];

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ abstract class AbstractProduct extends \Magento\Rule\Model\Condition\AbstractCon
102102
* @param \Magento\Catalog\Model\ResourceModel\Product $productResource
103103
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $attrSetCollection
104104
* @param \Magento\Framework\Locale\FormatInterface $localeFormat
105-
* @param \Magento\Catalog\Model\ResourceModel\Category|null $category
106105
* @param array $data
106+
* @param \Magento\Catalog\Model\ResourceModel\Category|null $category
107107
*
108108
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
109109
*/
@@ -752,18 +752,9 @@ protected function getEavAttributeTableAlias()
752752
private function getCategoryIds($productId)
753753
{
754754
if (!isset($this->categoryIdList[$productId])) {
755-
$unionSelect = new UnionExpression(
756-
[
757-
$this->getCategorySelect($productId, $this->category->getCategoryProductTable()),
758-
$this->getCategorySelect(
759-
$productId,
760-
$this->_productResource->getTable(AbstractAction::MAIN_INDEX_TABLE)
761-
)
762-
],
763-
Select::SQL_UNION_ALL
755+
$this->categoryIdList[$productId] = $this->_productResource->getConnection()->fetchCol(
756+
$this->getCategorySelect($productId, $this->category->getCategoryProductTable())
764757
);
765-
766-
$this->categoryIdList[$productId] = $this->_productResource->getConnection()->fetchCol($unionSelect);
767758
}
768759

769760
return $this->categoryIdList[$productId];

0 commit comments

Comments
 (0)