added direct to cart page. fixed bug in product details page. added qty valid.
このコミットが含まれているのは:
ベンダーファイル
+15
-4
@@ -112,8 +112,9 @@ function initAddToCart(){
|
||||
const data = getCartData();
|
||||
|
||||
let id = window.location.search.split('=')[1];
|
||||
const qty = parseInt($('#addtocart').data('qty'));
|
||||
if(!data){
|
||||
|
||||
|
||||
let cartObj = {};
|
||||
debugger;
|
||||
|
||||
@@ -122,7 +123,8 @@ function initAddToCart(){
|
||||
price:$('.price').html(),
|
||||
quantity:$('#quantity').val(),
|
||||
img:$('.productDetailsMain img').attr('src'),
|
||||
sku:$('#skudetailitem').val()
|
||||
sku:$('#skudetailitem').val(),
|
||||
totalQty:qty
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +148,8 @@ function initAddToCart(){
|
||||
price:price,
|
||||
quantity: parseInt(data[sku].quantity)+parseInt(quantity),
|
||||
img:img,
|
||||
sku:sku
|
||||
sku:sku,
|
||||
totalQty:qty
|
||||
}
|
||||
addtoCart(data);
|
||||
}else{
|
||||
@@ -155,7 +158,8 @@ function initAddToCart(){
|
||||
price:price,
|
||||
quantity:parseInt(quantity),
|
||||
img:img,
|
||||
sku:sku
|
||||
sku:sku,
|
||||
totalQty:qty
|
||||
}
|
||||
addtoCart(data);
|
||||
}
|
||||
@@ -170,6 +174,13 @@ function initAddToCart(){
|
||||
$('#addtocart').html('Add to cart')
|
||||
$('#addtocart').off().click((e)=>{
|
||||
debugger
|
||||
$('.insufficientqty').addClass('d-none');
|
||||
const qty = parseInt($('#addtocart').data('qty'));
|
||||
debugger;
|
||||
if(parseInt($('#quantity').val())>qty){
|
||||
$('.insufficientqty').removeClass('d-none');
|
||||
return;
|
||||
}
|
||||
$('#addtocart').off().click(function (el){
|
||||
window.location.href = '/shopping-cart.html';
|
||||
|
||||
|
||||
ベンダーファイル
+43
-7
@@ -5,6 +5,17 @@ function shoppingCartInit() {
|
||||
|
||||
shoppingCartAppend();
|
||||
|
||||
let insufficientQtyActions = {
|
||||
moreQtyAdd(e){
|
||||
$(e.target).parents('.mainselectcontainer').find('.insufficientqty').removeClass('d-none');
|
||||
},
|
||||
|
||||
moreQtyRemove(e){
|
||||
$(e.target).parents('.mainselectcontainer').find('.insufficientqty').addClass('d-none');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function shoppingCartAppend() {
|
||||
let data = getCartData();
|
||||
|
||||
@@ -47,13 +58,23 @@ function shoppingCartInit() {
|
||||
$('.quantitySelect').each(function (i, element) {
|
||||
if (!$(element).hasClass('d-none')) {
|
||||
$(element).off().change(function (e) {
|
||||
insufficientQtyActions.moreQtyRemove(e);
|
||||
let num = e.target.value;
|
||||
if (num == 5) {
|
||||
$(e.target).parents('.mainselectcontainer').find('.inputcartaddmore').removeClass('d-none');
|
||||
$(e.target).addClass('d-none');
|
||||
$(e.target).parents('.mainselectcontainer').find('.inputcartaddmore button').off().click(function (item) {
|
||||
const val = $(item.target).parent().find('input').val()
|
||||
const val = $(item.target).parent().find('input').val();
|
||||
debugger;
|
||||
let totalQty = $(this).parents('.mainselectcontainer').data('qty');
|
||||
|
||||
if(val<=0 || totalQty< val){
|
||||
insufficientQtyActions.moreQtyAdd(e);
|
||||
return;
|
||||
}
|
||||
|
||||
let id = $(item.target).parents('.mainselectcontainer').data('id');
|
||||
|
||||
updateCartQuantity(id, val);
|
||||
// $(item.target).parents('.mainselectcontainer').find('.inputcartaddmore').addClass('d-none');
|
||||
// $(e.target).removeClass('d-none');
|
||||
@@ -62,6 +83,11 @@ function shoppingCartInit() {
|
||||
|
||||
})
|
||||
} else {
|
||||
const val = $(item.target).parent().find('input').val();
|
||||
if(val<=0 || totalQty< val){
|
||||
insufficientQtyActions.moreQtyAdd(e);
|
||||
return;
|
||||
}
|
||||
let id = $(e.target).parents('.mainselectcontainer').data('id');
|
||||
updateCartQuantity(id, num);
|
||||
setLengthCart();
|
||||
@@ -70,7 +96,17 @@ function shoppingCartInit() {
|
||||
});
|
||||
} else {
|
||||
$(element).parents('.mainselectcontainer').find('.inputcartaddmore button').off().click(function (item) {
|
||||
debugger;
|
||||
|
||||
const val = $(item.target).parent().find('input').val()
|
||||
let totalQty = $(this).parents('.mainselectcontainer').data('qty');
|
||||
|
||||
if(val<=0 || totalQty< val){
|
||||
insufficientQtyActions.moreQtyAdd(item);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let id = $(item.target).parents('.mainselectcontainer').data('id');
|
||||
updateCartQuantity(id, val);
|
||||
// $(item.target).parents('.mainselectcontainer').find('.inputcartaddmore').addClass('d-none');
|
||||
@@ -132,11 +168,11 @@ function shoppingCartInit() {
|
||||
});
|
||||
}
|
||||
|
||||
function getQuantityHTML(value, id) {
|
||||
return `<div data-id="${id}" class="mainselectcontainer w-100">
|
||||
function getQuantityHTML(value,totalQty, id) {
|
||||
return `<div data-id="${id}" data-qty="${totalQty}" class="mainselectcontainer w-100">
|
||||
<div class="w-50">
|
||||
|
||||
<select class="quantitySelect form-select ${value >= 5 ? 'd-none' : ''}" value="${value}">
|
||||
<select class="quantitySelect form-select ${value >= 5 ? 'd-none' : ''}" value="${value}">
|
||||
<option ${value == 1 ? 'selected="selected"' : null} value="1">
|
||||
1
|
||||
</option>
|
||||
@@ -159,11 +195,11 @@ function shoppingCartInit() {
|
||||
<input min="1" class="form-control" style="max-width:100px" value="${value <= 5 ? '5' : value}" type="number" />
|
||||
<button class="btn border-none bg-info">Add</button>
|
||||
</div>
|
||||
|
||||
<div class="text-danger pt-2 insufficientqty d-none">Insufficient quantity</div>
|
||||
</div>`
|
||||
}
|
||||
|
||||
function shoppingCartDesktopHTML({ id, img, name, price, description, quantity, total }) {
|
||||
function shoppingCartDesktopHTML({ id, img, name, price, description, quantity, total,totalQty }) {
|
||||
const [currencySymbol,amt] = getCurrencySymbol(price);
|
||||
return `
|
||||
<div class="row bg-white border-bottom py-4 d-flex justify-content-center align-items-center">
|
||||
@@ -179,7 +215,7 @@ function shoppingCartInit() {
|
||||
</div>
|
||||
<div class="col-md-2 ">
|
||||
|
||||
${getQuantityHTML(quantity, id)}
|
||||
${getQuantityHTML(quantity,totalQty, id)}
|
||||
</div>
|
||||
<div class="col-md-2 ">
|
||||
<div class="d-flex justify-content-between w-100">
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする