| 
 | 1 | +diff --git a/vendor/magento/module-advanced-sales-rule/Model/Rule/Condition/FilterTextGenerator/Product/Attribute.php b/vendor/magento/module-advanced-sales-rule/Model/Rule/Condition/FilterTextGenerator/Product/Attribute.php  | 
 | 2 | +index 4e90156..cd2b85f 100644  | 
 | 3 | +--- a/vendor/magento/module-advanced-sales-rule/Model/Rule/Condition/FilterTextGenerator/Product/Attribute.php  | 
 | 4 | ++++ b/vendor/magento/module-advanced-sales-rule/Model/Rule/Condition/FilterTextGenerator/Product/Attribute.php  | 
 | 5 | +@@ -7,6 +7,10 @@ namespace Magento\AdvancedSalesRule\Model\Rule\Condition\FilterTextGenerator\Pro  | 
 | 6 | +   | 
 | 7 | + use Magento\AdvancedSalesRule\Model\Rule\Condition\ConcreteCondition\Product\Attribute as AttributeCondition;  | 
 | 8 | + use Magento\AdvancedRule\Model\Condition\FilterTextGeneratorInterface;  | 
 | 9 | ++use Magento\Catalog\Model\Product;  | 
 | 10 | ++use Magento\Eav\Model\Config;  | 
 | 11 | ++use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;  | 
 | 12 | ++use Magento\Framework\Locale\FormatInterface;  | 
 | 13 | +   | 
 | 14 | + class Attribute implements FilterTextGeneratorInterface  | 
 | 15 | + {  | 
 | 16 | +@@ -16,28 +20,48 @@ class Attribute implements FilterTextGeneratorInterface  | 
 | 17 | +     protected $attributeCode;  | 
 | 18 | +   | 
 | 19 | +     /**  | 
 | 20 | ++     * @var FormatInterface  | 
 | 21 | ++     */  | 
 | 22 | ++    private FormatInterface $localeFormat;  | 
 | 23 | ++  | 
 | 24 | ++    /**  | 
 | 25 | ++     * @var Config  | 
 | 26 | ++     */  | 
 | 27 | ++    private Config $config;  | 
 | 28 | ++  | 
 | 29 | ++    /**  | 
 | 30 | +      * @param array $data  | 
 | 31 | ++     * @param Config $config  | 
 | 32 | ++     * @param FormatInterface $localeFormat  | 
 | 33 | +      */  | 
 | 34 | +-    public function __construct(array $data)  | 
 | 35 | +-    {  | 
 | 36 | ++    public function __construct(  | 
 | 37 | ++        array $data,  | 
 | 38 | ++        Config $config,  | 
 | 39 | ++        FormatInterface $localeFormat  | 
 | 40 | ++    ) {  | 
 | 41 | +         $this->attributeCode = $data['attribute'];  | 
 | 42 | ++        $this->config = $config;  | 
 | 43 | ++        $this->localeFormat = $localeFormat;  | 
 | 44 | +     }  | 
 | 45 | +   | 
 | 46 | +     /**  | 
 | 47 | +-     * @param \Magento\Framework\DataObject $quoteAddress  | 
 | 48 | +-     * @return string[]  | 
 | 49 | ++     * @inheritdoc  | 
 | 50 | +      */  | 
 | 51 | +     public function generateFilterText(\Magento\Framework\DataObject $quoteAddress)  | 
 | 52 | +     {  | 
 | 53 | +         $filterText = [];  | 
 | 54 | +         if ($quoteAddress instanceof \Magento\Quote\Model\Quote\Address) {  | 
 | 55 | +             $items = $quoteAddress->getAllItems();  | 
 | 56 | ++            $attribute = $this->getAttributeObject();  | 
 | 57 | +             foreach ($items as $item) {  | 
 | 58 | +                 $product = $item->getProduct();  | 
 | 59 | +                 if (!$product->hasData($this->attributeCode)) {  | 
 | 60 | +                     $product->load($product->getId());  | 
 | 61 | +                 }  | 
 | 62 | +                 $value = $product->getData($this->attributeCode);  | 
 | 63 | ++                if ($attribute && $attribute->getBackendType() === 'decimal') {  | 
 | 64 | ++                    $value = $this->localeFormat->getNumber($value);  | 
 | 65 | ++                }  | 
 | 66 | +                 if (is_scalar($value)) {  | 
 | 67 | +                     $text = AttributeCondition::FILTER_TEXT_PREFIX . $this->attributeCode . ':' . $value;  | 
 | 68 | +                     if (!in_array($text, $filterText)) {  | 
 | 69 | +@@ -48,4 +72,20 @@ class Attribute implements FilterTextGeneratorInterface  | 
 | 70 | +         }  | 
 | 71 | +         return $filterText;  | 
 | 72 | +     }  | 
 | 73 | ++  | 
 | 74 | ++    /**  | 
 | 75 | ++     * Retrieve attribute object  | 
 | 76 | ++     *  | 
 | 77 | ++     * @return ?AbstractAttribute  | 
 | 78 | ++     */  | 
 | 79 | ++    private function getAttributeObject(): ?AbstractAttribute  | 
 | 80 | ++    {  | 
 | 81 | ++        try {  | 
 | 82 | ++            $attributeObject = $this->config->getAttribute(Product::ENTITY, $this->attributeCode);  | 
 | 83 | ++        } catch (\Exception $e) {  | 
 | 84 | ++            $attributeObject = null;  | 
 | 85 | ++        }  | 
 | 86 | ++  | 
 | 87 | ++        return $attributeObject;  | 
 | 88 | ++    }  | 
 | 89 | + }  | 
0 commit comments