Skip to content

Commit 0f9e6be

Browse files
MC-23036: Special/tier/group/rule/option prices for product in multiple websites
1 parent e30caae commit 0f9e6be

File tree

6 files changed

+121
-98
lines changed

6 files changed

+121
-98
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Pricing/Render/PriceTypes/CombinationAbstract.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
use Magento\Customer\Model\Session;
2424
use Magento\Framework\Registry;
2525
use Magento\Framework\View\Result\Page;
26+
use Magento\Framework\View\Result\PageFactory;
2627
use Magento\Store\Api\WebsiteRepositoryInterface;
2728
use Magento\Store\Model\StoreManagerInterface;
2829
use Magento\TestFramework\Helper\Bootstrap;
2930
use Magento\TestFramework\Helper\Xpath;
3031
use Magento\TestFramework\ObjectManager;
3132
use PHPUnit\Framework\TestCase;
32-
use const null;
3333

3434
/**
3535
* Base class for combination of different price types tests.
@@ -48,11 +48,6 @@ abstract class CombinationAbstract extends TestCase
4848
*/
4949
protected $page;
5050

51-
/**
52-
* @var Registry
53-
*/
54-
protected $registry;
55-
5651
/**
5752
* @var IndexBuilder
5853
*/
@@ -64,39 +59,44 @@ abstract class CombinationAbstract extends TestCase
6459
protected $customerSession;
6560

6661
/**
67-
* @var WebsiteRepositoryInterface
62+
* @var StoreManagerInterface
63+
*/
64+
protected $storeManager;
65+
66+
/**
67+
* @var Registry
6868
*/
69-
protected $websiteRepository;
69+
private $registry;
7070

7171
/**
72-
* @var StoreManagerInterface
72+
* @var WebsiteRepositoryInterface
7373
*/
74-
protected $storeManager;
74+
private $websiteRepository;
7575

7676
/**
7777
* @var ProductRepositoryInterface
7878
*/
79-
protected $productRepository;
79+
private $productRepository;
8080

8181
/**
8282
* @var RuleInterfaceFactory
8383
*/
84-
protected $catalogRuleFactory;
84+
private $catalogRuleFactory;
8585

8686
/**
8787
* @var CatalogRuleRepositoryInterface
8888
*/
89-
protected $catalogRuleRepository;
89+
private $catalogRuleRepository;
9090

9191
/**
9292
* @var ProductTierPriceInterfaceFactory
9393
*/
94-
protected $productTierPriceFactory;
94+
private $productTierPriceFactory;
9595

9696
/**
9797
* @var ProductTierPriceExtensionFactory
9898
*/
99-
protected $productTierPriceExtensionFactory;
99+
private $productTierPriceExtensionFactory;
100100

