Skip to content

Commit af8805a

Browse files
committed
Added better formatting prices
1 parent 52040b9 commit af8805a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

code_samples/discounts/src/Command/OrderPriceCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Ibexa\Contracts\ProductCatalog\Values\Price\PriceEnvelopeInterface;
1515
use Ibexa\Discounts\Value\Price\Stamp\DiscountStamp;
1616
use Ibexa\OrderManagement\Discounts\Value\DiscountsData;
17+
use Ibexa\ProductCatalog\Money\IntlMoneyFactory;
1718
use Money\Money;
1819
use Symfony\Component\Console\Command\Command;
1920
use Symfony\Component\Console\Input\InputInterface;
@@ -37,14 +38,17 @@ final class OrderPriceCommand extends Command
3738

3839
private PriceResolverInterface $priceResolver;
3940

41+
private IntlMoneyFactory $moneyFactory;
42+
4043
public function __construct(
4144
PermissionResolver $permissionResolver,
4245
UserService $userService,
4346
ProductServiceInterface $productService,
4447
OrderServiceInterface $orderService,
4548
ProductPriceServiceInterface $productPriceService,
4649
CurrencyServiceInterface $currencyService,
47-
PriceResolverInterface $priceResolver
50+
PriceResolverInterface $priceResolver,
51+
IntlMoneyFactory $moneyFactory
4852
) {
4953
parent::__construct();
5054

@@ -55,12 +59,14 @@ public function __construct(
5559
$this->productPriceService = $productPriceService;
5660
$this->currencyService = $currencyService;
5761
$this->priceResolver = $priceResolver;
62+
$this->moneyFactory = $moneyFactory;
5863
}
5964

6065
public function execute(InputInterface $input, OutputInterface $output): int
6166
{
6267
$this->permissionResolver->setCurrentUserReference($this->userService->loadUserByLogin('admin'));
6368

69+
$output->writeln('Product data:');
6470
$productCode = 'product_code_control_unit_0';
6571
$orderIdentifier = '4315bc58-1e96-4f21-82a0-15f736cbc4bc';
6672
$currencyCode = 'EUR';
@@ -129,6 +135,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
129135

130136
private function formatPrice(Money $money): string
131137
{
132-
return $money->getAmount() / 100.0 . ' ' . $money->getCurrency()->getCode();
138+
return $this->moneyFactory->getMoneyFormatter()->format($money);
133139
}
134140
}

docs/discounts/discounts_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,6 @@ The example below shows how you can use:
181181
- [`PriceEnvelopeInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Price-PriceEnvelopeInterface.html) to retrieve applied discounts
182182
- [`OrderServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-OrderManagement-OrderServiceInterface.html) to display discount details for [orders](order_management.md)
183183

184-
``` php hl_lines="72-73 79-80 82-95 99-125"
184+
``` php hl_lines="78-79 85-86 88-101 105-131"
185185
[[= include_file('code_samples/discounts/src/Command/OrderPriceCommand.php') =]]
186186
```

0 commit comments

Comments
 (0)