Skip to content

Instantly share code, notes, and snippets.

@rafaelpatro
Last active June 17, 2020 01:56
Show Gist options
  • Save rafaelpatro/1d84efa44b4db6315d67a47aaa6791c3 to your computer and use it in GitHub Desktop.
Save rafaelpatro/1d84efa44b4db6315d67a47aaa6791c3 to your computer and use it in GitHub Desktop.
Magento Catalog Product View shows Credit Card Installments
/**
* Credit Card Installments to Product Page
*
* Author:
* Rafael Patro <rafaelpatro@gmail.com>
*
* Intallation:
* Configure the variables ccording to your credit card plan.
* maxInstallments (integer) Maximum number of installments the cc plan accept
* minPlotValue (number) Minimum installment value
*
* Add a CMS Static Block applying the entire script below.
* Add a Widget to pages you want.
*
* License:
* GNU General Public License <http://www.gnu.org/licenses/>.
*/
(function(){
Element.addMethods({
getPriceFloat: function(elem) {
var textPrice = elem.textContent; // U$100.00
var stringPrice = textPrice.replace(/[^\d]/g, ''); // 10000
var stringFloat = stringPrice.replace(/(.+)(\d\d)/g, '$1.$2'); // 100.00
return parseNumber(stringFloat);
}
});
var CatalogProductViewCc = function() {
this.maxInstallments = 6, // e.g. {{config path="payment/cc_module/max_installments"}}
this.minPlotValue = 10, // e.g. {{config path="payment/cc_module/min_installment_value"}}
this.label = {
applyUpTo: 'Apply up to',
or: 'or',
of: 'of ',
currency: 'U$',
decimal: '.',
withOutInterest: 'without interest on card'
}
return this;
};
CatalogProductViewCc.prototype = {
getHtmlBlock: function(elem) {
var ul = new Element('ul', {class:"product-pricing tier-prices product-view-cc"});
for (var i = 2, price = elem.getPriceFloat(); i <= this.maxInstallments && (price/i) >= this.minPlotValue; i++) {
var plotView = (price/i).toFixed(2).replace('.', this.label.decimal);
ul.insert(
new Element('li')
.insert( new Element( 'span' ).update(i==2 ? this.label.applyUpTo : this.label.or) )
.insert( new Element('strong').update(' ' + i + 'x ') )
.insert( new Element( 'span' ).update(this.label.of) )
.insert( new Element('strong').update(this.label.currency + plotView) )
);
}
if (typeof plotView != 'undefined') {
ul.insert( new Element('li').update(this.label.withOutInterest) );
return ul;
}
return null;
},
show: function() {
$$('.product-view-cc').each(Element.remove);
if (priceBox = $$('.product-shop .price-info .price-box').last())
if (price = priceBox.select('.price').last())
priceBox.insert( {after:this.getHtmlBlock(price)} );
return this;
},
init: function() {
var _this = this;
_this.show();
$$('#product_addtocart_form').each(function(elem){
elem.observe('change', _this.show.bind(_this));
});
return this;
}
};
new CatalogProductViewCc().init();
})();
@rafaelpatro
Copy link
Author

Olá!

Este módulo é compatível com com Magento 2.3.5?

boa noite @rjslegall
Não. É compatível somente com M1.9, no tema RWD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment