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>
Solved! Go to Solution.
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.
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.