Skip to content

Commit 04ba59c

Browse files
committed
Merge branch 'ACP2E-3842' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-05-01-2025
2 parents 1e14bd7 + 6fc1122 commit 04ba59c

File tree

2 files changed

+97
-3
lines changed
  • app/code/Magento/SalesRule/Model/Rule/Condition/Product
  • dev/tests/integration/testsuite/Magento/SalesRule/Model/Rule/Condition/Product

2 files changed

+97
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ private function validateSubSelectConditions(mixed $item): bool
207207
*
208208
* @param mixed $item
209209
* @param mixed $attr
210-
* @param int $total
211-
* @return int|mixed
210+
* @param float $total
211+
* @return float
212212
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
213213
*/
214-
private function getBaseRowTotalForChildrenProduct(mixed $item, mixed $attr, int $total): mixed
214+
private function getBaseRowTotalForChildrenProduct(mixed $item, mixed $attr, float $total): float
215215
{
216216
$hasValidChild = false;
217217
$useChildrenTotal = ($item->getProductType() == Type::TYPE_BUNDLE);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Model\Rule\Condition\Product;
9+
10+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
11+
use Magento\Customer\Test\Fixture\Customer;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Quote\Test\Fixture\AddProductToCart;
14+
use Magento\Quote\Test\Fixture\CustomerCart;
15+
use Magento\TestFramework\Fixture\DataFixture;
16+
use Magento\Catalog\Api\ProductRepositoryInterface;
17+
use Magento\SalesRule\Model\Rule\Condition\Product as SalesRuleProduct;
18+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
use PHPUnit\Framework\TestCase;
21+
22+
/**
23+
* Integration test for Subselect::validate() method returning true.
24+
*
25+
* @magentoAppArea frontend
26+
*/
27+
class SubselectTest extends TestCase
28+
{
29+
/**
30+
* @var ObjectManagerInterface
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var Subselect
36+
*/
37+
private $subselectCondition;
38+
39+
/**
40+
* @var \Magento\Catalog\Api\ProductRepositoryInterface
41+
*/
42+
protected $productRepository;
43+
44+
protected function setUp(): void
45+
{
46+
$this->objectManager = Bootstrap::getObjectManager();
47+
$this->subselectCondition = $this->objectManager->create(Subselect::class);
48+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
49+
}
50+
51+
/**
52+
* Test validate() method returning true for total quantity >= 2 with single shipping.
53+
*
54+
*/
55+
#[
56+
DataFixture(Customer::class, as: 'customer'),
57+
DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], 'quote'),
58+
DataFixture(ProductFixture::class, ['sku' => 'simple1', 'price' => 100.50], as: 'product'),
59+
DataFixture(
60+
AddProductToCart::class,
61+
['cart_id' => '$quote.id$', 'product_id' => '$product.id$', 'qty' => 2],
62+
'item'
63+
),
64+
]
65+
public function testValidateReturnsTrueForSufficientQuantity()
66+
{
67+
$this->subselectCondition->setData([
68+
'attribute' => 'qty',
69+
'operator' => '>=',
70+
'value' => 2,
71+
'aggregator' => 'all',
72+
]);
73+
$productCondition = $this->objectManager->create(SalesRuleProduct::class);
74+
$productCondition->setData([
75+
'attribute' => 'sku',
76+
'operator' => '==',
77+
'value' => 'simple1',
78+
]);
79+
$this->subselectCondition->setConditions([$productCondition]);
80+
$product = $this->productRepository->get('simple1');
81+
$this->assertNotNull($product->getId());
82+
$quote = DataFixtureStorageManager::getStorage()->get('quote');
83+
$quote->setStoreId(1)->setIsActive(true)->setIsMultiShipping(false);
84+
$this->assertNotNull($quote->getId());
85+
$this->assertNotEmpty($quote->getAllVisibleItems());
86+
$quoteItem = $quote->getAllVisibleItems()[0];
87+
$this->assertNotNull($quoteItem);
88+
$this->assertNotNull($quoteItem->getProduct());
89+
$this->assertEquals(2, $quoteItem->getQty());
90+
$this->assertNotNull($quoteItem->getQuote());
91+
$result = $this->subselectCondition->validate($quoteItem);
92+
$this->assertTrue($result);
93+
}
94+
}

0 commit comments

Comments
 (0)