Product¶
A Product defines the data related to one entry in the persistence layer. An application can have different types of product. A Product is always linked to a ProductProvider.
The link between the Product and the ProductProvider is done through the configuration file (see app/config/sonata/sonata_product.yaml under sonata_product namespace in the sandbox).
A ProductProvider is responsible of the Product lifecycle across the application:
- Compute prices
- Forms manager: front and backend
- Add a Product into the Basket
- Create an
OrderElementupon theProductinformation- Create variations
A ProductManager is responsible of the Product lifecycle with the database:
- Retrieve a Product type
- Save/Delete a Product type
- Find a Product type
A ProductSetManager is responsible of retrieving a set of different products, or specific products (it overrides the ProductManager).
A ProductFinder is responsible for finding matching products related to a given one. It will noticeably be used for cross-selling & up-selling matches.
Each Product prototype has its own type (defined in ProductType property).
You can use Sonata\Component\Product\Pool to retrieve related ProductProvider and ProductManager instances.
Product Variations¶
A Product can be duplicated. For instance, you can have a Product variated in many
colors but all the others parameters are the same.
The ProductProvider is responsible of the variation creation.
The variations are related to a parent Product. When you edit some data in your parent
Product, you can synchronize them with the ProductProvider.
A product and its variations can be synchronized : each field of the master product (except id, parent and the variation fields) is copied
from the master product to its variations.
The “variation fields” are used to differentiate the variations. Each of these fields can’t be modified from the parent product since they are “children specific”.
Product Template¶
Here are the blocks you can override in the product template.
The product sheet is based on the main product block, which is divided in 2 blocks:
product_leftblock, which includes:
product_carouselblock displays the gallery associated with the product or just the main image of the product.product_rightblock, which includes:
product_titleblock displays the product title,product_propertiesblock displays various information about the product (price, …) in the blocks listed below:
product_generic_propertiesblock displays generic information about the product (non variation fields):
product_unit_priceblock displays the unit price of the product,product_referenceblock displays the reference (aka SKU) of the product,product_description_shortblock shows the short description of the product,product_errorsblock shows the product page errors (unavailable stock, …),product_variations_form_blockblocks displays a form allowing to select the variation based variated properties (see sonata.product.block.variations_form for more information).product_deliveryblock displays product delivery information (to override by default),product_basketblock displays the “Add to basket” form (rendered bySonataBasketBundle:Basket:add_product_form.html.twigtemplate).
- Also, to allow the display of variations, a javascript block has been implemented :
product_javascript_initblock to register javascript functions related to products
Additionally, you can override those template blocks:
product_crossblock is used as a container to encapsulate the following :
product_cross_sellingblock that includes cross-selling block (rendered bySonataProductBundle:Product:view_similar.html.twigtemplate).product_full_descriptionblock is used to render the full description of the productproduct_commentblock is used to render comments related to the product
Product Helpers¶
Some Twig helpers are available for your templates:
sonata_product_providergives you the relatedProductProviderfor a givenProduct.sonata_product_has_variationsreturns true or false if theProducthas variations.sonata_product_has_enabled_variationsreturns true or false if theProducthas enabled variations.sonata_product_cheapest_variationreturns cheapest variation, based on its price.sonata_product_cheapest_variation_pricereturns the price of the cheapest variation.sonata_product_pricecalculates the price of aProduct.sonata_product_stockgets the available stock of aProduct.
Product Block Services¶
Some SonataBlock services are available as well:
sonata.product.block.variations_form¶
Renders the variations_form. A Product argument is needed.
- Options:
variations_propertiesis an array of properties you wish to display.form_routeandform_route_parametersare used to generate the URL to submit the variation form.form_field_optionsallows you to give an array of options to the form field generated. Note that this parameter will be applied to every form fields (their type is “choice”. See Symfony Choice Form Type for a list of available parameters.
sonata.product.block.recent_products¶
Renders the latest added products. By default, the number of displayed products is set to 5, but you may override this setting using the setting key name number.