Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
karliuka committed Oct 31, 2021
2 parents aab5dcf + dfea6d1 commit 694884f
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 9 deletions.
8 changes: 5 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ repos:
- id: check-json
- id: pretty-format-json
args: ["--indent=4", "--autofix", "--no-sort-keys"]
- repo: https://github.com/eriocnemis/git.MagentoPreCommitHooks
rev: 1.0.7
- repo: https://github.com/eriocnemis/git.magento_pre_commit_hooks
rev: 1.0.10
hooks:
- id: magento-xml
- id: magento-phpcs
# - id: magento-phpmd
args: ["--autofix"]
- id: magento-phpmd
- id: magento-phpcpd
- id: magento-phpstan
2 changes: 2 additions & 0 deletions Model/Indexer/IndexBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

/**
* Rule index builder
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexBuilder
{
Expand Down
2 changes: 2 additions & 0 deletions Model/Indexer/Product/ProductRuleProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ProductRuleProcessor extends AbstractProcessor
* @param int $id
* @param bool $forceReindex
* @return void
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function reindexRow($id, $forceReindex = false)
{
Expand All @@ -39,6 +40,7 @@ public function reindexRow($id, $forceReindex = false)
* @param int[] $ids
* @param bool $forceReindex
* @return void
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function reindexList($ids, $forceReindex = false)
{
Expand Down
2 changes: 2 additions & 0 deletions Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @method getCategory()
* @method Rule setCollectedAttributes($attributes)
* @method getCollectedAttributes()
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Rule extends AbstractModel implements IdentityInterface
{
Expand Down Expand Up @@ -152,6 +153,7 @@ class Rule extends AbstractModel implements IdentityInterface
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param mixed[] $data
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Expand Down
112 changes: 108 additions & 4 deletions Model/Rule/Condition/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@
namespace Faonni\SmartCategory\Model\Rule\Condition;

use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\ResourceModel\IteratorFactory;
use Magento\Framework\Locale\FormatInterface;
use Magento\Backend\Helper\Data as Helper;
use Magento\Rule\Model\Condition\Context;
use Magento\Rule\Model\Condition\Product\AbstractProduct;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection as AttrSetCollection;
use Magento\Eav\Model\Config;
use Magento\Store\Model\Store;
use Magento\Catalog\Model\ProductFactory;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
use Magento\Catalog\Model\ProductCategoryList;

/**
* Product condition
Expand All @@ -16,16 +26,67 @@
* @method getJsFormObject()
* @method getAttributeOption()
* @method getRule()
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Product extends AbstractProduct
{
/**
* @var IteratorFactory
*/
protected $iteratorFactory;

/**
* Attribute data key that indicates whether it should be used for rules
*
* @var string
*/
protected $_isUsedForRuleProperty = 'is_used_for_smart_rules';

/**
* Initialize condition
*
* @param Context $context
* @param Helper $backendData
* @param Config $config
* @param ProductFactory $productFactory
* @param ProductRepositoryInterface $productRepository
* @param ProductResource $productResource
* @param AttrSetCollection $attrSetCollection
* @param FormatInterface $localeFormat
* @param IteratorFactory $iteratorFactory
* @param mixed[] $data
* @param ProductCategoryList|null $categoryList
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Context $context,
Helper $backendData,
Config $config,
ProductFactory $productFactory,
ProductRepositoryInterface $productRepository,
ProductResource $productResource,
AttrSetCollection $attrSetCollection,
FormatInterface $localeFormat,
IteratorFactory $iteratorFactory,
array $data = [],
ProductCategoryList $categoryList = null
) {
$this->iteratorFactory = $iteratorFactory;

parent::__construct(
$context,
$backendData,
$config,
$productFactory,
$productRepository,
$productResource,
$attrSetCollection,
$localeFormat,
$data,
$categoryList
);
}

/**
* Retrieve value element chooser URL
*
Expand Down Expand Up @@ -106,14 +167,12 @@ protected function setAttributeValue(AbstractModel $model)
return $this;
}

$productValues = $this->_entityAttributeValues[$model->getId()];

$productValues = $this->_entityAttributeValues[$model->getId()];
if (!isset($productValues[$storeId]) && !isset($productValues[$defaultStoreId])) {
return $this;
}

$value = isset($productValues[$storeId]) ? $productValues[$storeId] : $productValues[$defaultStoreId];

$value = $productValues[$storeId] ?? $productValues[$defaultStoreId];
$value = $this->prepareDatetimeValue($value, $model);
$value = $this->prepareMultiselectValue($value, $model);

Expand Down Expand Up @@ -157,4 +216,49 @@ protected function prepareMultiselectValue($value, AbstractModel $model)
}
return $value;
}

/**
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
*
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.ElseExpression)
*/
public function collectValidatedAttributes($productCollection)
{
$attribute = $this->getAttribute();
if ('category_ids' != $attribute) {
$productCollection->addAttributeToSelect($attribute, 'left');
if ($this->getAttributeObject()->isScopeGlobal()) {
$attributes = $this->getRule()->getCollectedAttributes();
$attributes[$attribute] = true;
$this->getRule()->setCollectedAttributes($attributes);
} else {
$select = clone $productCollection->getSelect();
$attributeModel = $productCollection->getEntity()->getAttribute($attribute);

$fieldMainTable = $productCollection->getConnection()->getAutoIncrementField($productCollection->getMainTable());
$fieldJoinTable = $attributeModel->getEntity()->getLinkField();
$select->reset()
->from(
['cpe' => $productCollection->getMainTable()],
['entity_id']
)->join(
['cpa' => $attributeModel->getBackend()->getTable()],
'cpe.' . $fieldMainTable . ' = cpa.' . $fieldJoinTable,
['store_id', 'value']
)->where('attribute_id = ?', (int)$attributeModel->getId());

$iterator = $this->iteratorFactory->create();
$res = [];
$iterator->walk((string)$select, [function (array $data) {
$row = $data['row'];
$res[$row['entity_id']][$row['store_id']] = $row['value'];
}], [], $productCollection->getConnection());
$this->_entityAttributeValues = $res;
}
}

return $this;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "faonni/module-smart-category",
"description": "SmartCategory module is a base of Smart Categories functionality.",
"type": "magento2-module",
"version": "2.3.2",
"version": "2.3.3",
"authors": [
{
"name": "Karliuka Vitalii",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Faonni_SmartCategory" setup_version="2.3.2">
<module name="Faonni_SmartCategory" setup_version="2.3.3">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Catalog"/>
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ parameters:
- '#no value type specified in iterable type Magento\\Framework\\Data\\Collection\\AbstractDb.#'
- '#no value type specified in iterable type Faonni\\SmartCategory\\Model\\ResourceModel\\Rule\\Collection.#'
- '#no value type specified in iterable type Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection.#'
- '#Cannot call method getBackend\(\) on Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute.#'
- '#Cannot call method getEntity\(\) on Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute.#'
- '#Cannot call method getId\(\) on Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute.#'

0 comments on commit 694884f

Please sign in to comment.