cancel
Showing results for 
Search instead for 
Did you mean: 

can any one explain the price logic ? Magento 2

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

can any one explain the price logic ? Magento 2

Hi guys, actually am trying to apply the price logic to product description  to get the child description when am going to click a swatch. For that  i need to understand the below code 

can any one explain it ?

 

<script>
require([
'jquery',
'priceBox'
], function($){
var dataPriceBoxSelector = '[data-role=priceBox]',
dataProductIdSelector = '[data-product-id=<?= $block->escapeHtml($_product->getId()) ?>]',
priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector);
priceBoxes = priceBoxes.filter(function(index, elem){
return !$(elem).find('.price-from').length;
});
priceBoxes.priceBox({'priceConfig': <?= /* @escapeNotVerified */ $block->getJsonConfig() ?>});
});
</script>

1 ACCEPTED SOLUTION

Accepted Solutions

Re: can any one explain the price logic ? Magento 2

Below price logic is used for only Bundle products.

 

dataPriceBoxSelector is used for getting  DOM of '[data-role=priceBox]'

dataProductIdSelector is getting DOM with [data-product-id=prodctId]

 

PriceBoxes is used for fetch Object of concatenating of dataPriceBoxSelector and dataProductIdSelector.

 

So your jQuery object look like  jQuery('[data-role=priceBox][data-product-id=45]') where 45 is your product id.

 

Now based on the above criteria below condition skip the div with class price-box.price-final_price, in bundle product. price-box.price-final_price DOM element used for display static price in bundle product like, 

From
$99.00
To
$489.00

So When priceBox Js is called at that time, skip the Dom for Static price display in bundle product using below condition,

pricesBoxes = priceBoxes.filter(function(index, elem){
      return !$(elem).find('.price-from').length;
});

and pass only Price Div which contains dynamic value based on bundle option changes.

 

So above logic is used for only bundle product with Div has price-box price-final_price class to skip it and only valid div class wil be pass using priceBox js with product value.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

View solution in original post

1 REPLY 1

Re: can any one explain the price logic ? Magento 2

Below price logic is used for only Bundle products.

 

dataPriceBoxSelector is used for getting  DOM of '[data-role=priceBox]'

dataProductIdSelector is getting DOM with [data-product-id=prodctId]

 

PriceBoxes is used for fetch Object of concatenating of dataPriceBoxSelector and dataProductIdSelector.

 

So your jQuery object look like  jQuery('[data-role=priceBox][data-product-id=45]') where 45 is your product id.

 

Now based on the above criteria below condition skip the div with class price-box.price-final_price, in bundle product. price-box.price-final_price DOM element used for display static price in bundle product like, 

From
$99.00
To
$489.00

So When priceBox Js is called at that time, skip the Dom for Static price display in bundle product using below condition,

pricesBoxes = priceBoxes.filter(function(index, elem){
      return !$(elem).find('.price-from').length;
});

and pass only Price Div which contains dynamic value based on bundle option changes.

 

So above logic is used for only bundle product with Div has price-box price-final_price class to skip it and only valid div class wil be pass using priceBox js with product value.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial