Advertisement
kiojiotisha

Untitled

Dec 1st, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. export function checkAndAdd (objArray,obj) {
  2. for (var i = 0; i < objArray.length; i++) {
  3. if (objArray[i].idProduct === obj.idProduct) {
  4. objArray[i].qtyProduct = objArray[i].qtyProduct + obj.qtyProduct;
  5. objArray[i].totalPrice = objArray[i].totalPrice + obj.totalPrice;
  6. return objArray; // exit loop and function
  7. }
  8. }
  9. objArray.push(obj);
  10. return objArray;
  11. }
  12.  
  13. handleIncrease(item){
  14. if(item.stockProduct < item.qtyProduct){
  15. alert('stock not enough');
  16. } else {
  17. let qty = item.qtyProduct + 1;
  18. item.qtyProduct = qty;
  19. hooks.consoleLog(TAG + "qty increase", {prod:item.qtyProduct,var:qty});
  20. item.totalPrice = qty * item.priceProduct;
  21. let listCart = this.state.listItem ? this.state.listItem : [];
  22. let newListCart = checkAdd = () =>{
  23. for (var i = 0; i < this.state.listItem.length; i++) {
  24. if (this.state.listItem[i].idProduct === item.idProduct) {
  25. this.state.listItem[i].qtyProduct = item.qtyProduct;
  26. this.state.listItem[i].totalPrice = item.totalPrice;
  27. return; // exit loop and function
  28. }
  29. }
  30. };
  31. this.setState({
  32. totalAll : this.state.listItem ? sumBy(this.state.listItem,'qtyProduct') : 0,
  33. totalAllPrice: this.state.listItem ? sumBy(this.state.listItem,'totalPrice') : 0,
  34. });
  35. this.props.addToCart(this.state.listItem);
  36. hooks.consoleLog(TAG + "new Cart list", {old:item, new:this.state.listItem});
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement