Quickcart and qty increments
Hello,
the quickcart qty increment (and also the qty increment in the product page) is not using the qty increment assigned to a product in the product advanced inventory.
For instance, if I set a qty increment of 10 to a product (so the product can be bought just in quantities of 10, 20, 30 ect), the arrows in the product page and in the quickcart don't follow it but increments of 1 generating an error (since the product can be incremented just by one...)
I solved it in the product page (it was quite simple, just ask if you need the code).
But in the quickcart I'm having troubles in passing the variable from mincart.phtml to quickcart.js.
in the minicart.phtml I pass the variable by the text/x-magento-init:
<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": {
"diego": "123"
}
}
}
and in quickcart.js I get the variable with the standard return function (config) (and it works just for getting the variable, in the below code printed in the console as output).
The problem is that, if I set the normal code in this function, the arrows doesn't work anymore...).
and I cannot find another way to do it.
The code:
define(['jquery', '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;
}
});
Thank you if anybody can help me :)
Please sign in to leave a comment.
Comments
0 comments