/   /   /  OroCommerce For Developers: Some lines about prices rendering in frontend

Note:

For more extensions and themes visit our store

OroCommerce For Developers: Some lines about prices rendering in frontend


The pricing bundle is the kernel of management of price system for OroCommerce B2B . In frontend  the price get showed by system layout based on service :

  1.  
  2.     oro_pricing.layout.data_provider.frontend_product_prices:
  3.         class: 'Oro\Bundle\PricingBundle\Layout\DataProvider\FrontendProductPricesProvider'
  4.         arguments:
  5.             - '@oro_pricing.model.product_price_scope_criteria_request_handler'
  6.             - '@oro_product.provider.product_variant_availability_provider'
  7.             - '@oro_pricing.user_currency_manager'
  8.             - '@oro_pricing.formatter.product_price_formatter'
  9.             - '@oro_pricing.provider.product_price'
  10.         tags:
  11.             - { name: layout.data_provider, alias: frontend_product_prices }
  12.  

This service is layout provider which give you the ability to get price list of specific product , the process of rendering price for top selling products fro example starts by importing oro_product_list which import   oro_product_list_item so to customization of this path you can find :
vendor/oro/commerce/src/Oro/Bundle/PricingBundle/Resources/views/layouts/blank/imports/oro_product_list_item/price.yml which contain:

  1.  
  2. layout:
  3.     imports:
  4.         -
  5.             id: oro_product_price
  6.             root: __product_secondary_content_first_container
  7.     actions: []
  8.  

is responsible to render the price of every item on to selling if you go to explore oro_product_price you will find the content:

  1.  
  2. layout:
  3.     actions:
  4.         - '@setBlockTheme':
  5.             themes: 'OroPricingBundle:layouts:blank/imports/oro_product_price/oro_product_price.html.twig'
  6.         - '@addTree':
  7.             items:
  8.                 __product_price_container:
  9.                     blockType: product_prices
  10.                     options:
  11.                         productPrices: '=product ? data["frontend_product_prices"].getByProduct(product) : []'
  12.                         attributeFamily: '=context.offsetExists("attribute_family") ? context["attribute_family"] : null'
  13.                         isPriceUnitsVisible: '=product ? data["oro_price_unit_visibility"].isPriceUnitsVisibleByProduct(product) : true'
  14.  

So you can now explore that  layout provider frontend_product_prices used to get price list of the current item :
 productPrices: '=product ? data["frontend_product_prices"].getByProduct(product) : []'


if you go to class  Oro\Bundle\PricingBundle\Layout\DataProvider\FrontendProductPricesProvider and explore the function :

  1.  
  2.     public function getByProducts($products)
  3.     {
  4.         $this->prepareAndSetProductsPrices($products);
  5.         $productPrices = [];
  6.         foreach ($products as $product) {
  7.             $productId = $product->getId();
  8.             if ($this->productPrices[$productId]) {
  9.                 $productPrices[$productId] = $this->getProductPrices($productId);
  10.             }
  11.         }
  12.         return $productPrices;
  13.     }
  14.  

You get the combined price list of current product. 

Video about subject

Comments

Related Posts

make your store more efficient

Solving problems. With open source technology. Professional results. That’s what makes Ibnab your best choice

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.