Configuration of price modes and types
Edit on GitHubThe following price modes are used to identify pricing type:
- GROSS_MODE: prices after tax.
- NET_MODE: prices before tax.
When a customer changes the price mode, they see different prices, taxes, as well as the discounts. Price mode is stored in Quote, which means that both modes can’t be used at the same time. The price is selected in \Spryker\Zed\PriceCartConnector\Communication\Plugin\CartItemPricePlugin
based on the current currency, type, and price mode.
Price type entity also has price mode to indicate which prices this type is applicable to:
- If it has the
BOTH
value, this price type is used for gross and net prices. - If
GROSS_MODE
is selected for all price types, the price input form renders only gross part of prices. - If
NET_MODE
is selected, the net price inputs are displayed respectively.
Each store can have a default price mode and a price type selected. These values are used when customer has not selected currency or changed the price mode.
You can use these keys in environment configuration:
- For default price type:
$config[PriceProductConstants::DEFAULT_PRICE_TYPE] = 'DEFAULT';
- For default price mode:
$config[PriceProductConstants::DEFAULT_PRICE_TYPE] = 'DEFAULT';
$config[PriceConstants::DEFAULT_PRICE_MODE] = PriceConfig::PRICE_MODE_GROSS;
Set up a price mode switcher
-
Upgrade the Price module to version 5 or higher. For instructions, see Upgrade the Price module.
-
Add
\SprykerShop\Yves\PriceWidget\Widget\PriceModeSwitcherWidget
to the\Pyz\Yves\ShopApplication\ShopApplicationDependencyProvider::getGlobalWidgets()
method. This renders a drop-down list with the price mode selection. -
Add
\SprykerShop\Yves\PriceWidget\Plugin\Router\PriceWidgetRouteProviderPlugin
to the\Pyz\Yves\Router\RouterDependencyProvider::getRouteProvider()
method. -
Create a template for the component:
Pyz/Yves/Price/Theme/default/partial/price_mode_switcher.twig
{% if price_modes|length > 1 %}
<form method="GET" action="{{ path('price-mode-switch') }}" data-component="price-mode-switch">
<select name="price-mode" onchange="this.form.submit()">
{% for price_mode in price_modes %}
<option value="{{ price_mode }}" {{ (price_mode == current_price_mode) ? 'selected' : ''}}>{{ ('price.mode.' ~ price_mode | lower) | trans }}</option>
{% endfor %}
</select>
<input type="hidden" name="referrer-url" value="{{ app.request.requestUri }}" />
</form>
{% endif %}
The switch works only when cart contains at least one item.
Switching to net prices
To show only NET prices in the catalog, but use gross prices in cart and checkout, override getDefaultPriceMode
and change to PRICE_MODE_NET
in the \Spryker\Shared\Price\PriceConfig
class.
Example of changing the mode for all stores:
<?php
namespace Pyz\Shared\Price;
use Spryker\Shared\Price\PriceConfig as DefaultPriceConfig;
class PriceConfig extends DefaultPriceConfig
{
/**
* @return string
*/
public function getDefaultPriceMode(): string
{
return static::PRICE_MODE_NET;
}
}
Example of changing the mode for DE store:
<?php
namespace Pyz\Shared\PriceDE;
use Spryker\Shared\Price\PriceConfig as DefaultPriceConfig;
class PriceConfig extends DefaultPriceConfig
{
/**
* @return string
*/
public function getDefaultPriceMode(): string
{
return static::PRICE_MODE_NET;
}
}
Thank you!
For submitting the form