101101
/**
102102
* @var ProductCustomOptionInterfaceFactory
@@ -110,7 +110,7 @@ protected function setUp()
110110
{
111111
parent::setUp();
112112
$this->objectManager = Bootstrap::getObjectManager();
113-
$this->page = $this->objectManager->create(Page::class);
113+
$this->page = $this->objectManager->get(PageFactory::class)->create();
114114
$this->registry = $this->objectManager->get(Registry::class);
115115
$this->indexBuilder = $this->objectManager->get(IndexBuilder::class);
116116
$this->customerSession = $this->objectManager->get(Session::class);
@@ -310,11 +310,11 @@ public function percentCustomOptionsDataProvider(): array
310310
return [
311311
'percent_option_for_product_without_special_price' => [
312312
'option_price' => 5,
313-
'product_prices' => ['special_price' => null,],
313+
'product_prices' => ['special_price' => null],
314314
],
315315
'percent_option_for_product_with_special_price' => [
316316
'option_price' => 3,
317-
'product_prices' => ['special_price' => 5.99,],
317+
'product_prices' => ['special_price' => 5.99],
318318
],
319319
];
320320
}
@@ -511,7 +511,7 @@ protected function getRegularPriceLabelXpath(): string
511511
"//div[contains(@class, 'price-box') and contains(@class, 'price-final_price')]",
512512
"//span[contains(@class, 'old-price')]",
513513
"//span[contains(@class, 'price-container')]",
514-
"//span[text()='Regular Price']",
514+
sprintf("//span[normalize-space(text())='%s']", __('Regular Price')),
515515
];
516516

517517
return implode('', $pathsForSearch);
@@ -548,7 +548,7 @@ protected function getTierPriceMessageXpath(array $expectedMessage): string
548548
* @param int $websiteId
549549
* @return void
550550
*/
551-
protected function assertRenderedPrices(
551+
public function assertRenderedPrices(
552552
string $sku,
553553
float $specialPrice,
554554
float $regularPrice,
@@ -572,7 +572,7 @@ protected function assertRenderedPrices(
572572
* @param array $productPrices
573573
* @return void
574574
*/
575-
protected function assertRenderedCustomOptionPrices(
575+
public function assertRenderedCustomOptionPrices(
576576
string $sku,
577577
float $optionPrice,
578578
array $productPrices

dev/tests/integration/testsuite/Magento/Catalog/Pricing/Render/PriceTypes/MultiWebsiteCombinationTest.php

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
namespace Magento\Catalog\Pricing\Render\PriceTypes;
99

10-
use Magento\Framework\View\Result\Page;
10+
use Magento\Framework\View\Result\PageFactory;
11+
use Magento\TestFramework\Store\ExecuteInStoreContext;
1112

1213
/**
1314
* Assertions related to check product price rendering with combination of different price types on second website.
@@ -17,6 +18,20 @@
1718
*/
1819
class MultiWebsiteCombinationTest extends CombinationAbstract
1920
{
21+
/**
22+
* @var ExecuteInStoreContext
23+
*/
24+
private $executeInStoreContext;
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
protected function setUp()
30+
{
31+
parent::setUp();
32+
$this->executeInStoreContext = $this->objectManager->get(ExecuteInStoreContext::class);
33+
}
34+
2035
/**
2136
* Assert that product price rendered with expected special and regular prices if
2237
* product has special price which lower than regular and tier prices on second website.
@@ -34,20 +49,16 @@ public function testRenderSpecialPriceInCombinationWithTierPrice(
3449
float $regularPrice,
3550
array $tierData
3651
): void {
37-
try {
38-
$this->storeManager->setCurrentStore('fixture_second_store');
39-
$this->assertRenderedPrices(
40-
'second-website-price-product',
41-
$specialPrice,
42-
$regularPrice,
43-
$tierData,
44-
(int)$this->storeManager->getStore()->getWebsiteId()
45-
);
46-
$this->storeManager->setCurrentStore('default');
47-
$this->assertRenderedPricesOnDefaultStore('second-website-price-product');
48-
} finally {
49-
$this->storeManager->setCurrentStore('default');
50-
}
52+
$this->executeInStoreContext->execute(
53+
'fixture_second_store',
54+
[$this, 'assertRenderedPrices'],
55+
'second-website-price-product',
56+
$specialPrice,
57+
$regularPrice,
58+
$tierData,
59+
(int)$this->storeManager->getStore('fixture_second_store')->getWebsiteId()
60+
);
61+
$this->assertRenderedPricesOnDefaultStore('second-website-price-product');
5162
}
5263

5364
/**
@@ -73,19 +84,18 @@ public function testRenderSpecialPriceInCombinationWithTierPriceForLoggedInUser(
7384
): void {
7485
try {
7586
$this->customerSession->setCustomerId(1);
76-
$this->storeManager->setCurrentStore('fixture_second_store');
77-
$this->assertRenderedPrices(
87+
$this->executeInStoreContext->execute(
88+
'fixture_second_store',
89+
[$this, 'assertRenderedPrices'],
7890
'second-website-price-product',
7991
$specialPrice,
8092
$regularPrice,
8193
$tierData,
82-
(int)$this->storeManager->getStore()->getWebsiteId()
94+
(int)$this->storeManager->getStore('fixture_second_store')->getWebsiteId()
8395
);
84-
$this->storeManager->setCurrentStore('default');
8596
$this->assertRenderedPricesOnDefaultStore('second-website-price-product');
8697
} finally {
8798
$this->customerSession->setCustomerId(null);
88-
$this->storeManager->setCurrentStore('default');
8999
}
90100
}
91101

@@ -110,22 +120,18 @@ public function testRenderCatalogRulePriceInCombinationWithDifferentPriceTypes(
110120
array $catalogRules,
111121
array $tierData
112122
): void {
113-
try {
114-
$this->createCatalogRulesForProduct($catalogRules, 'test');
115-
$this->indexBuilder->reindexFull();
116-
$this->storeManager->setCurrentStore('fixture_second_store');
117-
$this->assertRenderedPrices(
118-
'second-website-price-product',
119-
$specialPrice,
120-
$regularPrice,
121-
$tierData,
122-
(int)$this->storeManager->getStore()->getWebsiteId()
123-
);
124-
$this->storeManager->setCurrentStore('default');
125-
$this->assertRenderedPricesOnDefaultStore('second-website-price-product');
126-
} finally {
127-
$this->storeManager->setCurrentStore('default');
128-
}
123+
$this->createCatalogRulesForProduct($catalogRules, 'test');
124+
$this->indexBuilder->reindexFull();
125+
$this->executeInStoreContext->execute(
126+
'fixture_second_store',
127+
[$this, 'assertRenderedPrices'],
128+
'second-website-price-product',
129+
$specialPrice,
130+
$regularPrice,
131+
$tierData,
132+
(int)$this->storeManager->getStore('fixture_second_store')->getWebsiteId()
133+
);
134+
$this->assertRenderedPricesOnDefaultStore('second-website-price-product');
129135
}
130136

131137
/**
@@ -143,40 +149,40 @@ public function testRenderSpecialPriceInCombinationWithCustomOptionPrice(
143149
float $optionPrice,
144150
array $productPrices
145151
): void {
146-
try {
147-
$this->storeManager->setCurrentStore('fixture_second_store');
148-
$this->assertRenderedCustomOptionPrices('second-website-price-product', $optionPrice, $productPrices);
149-
$this->storeManager->setCurrentStore('default');
150-
$this->assertRenderedCustomOptionPricesOnDefaultStore('second-website-price-product');
151-
} finally {
152-
$this->storeManager->setCurrentStore('default');
153-
}
152+
$this->executeInStoreContext->execute(
153+
'fixture_second_store',
154+
[$this, 'assertRenderedCustomOptionPrices'],
155+
'second-website-price-product',
156+
$optionPrice,
157+
$productPrices
158+
);
159+
$this->assertRenderedCustomOptionPricesOnDefaultStore('second-website-price-product');
154160
}
155161

156162
/**
157-
* Checks price data dor product on default store.
163+
* Checks price data for product on default store.
158164
*
159165
* @param string $sku
160166
* @return void
161167
*/
162168
private function assertRenderedPricesOnDefaultStore(string $sku): void
163169
{
164170
//Reset layout page to get new block html
165-
$this->page = $this->objectManager->create(Page::class);
171+
$this->page = $this->objectManager->get(PageFactory::class)->create();
166172
$defaultStoreTierData = ['prices' => [], 'message_config' => null];
167173
$this->assertRenderedPrices($sku, 15, 20, $defaultStoreTierData);
168174
}
169175

170176
/**
171-
* Checks custom option price data dor product on default store.
177+
* Checks custom option price data for product on default store.
172178
*
173179
* @param string $sku
174180
* @return void
175181
*/
176182
private function assertRenderedCustomOptionPricesOnDefaultStore(string $sku): void
177183
{
178184
//Reset layout page to get new block html
179-
$this->page = $this->objectManager->create(Page::class);
185+
$this->page = $this->objectManager->get(PageFactory::class)->create();
180186
$this->assertRenderedCustomOptionPrices($sku, 7.5, []);
181187
}
182188
}

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Api\ProductRepositoryInterface;
1010
use Magento\Catalog\Helper\Data;
1111
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\Catalog\Model\Product\Type;
1213
use Magento\Catalog\Model\Product\Visibility;
1314
use Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange;
1415
use Magento\Config\Model\ResourceModel\Config;
@@ -34,16 +35,15 @@
3435
/** @var ProductRepositoryInterface $productRepository */
3536
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
3637
/** @var WebsiteRepositoryInterface $websiteRepository */
37-
$websiteRepository = $objectManager->create(WebsiteRepositoryInterface::class);
38+
$websiteRepository = $objectManager->get(WebsiteRepositoryInterface::class);
3839
$websiteId = $websiteRepository->get('test')->getId();
3940
$defaultWebsiteId = $websiteRepository->get('base')->getId();
4041
/** @var StoreManagerInterface $storeManager */
4142
$storeManager = $objectManager->get(StoreManagerInterface::class);
4243
$secondStoreId = $storeManager->getStore('fixture_second_store')->getId();
43-
$currentStoreCode = $storeManager->getStore()->getCode();
4444
/** @var $product \Magento\Catalog\Model\Product */
4545
$product = $productFactory->create();
46-
$product->setTypeId('simple')
46+
$product->setTypeId(Type::TYPE_SIMPLE)
4747
->setAttributeSetId($product->getDefaultAttributeSetId())
4848
->setWebsiteIds([$defaultWebsiteId, $websiteId])
4949
->setName('Second website price product')
@@ -65,9 +65,13 @@
6565
);
6666
$productRepository->save($product);
6767

68-
$storeManager->setCurrentStore('fixture_second_store');
69-
$product = $productRepository->get('second-website-price-product', false, $secondStoreId, true);
70-
$product->setPrice(10)
71-
->setSpecialPrice(5.99);
72-
$productRepository->save($product);
73-
$storeManager->setCurrentStore($currentStoreCode);
68+
try {
69+
$currentStoreCode = $storeManager->getStore()->getCode();
70+
$storeManager->setCurrentStore('fixture_second_store');
71+
$product = $productRepository->get('second-website-price-product', false, $secondStoreId, true);
72+
$product->setPrice(10)
73+
->setSpecialPrice(5.99);
74+
$productRepository->save($product);
75+
} finally {
76+
$storeManager->setCurrentStore($currentStoreCode);
77+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
$observer = $objectManager->get(Observer::class);
2525
$objectManager->get(SwitchPriceAttributeScopeOnConfigChange::class)->execute($observer);
2626
/** @var ProductRepositoryInterface $productRepository */
27-
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
27+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
2828
try {
2929
$productRepository->deleteById('second-website-price-product');
3030
} catch (NoSuchEntityException $e) {

0 commit comments

Comments
 (0)