Skip to content

Commit 831fb5b

Browse files
committed
#26121: special price & tier price are coming in base currency
Move price transform to PriceTiers
1 parent d99ff1b commit 831fb5b

File tree

5 files changed

+45
-254
lines changed

5 files changed

+45
-254
lines changed

app/code/Magento/Catalog/Model/Product/Price/TierPriceBuilder.php

Lines changed: 0 additions & 209 deletions
This file was deleted.

app/code/Magento/Catalog/Model/Product/Type/Price.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Magento\Catalog\Model\Product\Type;
99

1010
use Magento\Catalog\Model\Product;
11-
use Magento\Catalog\Model\Product\Price\TierPriceBuilder;
1211
use Magento\Customer\Api\GroupManagementInterface;
1312
use Magento\Framework\Pricing\PriceCurrencyInterface;
1413
use Magento\Store\Model\Store;
@@ -94,11 +93,6 @@ class Price
9493
*/
9594
private $tierPriceExtensionFactory;
9695

97-
/**
98-
* @var TierPriceBuilder
99-
*/
100-
private $tierPriceBuilder;
101-
10296
/**
10397
* Constructor
10498
*
@@ -109,10 +103,9 @@ class Price
109103
* @param \Magento\Framework\Event\ManagerInterface $eventManager
110104
* @param PriceCurrencyInterface $priceCurrency
111105
* @param GroupManagementInterface $groupManagement
112-
* @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory @deprecated
106+
* @param \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory
113107
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
114-
* @param ProductTierPriceExtensionFactory|null $tierPriceExtensionFactory @deprecated
115-
* @param TierPriceBuilder $tierPriceBuilder
108+
* @param ProductTierPriceExtensionFactory|null $tierPriceExtensionFactory
116109
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
117110
*/
118111
public function __construct(
@@ -125,8 +118,7 @@ public function __construct(
125118
GroupManagementInterface $groupManagement,
126119
\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory,
127120
\Magento\Framework\App\Config\ScopeConfigInterface $config,
128-
ProductTierPriceExtensionFactory $tierPriceExtensionFactory = null,
129-
?TierPriceBuilder $tierPriceBuilder = null
121+
ProductTierPriceExtensionFactory $tierPriceExtensionFactory = null
130122
) {
131123
$this->_ruleFactory = $ruleFactory;
132124
$this->_storeManager = $storeManager;
@@ -139,8 +131,6 @@ public function __construct(
139131
$this->config = $config;
140132
$this->tierPriceExtensionFactory = $tierPriceExtensionFactory ?: ObjectManager::getInstance()
141133
->get(ProductTierPriceExtensionFactory::class);
142-
$this->tierPriceBuilder = $tierPriceBuilder ?: ObjectManager::getInstance()
143-
->get(TierPriceBuilder::class);
144134
}
145135

146136
/**
@@ -379,7 +369,28 @@ protected function getAllCustomerGroupsId()
379369
*/
380370
public function getTierPrices($product)
381371
{
382-
return $this->tierPriceBuilder->getTierPrices($product);
372+
$prices = [];
373+
$tierPrices = $this->getExistingPrices($product, 'tier_price');
374+
foreach ($tierPrices as $price) {
375+
/** @var \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice */
376+
$tierPrice = $this->tierPriceFactory->create()
377+
->setExtensionAttributes($this->tierPriceExtensionFactory->create());
378+
$tierPrice->setCustomerGroupId($price['cust_group']);
379+
if (array_key_exists('website_price', $price)) {
380+
$value = $price['website_price'];
381+
} else {
382+
$value = $price['price'];
383+
}
384+
$tierPrice->setValue($value);
385+
$tierPrice->setQty($price['price_qty']);
386+
if (isset($price['percentage_value'])) {
387+
$tierPrice->getExtensionAttributes()->setPercentageValue($price['percentage_value']);
388+
}
389+
$websiteId = isset($price['website_id']) ? $price['website_id'] : $this->getWebsiteForPriceScope();
390+
$tierPrice->getExtensionAttributes()->setWebsiteId($websiteId);
391+
$prices[] = $tierPrice;
392+
}
393+
return $prices;
383394
}
384395

385396
/**

app/code/Magento/Catalog/Test/Unit/Model/Product/Type/PriceTest.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
use Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory;
1313
use Magento\Catalog\Model\Product;
1414
use Magento\Catalog\Model\Product\TierPrice;
15-
use Magento\Catalog\Model\Product\Price\TierPriceBuilder;
1615
use Magento\Catalog\Model\Product\Type\Price;
1716
use Magento\Customer\Api\GroupManagementInterface;
1817
use Magento\Customer\Model\Data\Group;
1918
use Magento\Customer\Model\GroupManagement;
2019
use Magento\Framework\App\Config\ScopeConfigInterface;
21-
use Magento\Framework\Pricing\PriceCurrencyInterface;
2220
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
2321
use Magento\Store\Model\StoreManagerInterface;
2422
use Magento\Store\Model\Website;
@@ -71,8 +69,6 @@ class PriceTest extends TestCase
7169

7270
private $tierPriceExtensionFactoryMock;
7371

74-
private $priceCurrencyMock;
75-
7672
protected function setUp(): void
7773
{
7874
$this->objectManagerHelper = new ObjectManagerHelper($this);
@@ -117,27 +113,14 @@ protected function setUp(): void
117113
->setMethods(['create'])
118114
->disableOriginalConstructor()
119115
->getMock();
120-
$this->priceCurrencyMock = $this->getMockBuilder(PriceCurrencyInterface::class)
121-
->getMockForAbstractClass();
122-
$tierPriceBuilder = $this->objectManagerHelper->getObject(
123-
TierPriceBuilder::class,
124-
[
125-
'tierPriceFactory' => $this->tpFactory,
126-
'tierPriceExtensionFactory' => $this->tierPriceExtensionFactoryMock,
127-
'config' => $this->scopeConfigMock,
128-
'storeManager' => $storeMangerMock,
129-
'priceCurrency' => $this->priceCurrencyMock,
130-
]
131-
);
132116
$this->model = $this->objectManagerHelper->getObject(
133117
Price::class,
134118
[
135119
'tierPriceFactory' => $this->tpFactory,
136120
'config' => $this->scopeConfigMock,
137121
'storeManager' => $storeMangerMock,
138122
'groupManagement' => $this->groupManagementMock,
139-
'tierPriceExtensionFactory' => $this->tierPriceExtensionFactoryMock,
140-
'tierPriceBuilder' => $tierPriceBuilder
123+
'tierPriceExtensionFactory' => $this->tierPriceExtensionFactoryMock
141124
]
142125
);
143126
}
@@ -251,10 +234,6 @@ function () {
251234
$this->tierPriceExtensionFactoryMock->expects($this->any())
252235
->method('create')
253236
->willReturn($tierPriceExtensionMock);
254-
$this->priceCurrencyMock->expects($this->any())->method('convertAndRound')
255-
->will(
256-
$this->onConsecutiveCalls(10, 20)
257-
);
258237

259238
// test with the data retrieved as a REST object
260239
$tpRests = $this->model->getTierPrices($this->product);

0 commit comments

Comments
 (0)