Skip to content

Commit cce0a99

Browse files
committed
#26121: special price & tier price are coming in base currency
Adjust to take customer group (via setting customerGroupId) into consideration.
1 parent 5c69aa1 commit cce0a99

File tree

4 files changed

+104
-13
lines changed

4 files changed

+104
-13
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,33 @@ protected function getAllCustomerGroupsId()
368368
* @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]
369369
*/
370370
public function getTierPrices($product)
371+
{
372+
$tierPricesRaw = $this->getExistingPrices($product, 'tier_price');
373+
374+
return $this->buildProductTierPriceInterfaceObjects($tierPricesRaw);
375+
}
376+
377+
/**
378+
* Return ProductTierPriceInterface[] given raw tier prices array
379+
*
380+
* @param array $tierPricesRaw
381+
* @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]
382+
*/
383+
public function transformTierPrices($tierPricesRaw)
384+
{
385+
return $this->buildProductTierPriceInterfaceObjects($tierPricesRaw);
386+
}
387+
388+
/**
389+
* Return ProductTierPriceInterface[] given raw tier prices array
390+
*
391+
* @param array $tierPricesRaw
392+
* @return \Magento\Catalog\Api\Data\ProductTierPriceInterface[]
393+
*/
394+
private function buildProductTierPriceInterfaceObjects($tierPricesRaw)
371395
{
372396
$prices = [];
373-
$tierPrices = $this->getExistingPrices($product, 'tier_price');
374-
foreach ($tierPrices as $price) {
397+
foreach ($tierPricesRaw as $price) {
375398
/** @var \Magento\Catalog\Api\Data\ProductTierPriceInterface $tierPrice */
376399
$tierPrice = $this->tierPriceFactory->create()
377400
->setExtensionAttributes($this->tierPriceExtensionFactory->create());

app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/PriceTiers.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,18 @@ private function formatProductTierPrices(array $tierPrices, float $productPrice,
130130
$tiers = [];
131131

132132
foreach ($tierPrices as $tierPrice) {
133-
$websitePrice = $tierPrice['website_price'];
134-
$percentValue = $tierPrice['percentage_value'];
135-
$quantity = $tierPrice['price_qty'];
136-
133+
$percentValue = $tierPrice->getExtensionAttributes()->getPercentageValue();
137134
if ($percentValue && is_numeric($percentValue)) {
138135
$discount = $this->discount->getDiscountByPercent($productPrice, (float)$percentValue);
139136
} else {
140-
$discount = $this->discount->getDiscountByDifference($productPrice, (float)$websitePrice);
137+
$discount = $this->discount->getDiscountByDifference($productPrice, (float)$tierPrice->getValue());
141138
}
142139

143140
$tiers[] = [
144141
"discount" => $discount,
145-
"quantity" => $quantity,
142+
"quantity" => $tierPrice->getQty(),
146143
"final_price" => [
147-
"value" => $websitePrice,
144+
"value" => $tierPrice->getValue(),
148145
"currency" => $store->getCurrentCurrencyCode()
149146
]
150147
];

app/code/Magento/CatalogCustomerGraphQl/Model/Resolver/Product/Price/Tiers.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1111
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1212
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
13-
use Magento\Catalog\Pricing\Price\TierPrice;
13+
use Magento\CatalogCustomerGraphQl\Pricing\Price\TierPrice;
1414
use Magento\Customer\Model\GroupManagement;
1515
use Magento\Catalog\Api\Data\ProductTierPriceInterface;
1616
use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderPool as PriceProviderPool;
17+
use Magento\Framework\App\ObjectManager;
18+
use Magento\Catalog\Model\Product\Type\Price;
1719

1820
/**
1921
* Get product tier price information
@@ -55,22 +57,30 @@ class Tiers
5557
*/
5658
private $products = [];
5759

60+
/**
61+
* @var Price
62+
*/
63+
private $price;
64+
5865
/**
5966
* @param CollectionFactory $collectionFactory
6067
* @param ProductResource $productResource
6168
* @param PriceProviderPool $priceProviderPool
6269
* @param int $customerGroupId
70+
* @param Price $price
6371
*/
6472
public function __construct(
6573
CollectionFactory $collectionFactory,
6674
ProductResource $productResource,
6775
PriceProviderPool $priceProviderPool,
68-
$customerGroupId
76+
$customerGroupId,
77+
Price $price
6978
) {
7079
$this->collectionFactory = $collectionFactory;
7180
$this->productResource = $productResource;
7281
$this->priceProviderPool = $priceProviderPool;
7382
$this->customerGroupId = $customerGroupId;
83+
$this->price = $price;
7484
}
7585

7686
/**
@@ -100,9 +110,21 @@ public function getProductTierPrices($productId): ?array
100110
}
101111

102112
/** @var TierPrice $tierPrice */
103-
$tierPrice = $this->products[$productId]->getPriceInfo()->getPrice(TierPrice::PRICE_CODE);
113+
$tierPrice = ObjectManager::getInstance()->create(TierPrice::class,
114+
[
115+
'saleableItem' => $this->products[$productId],
116+
'quantity' => 1,
117+
'customerGroupId' => $this->customerGroupId
118+
]
119+
);
120+
121+
/** @var array $tierPricesRaw */
122+
$tierPricesRaw = $tierPrice->getTierPriceList();
123+
124+
/** @var ProductTierPriceInterface[] $tierPrices */
125+
$tierPrices = $this->price->transformTierPrices($tierPricesRaw);
104126

105-
return $tierPrice->getTierPriceList();
127+
return $tierPrices;
106128
}
107129

108130
/**
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\CatalogCustomerGraphQl\Pricing\Price;
10+
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Customer\Api\GroupManagementInterface;
13+
use Magento\Customer\Model\Session;
14+
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
15+
use Magento\Framework\Pricing\PriceCurrencyInterface;
16+
17+
class TierPrice extends \Magento\Catalog\Pricing\Price\TierPrice
18+
{
19+
/**
20+
* TierPrice constructor.
21+
* @param Product $saleableItem
22+
* @param float $quantity
23+
* @param CalculatorInterface $calculator
24+
* @param PriceCurrencyInterface $priceCurrency
25+
* @param Session $customerSession
26+
* @param GroupManagementInterface $groupManagement
27+
* @param int $customerGroupId
28+
*/
29+
public function __construct(
30+
Product $saleableItem,
31+
$quantity,
32+
CalculatorInterface $calculator,
33+
PriceCurrencyInterface $priceCurrency,
34+
Session $customerSession,
35+
GroupManagementInterface $groupManagement,
36+
$customerGroupId
37+
) {
38+
parent::__construct(
39+
$saleableItem,
40+
$quantity,
41+
$calculator,
42+
$priceCurrency,
43+
$customerSession,
44+
$groupManagement
45+
);
46+
47+
$this->customerGroup = $customerGroupId;
48+
}
49+
}

0 commit comments

Comments
 (0)