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
:
PriceRequestProduct
object which has a reference to the ProductNode
instance and a quantityPriceRequest
object, which has a reference to that PriceRequestProduct
(within the property priceRequestProductList
)PriceRequest
instance as an argument to the method requestPrice()
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( array( '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( array( '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" $priceService->getPriceProvider()->requestPrice($priceRequest);
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
.
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
:
Parameter | Description | Options | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
outputPrice | Enables actions on the output of the price value |
| |||||||||||||||||||||
vatLabel | Enables actions on the optional VAT label |
| |||||||||||||||||||||
schema | enables to ouput schema infos | If set then a schema itemprop="price" will be used: <span itemprop="price" content="1865.00">1.865,00 €</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( catalogElement, 'customerPrice', { 'outputPrice': {'property': 'priceExclVat', 'cssClass': 'price_med', 'currency': 'EUR', 'locale': 'de'}, 'vatLabel': {'show': true, 'cssClass': 'price_info smaller', 'text': 'Excluding VAT'|trans} } ) }}