Skip to content

Commit 8c974d8

Browse files
committed
Merge remote-tracking branch 'origin/imported-magento-magento2-31352' into 2.4-develop-pr117
2 parents 5195384 + bc7f065 commit 8c974d8

File tree

6 files changed

+289
-1
lines changed

6 files changed

+289
-1
lines changed

app/code/Magento/Bundle/Pricing/Price/BundleSelectionFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ public function create(
5252
$quantity,
5353
array $arguments = []
5454
) {
55+
$quantity = $quantity ? (float)$quantity : 1.;
56+
$selection->setQty($quantity);
57+
5558
$arguments['bundleProduct'] = $bundleProduct;
5659
$arguments['saleableItem'] = $selection;
57-
$arguments['quantity'] = $quantity ? (float)$quantity : 1.;
60+
$arguments['quantity'] = $quantity;
5861

5962
return $this->objectManager->create(self::SELECTION_CLASS_DEFAULT, $arguments);
6063
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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\Bundle\Pricing\Price;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* 'Final Price' model integration tests.
17+
*
18+
* @magentoDbIsolation disabled
19+
*/
20+
class FinalPriceTest extends TestCase
21+
{
22+
/**
23+
* @var ProductRepositoryInterface
24+
*/
25+
private $productRepository;
26+
27+
/**
28+
* @var ObjectManagerInterface
29+
*/
30+
private $objectManager;
31+
32+
/**
33+
* @inheritDoc
34+
*/
35+
protected function setUp(): void
36+
{
37+
$this->objectManager = Bootstrap::getObjectManager();
38+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
39+
}
40+
41+
/**
42+
* Check minimal and maximal prices are calculated correctly for Bundle product selections with Tier Prices.
43+
*
44+
* @return void
45+
* @magentoDataFixture Magento/Bundle/_files/bundle_product_with_tier_price_selections.php
46+
*/
47+
public function testGetPriceForBundleSelectionsWithTierPrices(): void
48+
{
49+
$priceModel = $this->getPriceModel('bundle_with_tier_price_selections');
50+
$this->assertEquals(15.0, $priceModel->getMinimalPrice()->getValue());
51+
$this->assertEquals(45.0, $priceModel->getMaximalPrice()->getValue());
52+
}
53+
54+
/**
55+
* Create and retrieve Price Model for provided Product SKU.
56+
*
57+
* @param string $productSku
58+
* @return FinalPrice
59+
*/
60+
private function getPriceModel(string $productSku): FinalPrice
61+
{
62+
$bundleProduct = $this->productRepository->get($productSku);
63+
64+
return $this->objectManager->create(
65+
FinalPrice::class,
66+
[
67+
'saleableItem' => $bundleProduct,
68+
'quantity' => 0.,
69+
]
70+
);
71+
}
72+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
use Magento\Bundle\Model\Product\Price;
9+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\Catalog\Model\Product\Type;
13+
use Magento\Catalog\Model\Product\Type\AbstractType;
14+
use Magento\Catalog\Model\Product\Visibility;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
19+
20+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/three_simple_products_with_tier_price.php');
21+
22+
$objectManager = Bootstrap::getObjectManager();
23+
/** @var ProductRepositoryInterface $productRepository */
24+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
25+
/** @var ProductInterfaceFactory $productFactory */
26+
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
27+
/** @var PrepareBundleLinks $prepareBundleLinks */
28+
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
29+
/** @var StoreManagerInterface $storeManager */
30+
$storeManager = $objectManager->get(StoreManagerInterface::class);
31+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
32+
33+
$bundleProduct = $productFactory->create();
34+
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
35+
->setAttributeSetId($bundleProduct->getDefaultAttributeSetId())
36+
->setWebsiteIds([$defaultWebsiteId])
37+
->setName('Bundle Product')
38+
->setSku('bundle_with_tier_price_selections')
39+
->setVisibility(Visibility::VISIBILITY_BOTH)
40+
->setStatus(Status::STATUS_ENABLED)
41+
->setStockData(
42+
[
43+
'use_config_manage_stock' => 1,
44+
'qty' => 100,
45+
'is_qty_decimal' => 0,
46+
'is_in_stock' => 1,
47+
]
48+
)
49+
->setSkuType(0)
50+
->setPriceView(0)
51+
->setPriceType(Price::PRICE_TYPE_DYNAMIC)
52+
->setPrice(null)
53+
->setWeightType(0)
54+
->setShipmentType(AbstractType::SHIPMENT_TOGETHER);
55+
56+
$bundleOptionsData = [
57+
[
58+
'title' => 'Option 1',
59+
'default_title' => 'Option 1',
60+
'type' => 'select',
61+
'required' => 1,
62+
],
63+
];
64+
$bundleSelectionsData = [
65+
[
66+
[
67+
'sku' => 'simple_1',
68+
'selection_qty' => 3,
69+
],
70+
[
71+
'sku' => 'simple_2',
72+
'selection_qty' => 3,
73+
],
74+
[
75+
'sku' => 'simple_3',
76+
'selection_qty' => 3,
77+
],
78+
]
79+
];
80+
$bundleProduct = $prepareBundleLinks->execute($bundleProduct, $bundleOptionsData, $bundleSelectionsData);
81+
$productRepository->save($bundleProduct);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
13+
14+
Resolver::getInstance()
15+
->requireDataFixture('Magento/Catalog/_files/three_simple_products_with_tier_price_rollback.php');
16+
17+
$objectManager = Bootstrap::getObjectManager();
18+
/** @var Registry $registry */
19+
$registry = $objectManager->get(Registry::class);
20+
$registry->unregister('isSecureArea');
21+
$registry->register('isSecureArea', true);
22+
23+
/** @var ProductRepositoryInterface $productRepository */
24+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
25+
try {
26+
$product = $productRepository->get('bundle_with_tier_price_selections', false, null, true);
27+
$productRepository->delete($product);
28+
} catch (NoSuchEntityException $e) {
29+
//Product already removed
30+
}
31+
32+
$registry->unregister('isSecureArea');
33+
$registry->register('isSecureArea', false);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory;
9+
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
13+
use Magento\Catalog\Model\Product\Type;
14+
use Magento\Catalog\Model\Product\Visibility;
15+
use Magento\Customer\Model\Group;
16+
use Magento\Store\Api\Data\WebsiteInterface;
17+
use Magento\Store\Api\WebsiteRepositoryInterface;
18+
use Magento\TestFramework\Helper\Bootstrap;
19+
20+
$objectManager = Bootstrap::getObjectManager();
21+
/** @var ProductTierPriceInterfaceFactory $tierPriceFactory */
22+
$tierPriceFactory = $objectManager->get(ProductTierPriceInterfaceFactory::class);
23+
/** @var ProductTierPriceExtensionFactory $tpExtensionAttributes */
24+
$tpExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class);
25+
26+
/** @var WebsiteInterface $adminWebsite */
27+
$adminWebsite = $objectManager->get(WebsiteRepositoryInterface::class)->get('admin');
28+
$tierPriceExtensionAttributes = $tpExtensionAttributesFactory->create()
29+
->setWebsiteId($adminWebsite->getId())
30+
->setPercentageValue(50);
31+
32+
$tierPrice = $tierPriceFactory->create(
33+
[
34+
'data' => [
35+
'customer_group_id' => Group::CUST_GROUP_ALL,
36+
'qty' => 2,
37+
],
38+
]
39+
)->setExtensionAttributes($tierPriceExtensionAttributes);
40+
41+
/** @var ProductRepositoryInterface $productRepository */
42+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
43+
$productNumber = 1;
44+
foreach ([10, 20, 30] as $price) {
45+
/** @var $product Product */
46+
$product = $objectManager->create(Product::class);
47+
$product->setTypeId(Type::TYPE_SIMPLE)
48+
->setAttributeSetId($product->getDefaultAttributeSetId())
49+
->setWebsiteIds([1])
50+
->setName('Simple Product ' . $productNumber)
51+
->setSku('simple_' . $productNumber)
52+
->setPrice($price)
53+
->setWeight(1)
54+
->setTierPrices([$tierPrice])
55+
->setVisibility(Visibility::VISIBILITY_BOTH)
56+
->setStatus(Status::STATUS_ENABLED)
57+
->setStockData(
58+
[
59+
'use_config_manage_stock' => 1,
60+
'qty' => 100,
61+
'is_qty_decimal' => 0,
62+
'is_in_stock' => 1,
63+
]
64+
);
65+
66+
$productRepository->save($product);
67+
$productNumber++;
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Framework\Registry;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
/** @var Registry $registry */
15+
$registry = $objectManager->get(Registry::class);
16+
$registry->unregister('isSecureArea');
17+
$registry->register('isSecureArea', true);
18+
19+
/** @var ProductRepositoryInterface $productRepository */
20+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
21+
foreach (['simple_1', 'simple_2', 'simple_3'] as $sku) {
22+
try {
23+
$product = $productRepository->get($sku, false, null, true);
24+
$productRepository->delete($product);
25+
} catch (NoSuchEntityException $e) {
26+
//Product already removed
27+
}
28+
}
29+
30+
$registry->unregister('isSecureArea');
31+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)