Skip to content

Commit 5e3ef31

Browse files
Merge remote-tracking branch '30479/2.4-develop' into Aug01-comprs
2 parents f3d02cf + 5cd6c95 commit 5e3ef31

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright 2017 Adobe
3+
* Copyright 2013 Adobe
44
* All Rights Reserved.
55
*/
66
namespace Magento\SalesRule\Model\Rule\Condition;
@@ -65,9 +65,8 @@ public function loadAttributeOptions()
6565
$attributes = [];
6666
foreach ($productAttributes as $attribute) {
6767
/* @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
68-
if (!$attribute->isAllowedForRuleCondition()
69-
|| !$attribute->getDataUsingMethod($this->_isUsedForRuleProperty)
70-
) {
68+
if (!$attribute->getDataUsingMethod($this->_isUsedForRuleProperty)
69+
|| !$attribute->isAllowedForRuleCondition()) {
7170
continue;
7271
}
7372
$frontLabel = $attribute->getFrontendLabel();

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

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2016 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Catalog\Model\ProductCategoryList;
1313
use Magento\Catalog\Model\ProductFactory;
14+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1415
use Magento\Catalog\Model\ResourceModel\Product;
1516
use Magento\Directory\Model\CurrencyFactory;
1617
use Magento\Eav\Model\Config;
@@ -322,6 +323,73 @@ public function testQuoteLocaleFormatPrice($isValid, $conditionValue, $operator
322323
$this->assertEquals($isValid, $this->model->setValue($conditionValue)->validate($item));
323324
}
324325

326+
/**
327+
* Test for loadAttributeOptions
328+
*
329+
* @return void
330+
*/
331+
public function testLoadAttributeOptions(): void
332+
{
333+
$secondAttributeCode = 'second_attribute';
334+
335+
$attribute = $this->getMockBuilder(Attribute::class)
336+
->onlyMethods(['getDataUsingMethod'])
337+
->disableOriginalConstructor()
338+
->getMock();
339+
$attribute->expects($this->atLeastOnce())
340+
->method('getDataUsingMethod')
341+
->with('is_used_for_promo_rules')
342+
->willReturn(false);
343+
344+
$attributeSecond = $this->getMockBuilder(Attribute::class)
345+
->onlyMethods(['getDataUsingMethod', 'isAllowedForRuleCondition', 'getAttributeCode'])
346+
->addMethods(['getFrontendLabel'])
347+
->disableOriginalConstructor()
348+
->getMock();
349+
$attributeSecond->expects($this->atLeastOnce())
350+
->method('getDataUsingMethod')
351+
->with('is_used_for_promo_rules')
352+
->willReturn(true);
353+
$attributeSecond->expects($this->atLeastOnce())
354+
->method('isAllowedForRuleCondition')
355+
->willReturn(true);
356+
$attributeSecond->expects($this->atLeastOnce())
357+
->method('getFrontendLabel')
358+
->willReturn('Second Attribute');
359+
$attributeSecond->expects($this->atLeastOnce())
360+
->method('getAttributeCode')
361+
->willReturn($secondAttributeCode);
362+
363+
$attributeLoaderInterfaceMock = $this->createMock(AbstractEntity::class);
364+
$attributeLoaderInterfaceMock->expects($this->atLeastOnce())
365+
->method('getAttributesByCode')
366+
->willReturn([$attribute, $attributeSecond]);
367+
368+
$productResourceMock = $this->createMock(Product::class);
369+
$productResourceMock->expects($this->atLeastOnce())
370+
->method('loadAllAttributes')
371+
->willReturn($attributeLoaderInterfaceMock);
372+
373+
$model = new SalesRuleProduct(
374+
$this->contextMock,
375+
$this->backendHelperMock,
376+
$this->configMock,
377+
$this->productFactoryMock,
378+
$this->productRepositoryMock,
379+
$productResourceMock,
380+
$this->collectionMock,
381+
$this->format,
382+
[],
383+
$this->productCategoryListMock
384+
);
385+
386+
$model->loadAttributeOptions();
387+
388+
$this->assertArrayHasKey($secondAttributeCode, $model->getAttributeOption());
389+
$this->assertArrayHasKey('children::' . $secondAttributeCode, $model->getAttributeOption());
390+
$this->assertArrayHasKey('parent::' . $secondAttributeCode, $model->getAttributeOption());
391+
}
392+
325393
/**
326394
* DataProvider for testQuoteLocaleFormatPrice
327395
*

0 commit comments

Comments
 (0)