Quickcart and qty increments
Hi to everybody,
as you know, the increment qty of a product does not work in the product page and in the quickcart (for instance, if I set a product with qty increment of 10, so it can be bought just quantity of 10, 20, 30 etc, the arrows to change the product qty don't follow the increment).
I solved it in the product page (if you need the code just ask, it's quite simple), but I cannot do it in the quickcart.
The problem is that, if I try to pass a variable in from the minicart.phtml:
<script type="text/x-magento-init">
{
"[data-block='minicart']": {
"Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout();?>
},
"*": {
"Magento_Ui/js/block-loader": "<?php /* @escapeNotVerified */ echo $block->getViewFileUrl('images/loader-1.gif'); ?>",
"WeltPixel_QuickCart/js/quickcart": {
"test": "123"
}
}
}
I'm having trouble to use it in quickcart.js since I cannot understand how to use the return function (config) to retrieve the data.
I modified the quickcart.js like this to retrieve the variable (not it prints the var on the console and it works) but it seem that I cannot use the arrows anymore:
define(['jquery', 'jquery/ui', 'domReady'], function ($) {
"use strict";
return function(config) {
console.log(config.test);
var quickcart =
{
initialize: function (mobileBreakpoint) {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
var that = this;
console.log('inizio');
$('.quickcart-content-wrapper').on('click', '.qty-update', function () {
console.log('inizio');
quickcart.updateQty($(this));
});
$('.quickcart-content-wrapper').on('click', '.qty-update-v2', function () {
console.log('inizio');
quickcart.updateQty($(this));
});
$('.quickcart-content-wrapper').on('click', '.action.delete', function () {
console.log('inizio');
$('#btn-minicart-close').trigger('click');
$(".logo").removeAttr('style');
});
$('.quickcart-content-wrapper').on('click', '.action.close', function () {
console.log('inizio');
$(".logo").removeAttr('style');
that.removeTabIndexQtyButtons();
});
$('.showcart').on('click', function () {
console.log('inizio');
$(".logo").attr('style', 'z-index: 0');
that.addTabIndexQtyButtons();
if (quickcart.checkSafariBrowser()) {
$('.page-wrapper').css('overflow-x', 'visible');
}
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
$('.block-quickcart').addClass('quickCartIE');
}
});
$('.quickcart-content-wrapper').on('click', '.close', function () {
$('.page-wrapper').css('overflow-x', 'hidden');
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
$('.block-quickcart').removeClass('quickCartIE');
console.log('inizio');
}
});
$('.quickcart-content-wrapper').on('click', '.product-item-photo, .product-item-name a', function () {
var href = $(this).attr('href');
window.location.href = href;
console.log('inizio');
});
if (this.openMinicart()) {
var minicart = $('.minicart-wrapper');
minicart.on('contentLoading', function () {
minicart.on('contentUpdated', function () {
if (that.shouldOpenMinicart(mobileBreakpoint)) {
$(".logo").attr('style', 'z-index: 0');
if (quickcart.checkSafariBrowser()) {
$('.page-wrapper').css('overflow-x', 'visible');
}
$('.logo').focus();
minicart.find('[data-role="dropdownDialog"]').dropdownDialog("open");
}
});
});
}
},
addTabIndexQtyButtons: function () {
let plusQty = $('.item-plus'),
minusQty = $('.item-minus'),
miniCartWrapper = $('.quickcart-content-wrapper');
miniCartWrapper.addClass('isOpen');
if (miniCartWrapper.hasClass('isOpen')) {
plusQty.attr('tabindex', '0');
minusQty.attr('tabindex', '0');
}
},
removeTabIndexQtyButtons: function () {
let plusQty = $('.item-plus'),
minusQty = $('.item-minus'),
miniCartWrapper = $('.quickcart-content-wrapper');
if (miniCartWrapper.hasClass('isOpen')) {
plusQty.attr('tabindex', '-1');
minusQty.attr('tabindex', '-1');
}
miniCartWrapper.removeClass('isOpen');
},
openMinicart: function () {
if (window.openMinicart == 1) {
return true;
} else {
return false;
}
},
shouldOpenMinicart: function (mobileBreakpoint) {
if ((window.shouldOpenMinicart == 1) && this.shouldOpenMinicartBasedOnDeviceOptions(mobileBreakpoint)) {
return true;
} else {
return false;
}
},
shouldOpenMinicartBasedOnDeviceOptions: function (mobileBreakpoint) {
var windowWidth = jQuery(window).width();
switch (window.openMinicartDisplayOptions) {
case 'desktop':
return windowWidth > mobileBreakpoint;
break;
case 'mobile':
return windowWidth <= mobileBreakpoint;
break;
default:
return true;
}
},
updateQty: function (el) {
var qtyContainer = el.closest('.details-qty'),
currentQty = parseFloat(qtyContainer.find('input').val());
console.log('aaa');
console.log('this.diego');
console.log(parseInt(this.diego, 10));
console.log('el.diego');
console.log(el.diego);
console.log(parseInt(el.diego, 10));
if (el.hasClass('item-plus')) {
var newQty = currentQty + 160;
this.updateItemQty(el, newQty);
} else {
if (currentQty > 1) {
var newQty = parseFloat(currentQty) - 2;
this.updateItemQty(el, newQty);
} else {
this.deleteCartItem(el);
}
}
},
showSpinner: function (el) {
el.closest('.details-qty').find('.spinner').show();
this.updateUpdateCart(el);
},
updateItemQty: function (el, qty) {
el.closest('.details-qty').find('input').val(qty).hide();
this.showSpinner(el);
},
updateUpdateCart: function (el) {
el.closest('.details-qty').find('button.update-cart-item').trigger('click');
},
deleteCartItem: function (el) {
el.closest('.product-item-details').find('.product .action.delete').trigger('click');
},
checkSafariBrowser: function () {
var is_safari = navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1 && navigator.userAgent.indexOf('Android') == -1
if (is_safari) {
return true;
} else {
return false;
}
}
};
return quickcart;
}
});Please sign in to leave a comment.
Comments
0 comments