Skip to content

Product script services reference

You are viewing the next version (v6.7) of the documentation.
Click here to switch to the stable version (v6.6), or use the version switcher on the left to navigate between versions.

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 prices

  • Arguments:

    • array changes:
  • 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 int

    Returns 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 SalesChannelProductEntity

  • Returns mixed | null

    Returns the value of the property. The value is mixed due to the fact that all properties are accessed via __get()

  • Arguments:

    • string name: 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 calculatedCheapestPrice property returns the cheapest price of the product. The price object will be wrapped into a PriceFacade object which allows to manipulate the price.

  • Returns Shopware\Core\Checkout\Cart\Facade\PriceFacade | null

    Returns a PriceFacade if the product has a calculated cheapest price, otherwise null

calculatedPrice()

  • The calculatedPrice property returns the price of the product. The price object will be wrapped into a PriceFacade object which allows to manipulate the price.

  • Returns Shopware\Core\Checkout\Cart\Facade\PriceFacade | null

    Returns a PriceFacade if the product has a price, otherwise null

calculatedPrices()

  • The calculatedPrices property returns the price of the product. The price object will be wrapped into a PriceCollectionFacade object which allows to manipulate the collection.

  • Returns Shopware\Core\Content\Product\Hook\Pricing\PriceCollectionFacade | null

    Returns a PriceCollectionFacade if the product has graduated prices, otherwise null