Vue-Storefront | show item in cart for the item added on magento cart for same sku and id

400 views Asked by At

Currently i have connected the vue-storefront to magento2 and everything is working as expected

There is a requirement where if another same product with same sku and id but with an additional attribute of options is added in the cart on magento's end, it should show as different item in cart on vue storefront.

almost like bundle product of magento, but in this its added on magento cart as separate item.

So when vuestore pulls items from server i can see all the items including same sku items.

But as it has the same sku and id. it is not added on vuestore cart.

I have gone through vue-storefront core code, and made some changes for my testings.

Such as the following code where it is doing the comparisons.

added this in core/modules/cart/helpers/productsEquals.ts

  if (getAdhesiveGroutOptions(product1, 'options').length || getAdhesiveGroutOptions(product2, 'options').length) {
    // in admin panel we can add different sku for specific custom option so we can't rely on 'sku'
    // by default we want to check server_item_id ('id'), we can also use 'checksum'

    if(product1.sku && product2.sku && product1.sku === product2.sku){
      //Seems like they are same products, so just check if their options are similar as well.
      console.log('FullObjectAdhesiveGrouts', product1, product2);
      let adhesiveGroutOptions2 = getAdhesiveGroutOptions(product2, 'options');
      let adhesiveGroutOptions1 = getAdhesiveGroutOptions(product1, 'options');
      console.log('JustTheAdhesiveGroutOptions', adhesiveGroutOptions1, adhesiveGroutOptions2);
      if(product1.item_id){
        if(product2.totals && product2.totals.options && product2.totals.options.length > 0){
          return product1.item_id === product2.totals.item_id
        }
      }else{
        if(product2.item_id && product1.totals && product1.totals.options && product1.totals.options.length > 0){
          return product2.item_id === product1.totals.item_id
        }
      }
    }
    return false;
  }

But still im trying to figure out from where this additional condition exists where it checks for similar sku.

As if i add another product with different sku and product id, then on page load of vuestore the pull call updates that newly added item on magento to the vuestore cart as well.

0

There are 0 answers