Skip to content

Commit 694884f

Browse files
committed
resolve conflict
2 parents aab5dcf + dfea6d1 commit 694884f

File tree

8 files changed

+124
-9
lines changed

8 files changed

+124
-9
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ repos:
1111
- id: check-json
1212
- id: pretty-format-json
1313
args: ["--indent=4", "--autofix", "--no-sort-keys"]
14-
- repo: https://github.com/eriocnemis/git.MagentoPreCommitHooks
15-
rev: 1.0.7
14+
- repo: https://github.com/eriocnemis/git.magento_pre_commit_hooks
15+
rev: 1.0.10
1616
hooks:
17+
- id: magento-xml
1718
- id: magento-phpcs
18-
# - id: magento-phpmd
19+
args: ["--autofix"]
20+
- id: magento-phpmd
1921
- id: magento-phpcpd
2022
- id: magento-phpstan

Model/Indexer/IndexBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
/**
2121
* Rule index builder
22+
*
23+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2224
*/
2325
class IndexBuilder
2426
{

Model/Indexer/Product/ProductRuleProcessor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ProductRuleProcessor extends AbstractProcessor
2323
* @param int $id
2424
* @param bool $forceReindex
2525
* @return void
26+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
2627
*/
2728
public function reindexRow($id, $forceReindex = false)
2829
{
@@ -39,6 +40,7 @@ public function reindexRow($id, $forceReindex = false)
3940
* @param int[] $ids
4041
* @param bool $forceReindex
4142
* @return void
43+
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
4244
*/
4345
public function reindexList($ids, $forceReindex = false)
4446
{

Model/Rule.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @method getCategory()
3131
* @method Rule setCollectedAttributes($attributes)
3232
* @method getCollectedAttributes()
33+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3334
*/
3435
class Rule extends AbstractModel implements IdentityInterface
3536
{
@@ -152,6 +153,7 @@ class Rule extends AbstractModel implements IdentityInterface
152153
* @param AbstractResource|null $resource
153154
* @param AbstractDb|null $resourceCollection
154155
* @param mixed[] $data
156+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
155157
*/
156158
public function __construct(
157159
Context $context,

Model/Rule/Condition/Product.php

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@
66
namespace Faonni\SmartCategory\Model\Rule\Condition;
77

88
use Magento\Framework\Model\AbstractModel;
9+
use Magento\Framework\Model\ResourceModel\IteratorFactory;
10+
use Magento\Framework\Locale\FormatInterface;
11+
use Magento\Backend\Helper\Data as Helper;
12+
use Magento\Rule\Model\Condition\Context;
913
use Magento\Rule\Model\Condition\Product\AbstractProduct;
14+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection as AttrSetCollection;
15+
use Magento\Eav\Model\Config;
1016
use Magento\Store\Model\Store;
17+
use Magento\Catalog\Model\ProductFactory;
18+
use Magento\Catalog\Api\ProductRepositoryInterface;
19+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
20+
use Magento\Catalog\Model\ProductCategoryList;
1121

1222
/**
1323
* Product condition
@@ -16,16 +26,67 @@
1626
* @method getJsFormObject()
1727
* @method getAttributeOption()
1828
* @method getRule()
29+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1930
*/
2031
class Product extends AbstractProduct
2132
{
33+
/**
34+
* @var IteratorFactory
35+
*/
36+
protected $iteratorFactory;
37+
2238
/**
2339
* Attribute data key that indicates whether it should be used for rules
2440
*
2541
* @var string
2642
*/
2743
protected $_isUsedForRuleProperty = 'is_used_for_smart_rules';
2844

45+
/**
46+
* Initialize condition
47+
*
48+
* @param Context $context
49+
* @param Helper $backendData
50+
* @param Config $config
51+
* @param ProductFactory $productFactory
52+
* @param ProductRepositoryInterface $productRepository
53+
* @param ProductResource $productResource
54+
* @param AttrSetCollection $attrSetCollection
55+
* @param FormatInterface $localeFormat
56+
* @param IteratorFactory $iteratorFactory
57+
* @param mixed[] $data
58+
* @param ProductCategoryList|null $categoryList
59+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
60+
*/
61+
public function __construct(
62+
Context $context,
63+
Helper $backendData,
64+
Config $config,
65+
ProductFactory $productFactory,
66+
ProductRepositoryInterface $productRepository,
67+
ProductResource $productResource,
68+
AttrSetCollection $attrSetCollection,
69+
FormatInterface $localeFormat,
70+
IteratorFactory $iteratorFactory,
71+
array $data = [],
72+
ProductCategoryList $categoryList = null
73+
) {
74+
$this->iteratorFactory = $iteratorFactory;
75+
76+
parent::__construct(
77+
$context,
78+
$backendData,
79+
$config,
80+
$productFactory,
81+
$productRepository,
82+
$productResource,
83+
$attrSetCollection,
84+
$localeFormat,
85+
$data,
86+
$categoryList
87+
);
88+
}
89+
2990
/**
3091
* Retrieve value element chooser URL
3192
*
@@ -106,14 +167,12 @@ protected function setAttributeValue(AbstractModel $model)
106167
return $this;
107168
}
108169

109-
$productValues = $this->_entityAttributeValues[$model->getId()];
110-
170+
$productValues = $this->_entityAttributeValues[$model->getId()];
111171
if (!isset($productValues[$storeId]) && !isset($productValues[$defaultStoreId])) {
112172
return $this;
113173
}
114174

115-
$value = isset($productValues[$storeId]) ? $productValues[$storeId] : $productValues[$defaultStoreId];
116-
175+
$value = $productValues[$storeId] ?? $productValues[$defaultStoreId];
117176
$value = $this->prepareDatetimeValue($value, $model);
118177
$value = $this->prepareMultiselectValue($value, $model);
119178

@@ -157,4 +216,49 @@ protected function prepareMultiselectValue($value, AbstractModel $model)
157216
}
158217
return $value;
159218
}
219+
220+
/**
221+
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
222+
*
223+
* @return $this
224+
* @throws \Magento\Framework\Exception\LocalizedException
225+
* @SuppressWarnings(PHPMD.ElseExpression)
226+
*/
227+
public function collectValidatedAttributes($productCollection)
228+
{
229+
$attribute = $this->getAttribute();
230+
if ('category_ids' != $attribute) {
231+
$productCollection->addAttributeToSelect($attribute, 'left');
232+
if ($this->getAttributeObject()->isScopeGlobal()) {
233+
$attributes = $this->getRule()->getCollectedAttributes();
234+
$attributes[$attribute] = true;
235+
$this->getRule()->setCollectedAttributes($attributes);
236+
} else {
237+
$select = clone $productCollection->getSelect();
238+
$attributeModel = $productCollection->getEntity()->getAttribute($attribute);
239+
240+
$fieldMainTable = $productCollection->getConnection()->getAutoIncrementField($productCollection->getMainTable());
241+
$fieldJoinTable = $attributeModel->getEntity()->getLinkField();
242+
$select->reset()
243+
->from(
244+
['cpe' => $productCollection->getMainTable()],
245+
['entity_id']
246+
)->join(
247+
['cpa' => $attributeModel->getBackend()->getTable()],
248+
'cpe.' . $fieldMainTable . ' = cpa.' . $fieldJoinTable,
249+
['store_id', 'value']
250+
)->where('attribute_id = ?', (int)$attributeModel->getId());
251+
252+
$iterator = $this->iteratorFactory->create();
253+
$res = [];
254+
$iterator->walk((string)$select, [function (array $data) {
255+
$row = $data['row'];
256+
$res[$row['entity_id']][$row['store_id']] = $row['value'];
257+
}], [], $productCollection->getConnection());
258+
$this->_entityAttributeValues = $res;
259+
}
260+
}
261+
262+
return $this;
263+
}
160264
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "faonni/module-smart-category",
33
"description": "SmartCategory module is a base of Smart Categories functionality.",
44
"type": "magento2-module",
5-
"version": "2.3.2",
5+
"version": "2.3.3",
66
"authors": [
77
{
88
"name": "Karliuka Vitalii",

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10-
<module name="Faonni_SmartCategory" setup_version="2.3.2">
10+
<module name="Faonni_SmartCategory" setup_version="2.3.3">
1111
<sequence>
1212
<module name="Magento_Backend"/>
1313
<module name="Magento_Catalog"/>

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ parameters:
3838
- '#no value type specified in iterable type Magento\\Framework\\Data\\Collection\\AbstractDb.#'
3939
- '#no value type specified in iterable type Faonni\\SmartCategory\\Model\\ResourceModel\\Rule\\Collection.#'
4040
- '#no value type specified in iterable type Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection.#'
41+
- '#Cannot call method getBackend\(\) on Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute.#'
42+
- '#Cannot call method getEntity\(\) on Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute.#'
43+
- '#Cannot call method getId\(\) on Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute.#'

0 commit comments

Comments
 (0)