Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 20 Next »

How to get a customer price for a single ProductNode

To request a specific price from a price engine for a ProductNode, following steps are needed. The price engine specific price will be called "customer price" from now on as it will be associated to the property "customerPrice" in the ProductNode:

  1. Instantiate a PriceRequestProduct object which has a reference to the ProductNode instance and a quantity
  2. Instantiate a PriceRequest object, which has a reference to that PriceRequestProduct (within the property priceRequestProductList)
  3. Request the price engine via the price service by giving the PriceRequest instance as an argument to the method requestPrice()

Example: Controller with price request process
use Siso\Bundle\PriceBundle\Model\PriceRequestProduct;
use Siso\Bundle\PriceBundle\Model\PriceRequest;
use Silversolutions\Bundle\EshopBundle\Product\ProductNode;
/** @var $priceService \Siso\Bundle\PriceBundle\Service\PriceService */
$priceService = $this->get('siso_price.price_service');
// 1.: Create an instance of PriceRequestProduct
/** @var $priceRequestProduct $priceRequestProduct */
$priceRequestProduct = new PriceRequestProduct(
        'productNode' => $catalogData,
        'quantity' => 1,
// if e.g. the underlaying price engine requires additional
// information, the property "headerInfo" can be used
$headerInfo = array('customerNumber' => 10000);
// 2.: Create an instance of PriceRequest and associate the
// previous instantiated $priceRequestProduct as an element
$priceRequest = new PriceRequest(
        'priceRequestProductList' => array($priceRequestProduct),
        'headerInfo' => $headerInfo,
// 3.: Finally request price via the price provider given in the 
// price service.The product node within
// $priceRequest->priceRequestProductList[0]->productNode
// will be enriched with a PriceField containing a Price instance
// in the property "customerPrice"

As you can see from the comments, the property "customerPrice" for the ProductNode will be set with an instance of PriceField. This PriceField contains a property "price" with an instance of Price.

Render PriceField

To render the customerPrice (instance of PriceField) of the ProductNode, you might use the Twig function ses_render_field() within the template MyTestBundle::product.html.twig.

{{ ses_render_field(catalogElement, 'customerPrice') }}

Following optional render parameters are available for a PriceField:

outputPriceEnables actions on the output of the price value
idOptional string of ID to use for price"" (undefined)
cssClassOptional string of CSS class(es) to use for price"" (undefined)
localeTwo digit locale code (e.g.: "en", "us", "de")"en"
currencyThree digit currency code (e.g.: EUR, GBP, USD)price.currency
propertyProperty of price field used for outputted valueprice.price
rawPrice is outputted without any HTML tags, if truefalse (undefined)
vatLabelEnables actions on the optional VAT label
idOptional string of ID to use for VAT label"" (undefined)
showVAT label is shown, if truefalse (undefined)
cssClassOptional string of CSS class(es) to use for VAT label"" (undefined)
textOverride of the outputted text

Default text depending on price.isVatPrice ("Including VAT" or "Excluding VAT")

rawVAT label is outputted without any HTML tags, if truefalse (undefined)
schemaenables to ouput schema infos

If set then a schema


will be used:

<span itemprop="price" content="1865.00">1.865,00&nbsp;€</span>

Following example would output the value of property "priceExclVat" (property: "priceExclVat") from the price field in German (locale: "de") standard format with enforced used of the Euro sign (currency: "EUR"). The CSS class "price_med" is set to the price <p> tag. Furthermore a VAT label is shown below the price (show: true) with defined text "Excluding VAT" and CSS classes "price_info" and "smaller" to the VAT <p> tag.

{{ ses_render_field(
		'outputPrice': {'property': 'priceExclVat', 'cssClass': 'price_med', 'currency': 'EUR', 'locale': 'de'},
        'vatLabel': {'show': true, 'cssClass': 'price_info smaller', 'text': 'Excluding VAT'|trans}

Price Range for Variant Products

Often for one variant product we have different prices depending on the option.

On the product listing and detail page for this product the shop displays the price range for current customer. 

If means that there will be a label e.g. "Price from: 1600 EUR".

  • No labels