I am currently using a mixin to override the default use of the reloadPrice method as found in "Magento_Catalog/js/price-box", but I need to pass the final.price value through a PHP module to re-format the price.
I have already tried creating a map, then passing through the data from the phtml to the Javascript but i'm unsure whether or not that is correct or was implemented correctly to start with.
// requirejs-config.js
var config = {
config: {
mixins: {
'Magento_Catalog/js/price-box': {
'Jabberdog_Price/js/price-box': true
}
}
}
};
// price-box.js
define([
'jquery',
'Magento_Catalog/js/price-utils',
'underscore',
'mage/template',
'jquery/ui'
], function ($, utils, _, mageTemplate) {
'use strict';
return function (priceBox) {
return $.widget('mage.priceBox', priceBox, {
/**
* Render price unit block.
*/
reloadPrice: function reDrawPrices() {
var priceFormat = (this.options.priceConfig && this.options.priceConfig.priceFormat) || {},
// override the priceTemplate?
priceTemplate = mageTemplate(this.options.priceTemplate);
_.each(this.cache.displayPrices, function (price, priceCode) {
price.final = _.reduce(price.adjustments, function (memo, amount) {
return memo + amount;
}, price.amount);
// run price.final through our PHP module
console.log(price.final);
price.formatted = utils.formatPrice(price.final, priceFormat);
// this needs to run through the PHP module also?
/*$('[data-price-type="' + priceCode + '"]', this.element).html(priceTemplate({
data: price
}));*/
}, this);
}
});
};
});
I expect the output of the final.price to pass through a PHP module which converts the price into an image, so the result is the price printed back on the view as an image and not text.