Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function checkAndAdd (objArray,obj) {
- for (var i = 0; i < objArray.length; i++) {
- if (objArray[i].idProduct === obj.idProduct) {
- objArray[i].qtyProduct = objArray[i].qtyProduct + obj.qtyProduct;
- objArray[i].totalPrice = objArray[i].totalPrice + obj.totalPrice;
- return objArray; // exit loop and function
- }
- }
- objArray.push(obj);
- return objArray;
- }
- handleIncrease(item){
- if(item.stockProduct < item.qtyProduct){
- alert('stock not enough');
- } else {
- let qty = item.qtyProduct + 1;
- item.qtyProduct = qty;
- hooks.consoleLog(TAG + "qty increase", {prod:item.qtyProduct,var:qty});
- item.totalPrice = qty * item.priceProduct;
- let listCart = this.state.listItem ? this.state.listItem : [];
- let newListCart = checkAdd = () =>{
- for (var i = 0; i < this.state.listItem.length; i++) {
- if (this.state.listItem[i].idProduct === item.idProduct) {
- this.state.listItem[i].qtyProduct = item.qtyProduct;
- this.state.listItem[i].totalPrice = item.totalPrice;
- return; // exit loop and function
- }
- }
- };
- this.setState({
- totalAll : this.state.listItem ? sumBy(this.state.listItem,'qtyProduct') : 0,
- totalAllPrice: this.state.listItem ? sumBy(this.state.listItem,'totalPrice') : 0,
- });
- this.props.addToCart(this.state.listItem);
- hooks.consoleLog(TAG + "new Cart list", {old:item, new:this.state.listItem});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement