Product script services reference
Shopware\Core\Content\Product\Hook\Pricing\CheapestPriceFacade
The CheapestPriceFacade is a wrapper around the cheapest price of the product.
reset()
reset()allows to reset the cheapest price to the original price of the product.Examples:
Reset the product price to default
twig{% do variant.calculatedCheapestPrice.change(price) %}
change()
change()allows to overwrite the cheapest price of the current price scope. The provided price will be recalculated over the quantity price calculator to consider quantity, tax rule and cash rounding configurations.Arguments:
\PriceFacade|\PriceCollection|\CalculatedPrice|null|nullprice: You can provide different values to overwrite the cheapest price. In case of null, it uses the original single price of the product.boolrange: Allows to switch thehasRangeattribute of the cheapest priceDefault:
false
Examples:
Overwrite prices with a static defined collection
twig{% set price = services.price.create({ 'default': { 'gross': 15, 'net': 15} }) %} {% do variant.calculatedCheapestPrice.change(price) %}Overwrite the cheapest price with the original price
twig{% do variant.calculatedCheapestPrice.plus(price) %}Discount the cheapest price by 10%
twig{% do variant.calculatedCheapestPrice.discount(10) %}
getTotal()
getTotal()returns the total price for the line-item.Returns
floatThe total price as float.
getUnit()
getUnit()returns the unit price for the line-item.This is equivalent to the total price of the line-item with the quantity 1.
Returns
floatThe price per unit as float.
getQuantity()
getQuantity()returns the quantity that was used to calculate the total price.Returns
intReturns the quantity.
getTaxes()
getTaxes()returns the calculated taxes of the price.Returns
Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollectionReturns the calculated taxes.
getRules()
getRules()returns the tax rules that were used to calculate the price.Returns
Shopware\Core\Checkout\Cart\Tax\Struct\TaxRuleCollectionReturns the tax rules.
plus()
plus()allows a price addition of the current price scope. The provided price will be recalculated via the quantity price calculator.The provided price is interpreted as a unit price and will be added to the current unit price. The total price is calculated afterwards considering quantity, tax rule and cash rounding configurations.
Arguments:
Shopware\Core\Framework\DataAbstractionLayer\Pricing\PriceCollectionprice: The provided price can be a fetched price from the database or generated over thePriceFactorystatically
Examples:
Plus a static defined price to the existing calculated price
twig{% set price = services.price.create({ 'default': { 'gross': 1.5, 'net': 1.5} }) %} {% do product.calculatedPrice.plus(price) %}
minus()
minus()allows a price subtraction of the current price scope. The provided price will be recalculated via the quantity price calculator.The provided price is interpreted as a unit price and will reduce to the current unit price. The total price is calculated afterwards considering quantity, tax rule and cash rounding configurations.
Arguments:
Shopware\Core\Framework\DataAbstractionLayer\Pricing\PriceCollectionprice: The provided price can be a fetched price from the database or generated over thePriceFactorystatically
Examples:
Minus a static defined price to the existing calculated price
twig{% set price = services.price.create({ 'default': { 'gross': 1.5, 'net': 1.5} }) %} {% do product.calculatedPrice.minus(price) %}
discount()
discount()allows a percentage discount calculation of the current price scope. The provided value will be ensured to be negative viaabs(value) * -1.The provided discount is interpreted as a percentage value and will be applied to the unit price and the total price as well.
Arguments:
floatvalue: The percentage value of the discount. The value will be ensured to be negative viaabs(value) * -1.
Examples:
Adds a 10% discount to the existing calculated price
twig{% do product.calculatedPrice.discount(10) %}
surcharge()
surcharge()allows a percentage surcharge calculation of the current price scope. The provided value will be ensured to be negative viaabs(value).The provided surcharge is interpreted as a percentage value and will be applied to the unit price and the total price as well.
Arguments:
floatvalue: The percentage value of the surcharge. The value will be ensured to be negative viaabs(value).
Examples:
Adds a 10% surcharge to the existing calculated price
twig{% do product.calculatedPrice.surcharge(10) %}
create()
create()creates a newPriceCollectionbased on an array of prices.Returns
Shopware\Core\Framework\DataAbstractionLayer\Pricing\PriceCollectionReturns the newly created
PriceCollection.Arguments:
arrayprice: The prices for the new collection, indexed by the currency-id or iso-code of the currency.
Examples:
Create a new Price in the default currency.
twig{% set price = services.cart.price.create({ 'default': { 'gross': 19.99, 'net': 19.99} }) %}
Shopware\Core\Content\Product\Hook\Pricing\PriceCollectionFacade
The PriceCollectionFacade is a wrapper around the calculated price collection of a product. It allows to manipulate the quantity prices by resetting or changing the price collection.
reset()
- The
reset()functions allows to reset the complete price collection.
change()
The
change()function allows a complete overwrite of the product quantity pricesArguments:
arraychanges:
Examples:
Overwrite the product prices with a new quantity price graduation
twig{% do product.calculatedPrices.change([ { to: 20, price: services.price.create({ 'default': { 'gross': 15, 'net': 15} }) }, { to: 30, price: services.price.create({ 'default': { 'gross': 10, 'net': 10} }) }, { to: null, price: services.price.create({ 'default': { 'gross': 5, 'net': 5} }) }, ]) %}
count()
The
count()function returns the number of prices which are stored inside this collection.Returns
intReturns the number of prices which are stored inside this collection
Shopware\Core\Content\Product\Hook\Pricing\ProductProxy
The ProductProxy is a wrapper for the SalesChannelProductEntity. It provides access to all properties of the product, but also wraps some data into helper facade classes like PriceFacade or PriceCollectionFacade.
__get()
The
__get()function allows access to all properties of the SalesChannelProductEntityReturns
mixed|nullReturns the value of the property. The value is
mixeddue to the fact that all properties are accessed via__get()Arguments:
stringname: Name of the property to access
Examples:
Access the product properties
twig{ to: 30, price: services.price.create({ 'default': { 'gross': 10, 'net': 10} }) }, { to: null, price: services.price.create({ 'default': { 'gross': 5, 'net': 5} }) }, ]) %}
calculatedCheapestPrice()
The
calculatedCheapestPriceproperty returns the cheapest price of the product. The price object will be wrapped into aPriceFacadeobject which allows to manipulate the price.Returns
Shopware\Core\Checkout\Cart\Facade\PriceFacade|nullReturns a
PriceFacadeif the product has a calculated cheapest price, otherwisenull
calculatedPrice()
The
calculatedPriceproperty returns the price of the product. The price object will be wrapped into aPriceFacadeobject which allows to manipulate the price.Returns
Shopware\Core\Checkout\Cart\Facade\PriceFacade|nullReturns a
PriceFacadeif the product has a price, otherwisenull
calculatedPrices()
The
calculatedPricesproperty returns the price of the product. The price object will be wrapped into aPriceCollectionFacadeobject which allows to manipulate the collection.Returns
Shopware\Core\Content\Product\Hook\Pricing\PriceCollectionFacade|nullReturns a
PriceCollectionFacadeif the product has graduated prices, otherwisenull