Skip to content

Commit 96b7766

Browse files
authored
Merge pull request #694 from adobe-commerce-tier-4/PR_2026_02_03_muntianu
[Support Tier-4 muntianu] 02-03-2026 Regular delivery of bugfixes and improvements
2 parents e091465 + e064529 commit 96b7766

2 files changed

Lines changed: 128 additions & 3 deletions

File tree

InventoryBundleProduct/Plugin/InventorySales/Model/IsProductSalableCondition/GetIsQtySalableForBundleProduct.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ public function afterExecute(
5353
string $sku,
5454
int $stockId
5555
): bool {
56-
return $isSalable && $this->getProductTypesBySkus->execute([$sku])[$sku] === Type::TYPE_CODE
57-
? $this->isBundleProductChildrenSalable->execute($sku, $stockId)
58-
: $isSalable;
56+
if ($this->getProductTypesBySkus->execute([$sku])[$sku] === Type::TYPE_CODE) {
57+
$isSalable = $this->isBundleProductChildrenSalable->execute($sku, $stockId);
58+
}
59+
return $isSalable;
5960
}
6061
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright 2026 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventoryBundleProduct\Test\Unit\Plugin\InventorySales\Model\IsProductSalableCondition;
9+
10+
use Magento\Bundle\Model\Product\Type;
11+
use Magento\InventoryBundleProduct\Model\IsBundleProductChildrenSalable;
12+
// phpcs:disable
13+
use Magento\InventoryBundleProduct\Plugin\InventorySales\Model\IsProductSalableCondition\GetIsQtySalableForBundleProduct;
14+
// phpcs:enable
15+
use Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface;
16+
use Magento\InventorySalesApi\Model\GetIsQtySalableInterface;
17+
use PHPUnit\Framework\Attributes\DataProvider;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
class GetIsQtySalableForBundleProductTest extends TestCase
22+
{
23+
/**
24+
* @var IsBundleProductChildrenSalable|MockObject
25+
*/
26+
private $isBundleProductChildrenSalable;
27+
28+
/**
29+
* @var GetProductTypesBySkusInterface|MockObject
30+
*/
31+
private $getProductTypesBySkus;
32+
33+
/**
34+
* @var GetIsQtySalableInterface|MockObject
35+
*/
36+
private $subject;
37+
38+
/**
39+
* @var GetIsQtySalableForBundleProduct
40+
*/
41+
private $model;
42+
43+
protected function setUp(): void
44+
{
45+
$this->isBundleProductChildrenSalable = $this->createMock(IsBundleProductChildrenSalable::class);
46+
$this->getProductTypesBySkus = $this->createMock(GetProductTypesBySkusInterface::class);
47+
$this->subject = $this->createMock(GetIsQtySalableInterface::class);
48+
49+
$this->model = new GetIsQtySalableForBundleProduct(
50+
$this->isBundleProductChildrenSalable,
51+
$this->getProductTypesBySkus
52+
);
53+
}
54+
55+
/**
56+
* @param string $sku
57+
* @param int $stockId
58+
* @param string $type
59+
* @param bool $isSalable
60+
* @param int $num
61+
* @param bool $expected
62+
* @return void
63+
*/
64+
#[DataProvider('salabilityDataProvider')]
65+
public function testAfterExecute(
66+
string $sku,
67+
int $stockId,
68+
string $type,
69+
bool $isSalable,
70+
int $num,
71+
bool $expected
72+
): void {
73+
$this->getProductTypesBySkus->expects($this->once())
74+
->method('execute')
75+
->with([$sku])
76+
->willReturn([$sku => $type]);
77+
$this->isBundleProductChildrenSalable->expects($this->exactly($num))
78+
->method('execute')
79+
->with($sku, $stockId)
80+
->willReturn(true);
81+
$this->assertSame(
82+
$expected,
83+
$this->model->afterExecute($this->subject, $isSalable, $sku, $stockId)
84+
);
85+
}
86+
87+
public static function salabilityDataProvider() : array
88+
{
89+
return [
90+
[
91+
'sku' => 'bundle-test',
92+
'stockId' => 1,
93+
'type' => Type::TYPE_CODE,
94+
'isSalable' => false,
95+
'num' => 1,
96+
'expected' => true
97+
],
98+
[
99+
'sku' => 'bundle-test',
100+
'stockId' => 1,
101+
'type' => Type::TYPE_CODE,
102+
'isSalable' => true,
103+
'num' => 1,
104+
'expected' => true
105+
],
106+
[
107+
'sku' => 'simple',
108+
'stockId' => 1,
109+
'type' => 'simple',
110+
'isSalable' => false,
111+
'num' => 0,
112+
'expected' => false
113+
],
114+
[
115+
'sku' => 'simple',
116+
'stockId' => 1,
117+
'type' => 'simple',
118+
'isSalable' => true,
119+
'num' => 0,
120+
'expected' => true
121+
],
122+
];
123+
}
124+
}

0 commit comments

Comments
 (0)