Product script services reference
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 debug.dump(product.calculatedPrice.unit, 'discount') %} {% do product.calculatedPrice.surcharge(10) %} {% do debug.dump(product.calculatedPrice.unit, 'surcharge') %}
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