Price API¶
Currencies¶
To manage currencies, use CurrencyServiceInterface.
To access a currency object by its code, use CurrencyServiceInterface::getCurrencyByCode.
To access a whole list of currencies, use CurrencyServiceInterface::findCurrencies.
1 2 3 4 5 6 7 8 | |
To create a new currency, use CurrencyServiceInterface::createCurrency() and provide it with a CurrencyCreateStruct with code, number of fractional digits and a flag indicating if the currency is enabled:
1 2 3 | |
Prices¶
To manage prices, use ProductPriceServiceInterface.
To retrieve the price of a product in the currency for the current context, use Product::getPrice():
1 2 3 | |
To retrieve the price of a product in a specific currency, use ProductPriceService::getPriceByProductAndCurrency:
1 2 3 | |
To get all prices (in different currencies) for a given product, use ProductPriceServiceInterface::findPricesByProductCode:
1 2 3 4 5 6 | |
To load price definitions that match given criteria, use ProductPriceServiceInterface::findPrices:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
You can also use ProductPriceServiceInterface to create or modify existing prices.
For example, to create a new price for a given currency, use ProductPriceService::createProductPrice and provide it with a ProductPriceCreateStruct object:
1 2 3 4 5 | |
Note
Prices operate using the Money library.
That is why all amounts are provided in the smallest unit.
For example, for euro 50000 refers to 50000 cents, equal to 500 euros.
Resolve prices¶
To display a product price on a product page or in the cart, you must calculate its value based on a base price and the context.
Context contains information about any price modifiers that may apply to a specific customer group.
To determine the final price, or resolve the price, use the PriceResolverInterface service, which takes the following conditions into account:
- Existance of base price for the product in the specified currency
- Existance of customer group-related modifiers
- Existance of applicable discounts
If the base price in the specified currency is missing, the return value is null.
To resolve a price of a product in the currency for the current context, use either PriceResolverInterface::resolvePrice() or PriceResolverInterface::resolvePrices():
1 2 3 4 5 6 7 8 | |
VAT¶
To get information about the VAT categories and rates configured in the system, use VatServiceInterface.
VAT is configured per region, so you also need to use RegionServiceInterface to get the relevant region object.
1 | |
To get information about all VAT categories configured for the selected region, use VatServiceInterface::getVatCategories():
1 2 3 4 5 | |
To get a single VAT category, use VatServiceInterface::getVatCategoryByIdentifier() and provide it with the region object and the identifier of the VAT category:
1 | |