Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 236ce9a

Browse files
author
Roman Glushko
committed
#141 Retrieves actual price value units
1 parent 5140906 commit 236ce9a

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/CartItem/CustomizableOptions.php

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Authorization\Model\UserContextInterface;
1111
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
12+
use Magento\Catalog\Model\Config\Source\ProductPriceOptionsInterface;
1213
use Magento\Catalog\Model\Product\Option\Type\DefaultType as DefaultOptionType;
1314
use Magento\Catalog\Model\Product\Option\Type\Select as SelectOptionType;
1415
use Magento\Catalog\Model\Product\Option\Type\Text as TextOptionType;
@@ -18,12 +19,20 @@
1819
use Magento\Framework\GraphQl\Query\ResolverInterface;
1920
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
2021
use Magento\Quote\Model\Quote\Item as QuoteItem;
22+
use Magento\Store\Api\Data\StoreInterface;
23+
use Magento\Store\Model\Store;
24+
use Magento\Store\Model\StoreManagerInterface;
2125

2226
/**
2327
* {@inheritdoc}
2428
*/
2529
class CustomizableOptions implements ResolverInterface
2630
{
31+
/**
32+
* @var StoreManagerInterface
33+
*/
34+
private $storeManager;
35+
2736
/**
2837
* @var ValueFactory
2938
*/
@@ -37,13 +46,16 @@ class CustomizableOptions implements ResolverInterface
3746
/**
3847
* @param ValueFactory $valueFactory
3948
* @param UserContextInterface $userContext
49+
* @param StoreManagerInterface $storeManager
4050
*/
4151
public function __construct(
4252
ValueFactory $valueFactory,
43-
UserContextInterface $userContext
53+
UserContextInterface $userContext,
54+
StoreManagerInterface $storeManager
4455
) {
4556
$this->valueFactory = $valueFactory;
4657
$this->userContext = $userContext;
58+
$this->storeManager = $storeManager;
4759
}
4860

4961
/**
@@ -134,9 +146,11 @@ private function getOptionData($cartItem, int $optionId): array
134146
|| ProductCustomOptionInterface::OPTION_TYPE_CHECKBOX == $option->getType()
135147
) {
136148
$optionValue = $option->getValueById($itemOption->getValue());
149+
$priceValueUnits = $this->getPriceValueUnits($optionValue->getPriceType());
150+
137151
$selectedOptionValueData['price'] = [
138152
'type' => strtoupper($optionValue->getPriceType()),
139-
'units' => '$',
153+
'units' => $priceValueUnits,
140154
'value' => $optionValue->getPrice(),
141155
];
142156

@@ -148,9 +162,11 @@ private function getOptionData($cartItem, int $optionId): array
148162
|| ProductCustomOptionInterface::OPTION_GROUP_DATE == $option->getType()
149163
|| ProductCustomOptionInterface::OPTION_TYPE_TIME == $option->getType()
150164
) {
165+
$priceValueUnits = $this->getPriceValueUnits($option->getPriceType());
166+
151167
$selectedOptionValueData['price'] = [
152168
'type' => strtoupper($option->getPriceType()),
153-
'units' => '$',
169+
'units' => $priceValueUnits,
154170
'value' => $option->getPrice(),
155171
];
156172

@@ -163,13 +179,14 @@ private function getOptionData($cartItem, int $optionId): array
163179

164180
foreach ($optionIds as $optionId) {
165181
$optionValue = $option->getValueById($optionId);
182+
$priceValueUnits = $this->getPriceValueUnits($optionValue->getPriceType());
166183

167184
$selectedOptionValueData[] = [
168185
'id' => $itemOption->getId(),
169186
'label' => $optionValue->getTitle(),
170187
'price' => [
171188
'type' => strtoupper($optionValue->getPriceType()),
172-
'units' => '$',
189+
'units' => $priceValueUnits,
173190
'value' => $optionValue->getPrice(),
174191
],
175192
];
@@ -184,4 +201,29 @@ private function getOptionData($cartItem, int $optionId): array
184201
'sort_order' => $option->getSortOrder(),
185202
];
186203
}
204+
205+
/**
206+
* @param string $priceType
207+
*/
208+
private function getPriceValueUnits(string $priceType): string
209+
{
210+
if (ProductPriceOptionsInterface::VALUE_PERCENT == $priceType) {
211+
return '%';
212+
}
213+
214+
return $this->getCurrencySymbol();
215+
}
216+
217+
/**
218+
* Get currency symbol
219+
*
220+
* @return string
221+
*/
222+
private function getCurrencySymbol(): string
223+
{
224+
/** @var Store|StoreInterface $store */
225+
$store = $this->storeManager->getStore();
226+
227+
return $store->getBaseCurrency()->getCurrencySymbol();
228+
}
187229
}

0 commit comments

Comments
 (0)