Skip to content

Commit 89e8b94

Browse files
committed
make deliver options interactive
1 parent 7f71f8e commit 89e8b94

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

basic-projects/amazon-project/data/cart.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,18 @@ export function updateQuantityLabel(newQuantity, itemId){
6363
cartItem.quantity = newQuantity;
6464
}
6565
})
66+
};
67+
68+
export function updateDeliveryOption(productId, deliveryOptionId){
69+
let matchingItem;
70+
71+
cart.forEach((cartItem) => {
72+
if (productId === cartItem.productId) {
73+
matchingItem = cartItem;
74+
}
75+
});
76+
77+
matchingItem.deliveryOptionId = deliveryOptionId;
78+
79+
saveToStorage();
6680
};

basic-projects/amazon-project/scripts/checkout.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import {cart, removeFromCart, calculateCartQuantity, updateQuantityLabel} from '../data/cart.js'
1+
import {cart, removeFromCart, calculateCartQuantity, updateQuantityLabel, updateDeliveryOption} from '../data/cart.js'
22
import {products} from '../data/products.js'
33
import formatCurrency from './utils/price.js';
44
import deliveryOptions from '../data/delivery-options.js';
5-
import dayjs from 'https://cdn.jsdelivr.net/npm/dayjs/+esm';
65

76

87

@@ -181,4 +180,12 @@ document.querySelectorAll('.js-save-link')
181180
saveUpdatedQuantity(itemId);
182181

183182
})
184-
});
183+
});
184+
185+
document.querySelectorAll('.js-delivery-option')
186+
.forEach((element) => {
187+
element.addEventListener('click', () => {
188+
const {productId, deliveryOptionId} = element.dataset;
189+
updateDeliveryOption(productId, deliveryOptionId);
190+
})
191+
});

0 commit comments

Comments
 (0)