Skip to content

Commit 66e8fff

Browse files
committed
MC-30160: Indexer price calculation for fixed/dynamic bundle product with different type prices
1 parent ee8e5e2 commit 66e8fff

10 files changed

+315
-355
lines changed

dev/tests/integration/testsuite/Magento/Bundle/Model/Product/PriceTest.php

Lines changed: 207 additions & 332 deletions
Large diffs are not rendered by default.

dev/tests/integration/testsuite/Magento/Bundle/_files/dynamic_bundle_product_with_catalog_rule.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717
use Magento\CatalogRule\Model\Rule\Condition\Combine;
1818
use Magento\CatalogRule\Model\Rule\Condition\Product;
1919
use Magento\Customer\Model\Group;
20-
use Magento\Store\Api\WebsiteRepositoryInterface;
2120
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
2221

2322
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products.php';
2423

25-
/** @var WebsiteRepositoryInterface $websiteRepository */
26-
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
27-
$defaultWebsiteId = $websiteRepository->get('base')->getId();
2824
/** @var PrepareBundleLinks $prepareBundleLinks */
2925
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
3026
/** @var RuleInterfaceFactory $catalogRuleFactory */
@@ -33,11 +29,12 @@
3329
$catalogRuleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
3430
/** @var IndexBuilder $indexBuilder */
3531
$indexBuilder = $objectManager->get(IndexBuilder::class);
32+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
3633

3734
$category = $categoryFactory->create();
3835
$category->isObjectNew(true);
3936
$category->setName('Category with bundle product and rule')
40-
->setParentId(2)
37+
->setParentId($categoryHelper->getId())
4138
->setIsActive(true)
4239
->setPosition(1);
4340
$category = $categoryRepository->save($category);

dev/tests/integration/testsuite/Magento/Bundle/_files/dynamic_bundle_product_with_catalog_rule_rollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}
4242

4343
$ruleCollection = $ruleCollectionFactory->create();
44-
$ruleCollection->addFieldToFilter('name', ['eq' => 'Rule for bundle product']);
44+
$ruleCollection->addFieldToFilter('name', 'Rule for bundle product');
4545
$ruleCollection->setPageSize(1);
4646
$catalogRule = $ruleCollection->getFirstItem();
4747

dev/tests/integration/testsuite/Magento/Bundle/_files/dynamic_bundle_product_with_special_price.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
use Magento\Catalog\Model\Product\Type;
1111
use Magento\Catalog\Model\Product\Type\AbstractType;
1212
use Magento\Catalog\Model\Product\Visibility;
13-
use Magento\Store\Api\WebsiteRepositoryInterface;
1413
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
1514

1615
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products.php';
1716

18-
/** @var WebsiteRepositoryInterface $websiteRepository */
19-
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
20-
$defaultWebsiteId = $websiteRepository->get('base')->getId();
2117
/** @var PrepareBundleLinks $prepareBundleLinks */
2218
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
19+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
2320

2421
$bundleProduct = $productFactory->create();
2522
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)

dev/tests/integration/testsuite/Magento/Bundle/_files/dynamic_bundle_product_with_tier_price.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@
1212
use Magento\Catalog\Model\Product\Type;
1313
use Magento\Catalog\Model\Product\Type\AbstractType;
1414
use Magento\Catalog\Model\Product\Visibility;
15-
use Magento\Store\Api\WebsiteRepositoryInterface;
1615
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
1716
use Magento\Customer\Model\Group;
1817

1918
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products.php';
2019

21-
/** @var WebsiteRepositoryInterface $websiteRepository */
22-
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
23-
$defaultWebsiteId = $websiteRepository->get('base')->getId();
2420
/** @var PrepareBundleLinks $prepareBundleLinks */
2521
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
2622
/** @var ProductTierPriceInterfaceFactory $tierPriceFactory */
2723
$tierPriceFactory = $objectManager->get(ProductTierPriceInterfaceFactory::class);
2824
/** @var $tierPriceExtensionAttributesFactory */
2925
$tierPriceExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class);
26+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
3027

