<commit_before>import { MutationTree } from 'vuex'
import * as types from '../../mutation-types'
import EventBus from '../../lib/event-bus'
import config from '../../lib/config'
import CartState from './types/CartState'

const mutations: MutationTree<CartState> = {
  /**
   * Add product to cart
   * @param {Object} product data format for products is described in /doc/ElasticSearch data formats.md
   */
  [types.CART_ADD_ITEM] (state, { product }) {
    const record = state.cartItems.find(p => p.sku === product.sku)
    if (!record) {
      let item = {
        ...product,
        qty: product.qty ? product.qty : 1
      }
      EventBus.$emit('cart-before-add', { product: item })
      state.cartItems.push(item)
    } else {
      record.qty += (product.qty ? product.qty : 1)
    }
  },
  [types.CART_SAVE] (state) {
    EventBus.$emit('cart-before-save', { items: state.cartItems })
    state.cartSavedAt = Date.now()
  },
  [types.CART_DEL_ITEM] (state, { product }) {
    EventBus.$emit('cart-before-delete', { items: state.cartItems })
    state.cartItems = state.cartItems.filter(p => p.sku !== product.sku && p.parentSku !== product.sku)
    EventBus.$emit('cart-after-delete', { items: state.cartItems })
    state.cartSavedAt = Date.now()
  },
  [types.CART_UPD_ITEM] (state, { product, qty }) {
    const record = state.cartItems.find(p => p.sku === product.sku)

    if (record) {
      EventBus.$emit('cart-before-update', { product: record })
      record.qty = qty
      EventBus.$emit('cart-after-update', { product: record })
      state.cartSavedAt = Date.now()
    }<commit_msg>Fix product incrementation in cart<commit_after>import { MutationTree } from 'vuex'
import * as types from '../../mutation-types'
import EventBus from '../../lib/event-bus'
import config from '../../lib/config'
import CartState from './types/CartState'

const mutations: MutationTree<CartState> = {
  /**
   * Add product to cart
   * @param {Object} product data format for products is described in /doc/ElasticSearch data formats.md
   */
  [types.CART_ADD_ITEM] (state, { product }) {
    const record = state.cartItems.find(p => p.sku === product.sku)
    if (!record) {
      let item = {
        ...product,
        qty: product.qty ? product.qty : 1
      }
      EventBus.$emit('cart-before-add', { product: item })
      state.cartItems.push(item)
    } else {
      record.qty += parseInt((product.qty ? product.qty : 1))
    }
  },
  [types.CART_SAVE] (state) {
    EventBus.$emit('cart-before-save', { items: state.cartItems })
    state.cartSavedAt = Date.now()
  },
  [types.CART_DEL_ITEM] (state, { product }) {
    EventBus.$emit('cart-before-delete', { items: state.cartItems })
    state.cartItems = state.cartItems.filter(p => p.sku !== product.sku && p.parentSku !== product.sku)
    EventBus.$emit('cart-after-delete', { items: state.cartItems })
    state.cartSavedAt = Date.now()
  },
  [types.CART_UPD_ITEM] (state, { product, qty }) {
    const record = state.cartItems.find(p => p.sku === product.sku)

    if (record) {
      EventBus.$emit('cart-before-update', { product: record })
      record.qty = qty
      EventBus.$emit('cart-after-update', { product: record })
      state.cartSavedAt = Date.now()
    }
{'fraction_non_alphanumeric': 0.16753926701570682, 'fraction_numerical': 0.0012319063751154912, 'mean_word_length': 2.936969696969697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1670492', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1086, 'n_words': 228}