Skip to content

Commit 577b3b3

Browse files
committed
Merge remote-tracking branch 'origin/MC-33427' into 2.4-develop-pr23
2 parents e9ad350 + e2474c2 commit 577b3b3

File tree

4 files changed

+145
-2
lines changed

4 files changed

+145
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MsrpGroupedProduct\Plugin\Model\Product\Type;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Link\Product\Collection;
11+
12+
/**
13+
* Minimum advertised price plugin for grouped product
14+
*/
15+
class Grouped
16+
{
17+
/**
18+
* Add minimum advertised price to the attribute selection for associated products
19+
*
20+
* @param \Magento\GroupedProduct\Model\Product\Type\Grouped $subject
21+
* @param Collection $collection
22+
* @return Collection
23+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
24+
*/
25+
public function afterGetAssociatedProductCollection(
26+
\Magento\GroupedProduct\Model\Product\Type\Grouped $subject,
27+
Collection $collection
28+
): Collection {
29+
$collection->addAttributeToSelect(['msrp']);
30+
return $collection;
31+
}
32+
}

app/code/Magento/MsrpGroupedProduct/Pricing/MsrpPriceCalculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ public function getMsrpPriceValue(ProductInterface $product): float
3131
/** @var Grouped $groupedProduct */
3232
$groupedProduct = $product->getTypeInstance();
3333

34-
return $groupedProduct->getChildrenMsrp($product);
34+
return (float) $groupedProduct->getChildrenMsrp($product);
3535
}
3636
}

app/code/Magento/MsrpGroupedProduct/etc/di.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
</argument>
1717
</arguments>
1818
</type>
19-
</config>
19+
<type name="\Magento\GroupedProduct\Model\Product\Type\Grouped">
20+
<plugin name="grouped_product_minimum_advertised_price" type="\Magento\MsrpGroupedProduct\Plugin\Model\Product\Type\Grouped"/>
21+
</type>
22+
</config>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MsrpGroupedProduct\Pricing;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* Test group product minimum advertised price model
17+
*/
18+
class MsrpPriceCalculatorTest extends TestCase
19+
{
20+
/**
21+
* @var ProductRepositoryInterface
22+
*/
23+
private $productRepository;
24+
/**
25+
* @var MsrpPriceCalculator
26+
*/
27+
private $model;
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
protected function setUp()
33+
{
34+
parent::setUp();
35+
$objectManager = Bootstrap::getObjectManager();
36+
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
37+
$this->model = $objectManager->get(MsrpPriceCalculator::class);
38+
}
39+
40+
/**
41+
* Test grouped product minimum advertised price
42+
*
43+
* @magentoAppIsolation enabled
44+
* @magentoDataFixture Magento/GroupedProduct/_files/product_grouped.php
45+
* @dataProvider getMsrpPriceValueDataProvider
46+
* @param float|null $simpleProductPriceMsrp
47+
* @param float|null $virtualProductMsrp
48+
* @param float|null $expectedMsrp
49+
*/
50+
public function testGetMsrpPriceValue(
51+
?float $simpleProductPriceMsrp,
52+
?float $virtualProductMsrp,
53+
?float $expectedMsrp
54+
): void {
55+
$this->setProductMinimumAdvertisedPrice('simple', $simpleProductPriceMsrp);
56+
$this->setProductMinimumAdvertisedPrice('virtual-product', $virtualProductMsrp);
57+
$groupedProduct = $this->getProduct('grouped-product');
58+
$this->assertEquals($expectedMsrp, $this->model->getMsrpPriceValue($groupedProduct));
59+
}
60+
61+
/**
62+
* Set product minimum advertised price by sku
63+
*
64+
* @param string $sku
65+
* @param float|null $msrp
66+
*/
67+
private function setProductMinimumAdvertisedPrice(string $sku, ?float $msrp): void
68+
{
69+
$product = $this->getProduct($sku);
70+
$product->setMsrp($msrp);
71+
$this->productRepository->save($product);
72+
}
73+
74+
/**
75+
* Get product by sku
76+
*
77+
* @param string $sku
78+
* @return ProductInterface
79+
*/
80+
private function getProduct(string $sku): ProductInterface
81+
{
82+
return $this->productRepository->get($sku, false, null, true);
83+
}
84+
85+
/**
86+
* @return array
87+
*/
88+
public function getMsrpPriceValueDataProvider(): array
89+
{
90+
return [
91+
[
92+
12.0,
93+
8.0,
94+
8.0
95+
],
96+
[
97+
12.0,
98+
null,
99+
12.0
100+
],
101+
[
102+
null,
103+
null,
104+
0.0
105+
]
106+
];
107+
}
108+
}

0 commit comments

Comments
 (0)