3128
$bundleProduct = $productFactory->create();
3229
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)
@@ -80,7 +77,7 @@
8077
$tierPriceExtensionAttribute = $tierPriceExtensionAttributesFactory->create(
8178
[
8279
'data' => [
83-
'website_id' => $websiteRepository->get('admin')->getId(),
80+
'website_id' => 0,
8481
'percentage_value' => 25,
8582
]
8683
]

dev/tests/integration/testsuite/Magento/Bundle/_files/dynamic_bundle_product_without_discounts.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
use Magento\Catalog\Model\Product\Type;
1111
use Magento\Catalog\Model\Product\Type\AbstractType;
1212
use Magento\Catalog\Model\Product\Visibility;
13-
use Magento\Store\Api\WebsiteRepositoryInterface;
1413
use Magento\TestFramework\Bundle\Model\PrepareBundleLinks;
1514

1615
require __DIR__ . '/../../../Magento/Catalog/_files/category_with_different_price_products.php';
1716

18-
/** @var WebsiteRepositoryInterface $websiteRepository */
19-
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
20-
$defaultWebsiteId = $websiteRepository->get('base')->getId();
2117
/** @var PrepareBundleLinks $prepareBundleLinks */
2218
$prepareBundleLinks = $objectManager->get(PrepareBundleLinks::class);
19+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
2320

2421
$bundleProduct = $productFactory->create();
2522
$bundleProduct->setTypeId(Type::TYPE_BUNDLE)

dev/tests/integration/testsuite/Magento/Bundle/_files/fixed_bundle_product_with_tier_price.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
$tierPriceExtensionAttribute = $tierPriceExtensionAttributesFactory->create(
8585
[
8686
'data' => [
87-
'website_id' => $websiteRepository->get('admin')->getId(),
87+
'website_id' => 0,
8888
'percentage_value' => 25,
8989
]
9090
]

dev/tests/integration/testsuite/Magento/Catalog/_files/category_with_different_price_products.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,30 @@
1515
use Magento\Store\Model\Store;
1616
use Magento\Store\Model\StoreManagerInterface;
1717
use Magento\TestFramework\Helper\Bootstrap;
18+
use Magento\Catalog\Helper\DefaultCategory;
1819

1920
$objectManager = Bootstrap::getObjectManager();
21+
/** @var StoreManagerInterface $storeManager */
2022
$storeManager = $objectManager->get(StoreManagerInterface::class);
23+
/** @var CategoryInterfaceFactory $categoryFactory */
2124
$categoryFactory = $objectManager->get(CategoryInterfaceFactory::class);
25+
/** @var ProductInterfaceFactory $productFactory */
2226
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
27+
/** @var ProductRepositoryInterface $productRepository */
2328
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
29+
$productRepository->cleanCache();
30+
/** @var CategoryRepositoryInterface $categoryRepository */
2431
$categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
32+
/** @var DefaultCategory $categoryHelper */
33+
$categoryHelper = $objectManager->get(DefaultCategory::class);
2534
$currentStoreId = $storeManager->getStore()->getId();
35+
$defaultWebsiteId = $storeManager->getWebsite('base')->getId();
2636

2737
$storeManager->setCurrentStore(Store::DEFAULT_STORE_ID);
2838
$category = $categoryFactory->create();
2939
$category->isObjectNew(true);
3040
$category->setName('Category 999')
31-
->setParentId(2)
41+
->setParentId($categoryHelper->getId())
3242
->setLevel(2)
3343
->setAvailableSortBy('name')
3444
->setDefaultSortBy('name')
@@ -41,7 +51,7 @@
4151
$product->setTypeId(Type::TYPE_SIMPLE)
4252
->setAttributeSetId($product->getDefaultAttributeSetId())
4353
->setStoreId(Store::DEFAULT_STORE_ID)
44-
->setWebsiteIds([1])
54+
->setWebsiteIds([$defaultWebsiteId])
4555
->setName('Simple Product With Price 10')
4656
->setSku('simple1000')
4757
->setPrice(10)
@@ -56,7 +66,7 @@
5666
$product2->setTypeId(Type::TYPE_SIMPLE)
5767
->setAttributeSetId($product2->getDefaultAttributeSetId())
5868
->setStoreId(Store::DEFAULT_STORE_ID)
59-
->setWebsiteIds([1])
69+
->setWebsiteIds([$defaultWebsiteId])
6070
->setName('Simple Product With Price 20')
6171
->setSku('simple1001')
6272
->setPrice(20)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\CatalogRule\Api\CatalogRuleRepositoryInterface;
9+
use Magento\CatalogRule\Api\Data\RuleInterface;
10+
use Magento\CatalogRule\Api\Data\RuleInterfaceFactory;
11+
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
12+
use Magento\CatalogRule\Model\Rule\Condition\Combine;
13+
use Magento\CatalogRule\Model\Rule\Condition\Product;
14+
use Magento\Customer\Model\Group;
15+
use Magento\Store\Api\WebsiteRepositoryInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Magento\TestFramework\Catalog\Model\GetCategoryByName;
18+
19+
$objectManager = Bootstrap::getObjectManager();
20+
/** @var WebsiteRepositoryInterface $websiteRepository */
21+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
22+
$defaultWebsiteId = $websiteRepository->get('base')->getId();
23+
/** @var IndexBuilder $indexBuilder */
24+
$indexBuilder = $objectManager->get(IndexBuilder::class);
25+
/** @var CatalogRuleRepositoryInterface $catalogRuleRepository */
26+
$catalogRuleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
27+
/** @var RuleInterfaceFactory $ruleFactory */
28+
$catalogRuleFactory = $objectManager->get(RuleInterfaceFactory::class);
29+
/** @var GetCategoryByName $getCategoryByName */
30+
$getCategoryByName = $objectManager->get(GetCategoryByName::class);
31+
32+
$category = $getCategoryByName->execute('Category 999');
33+
if ($category->getId()) {
34+
$ruleData = [
35+
RuleInterface::NAME => 'Catalog rule for category 999',
36+
RuleInterface::IS_ACTIVE => 1,
37+
'website_ids' => [$defaultWebsiteId],
38+
'customer_group_ids' => Group::NOT_LOGGED_IN_ID,
39+
RuleInterface::DISCOUNT_AMOUNT => 25,
40+
RuleInterface::SIMPLE_ACTION => 'by_percent',
41+
'conditions' => [
42+
'1' => [
43+
'type' => Combine::class,
44+
'aggregator' => 'all',
45+
'value' => '1',
46+
],
47+
'1--1' => [
48+
'type' => Product::class,
49+
'attribute' => 'category_ids',
50+
'operator' => '==',
51+
'value' => $category->getId(),
52+
],
53+
],
54+
];
55+
$catalogRule = $catalogRuleFactory->create();
56+
$catalogRule->loadPost($ruleData);
57+
$catalogRuleRepository->save($catalogRule);
58+
$indexBuilder->reindexFull();
59+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\CatalogRule\Api\CatalogRuleRepositoryInterface;
9+
use Magento\CatalogRule\Model\Indexer\IndexBuilder;
10+
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
/** @var CatalogRuleRepositoryInterface $ruleRepository */
15+
$catalogRuleRepository = $objectManager->get(CatalogRuleRepositoryInterface::class);
16+
/** @var CollectionFactory $ruleCollectionFactory */
17+
$ruleCollectionFactory = $objectManager->get(CollectionFactory::class);
18+
/** @var IndexBuilder $indexBuilder */
19+
$indexBuilder = $objectManager->get(IndexBuilder::class);
20+
21+
$ruleCollection = $ruleCollectionFactory->create();
22+
$ruleCollection->addFieldToFilter('name', 'Catalog rule for category 999');
23+
$ruleCollection->setPageSize(1);
24+
$catalogRule = $ruleCollection->getFirstItem();
25+
if ($catalogRule->getId()) {
26+
$catalogRuleRepository->delete($catalogRule);
27+
}
28+
$indexBuilder->reindexFull();

0 commit comments

Comments
 (0)