Helpcenter +918010117117 https://cdn1.storehippo.com/s/573db3149f0d58741f0cc63b/ms.settings/5256837ccc4abf1d39000001/57614ef64256dc6851749879-480x480.png" support@storehippo.com https://www.facebook.com/StoreHippohttps://twitter.com/StoreHippohttps://www.linkedin.com/company/hippoinnovations/https://plus.google.com/+Storehippo/posts
B4,309-10 Spaze iTech Park, Sector 49, Sohna Road, 122001 Gurgaon India
call to replace anchor tags contains '/admin' in href

Restricting cart for single seller

You can add restrict cart for single seller functionality in your store. After adding this feature, the users can only add those items to a cart that are from a single seller. StoreHippo provides the startup widgets feature. Startup widgets contain logic to add behavior to storefronts. With the help of a startup widget, you can implement this feature in your store. 

Scenario

Suppose you want that the customers can only add products from one seller to the cart.

Steps

To restrict cart for a single seller, follow the steps mentioned below:

  • Go to the Site > Startup Widgets section in the StoreHippo Admin Panel.
  • Click the Add New button to add a new widget. A page will open up with multiple fields. 
  • In the Name field, enter the widget name.
  • Paste the following code in the Controller section.
    ms.app.addPrehook({entity: 'ms.carts', command: 'addItem'}, function(req, res, next) {
      if(!(ms.cart  && ms.cart.items && ms.cart.items.length)) return next()
    var checkseller = true;
      ms.cart.items.forEach(function(item){
        if(checkseller && item.seller != req.data.seller_id){
          checkseller = false;
          alert("Only one seller items can be purchased at a time")
          return res.error(406 ,"Only one seller items can be purchased at a time");
        }
      })
      if(checkseller) next()
    })
  • In the Append To field, select the Head option.
  • Select the Publish option to activate the widget.
  • Click the Save button to apply the changes. 

Now, the user will be allowed to add items from the single seller only. If the user tries to add an item from the other seller, the popup opens up notifying about the restriction.

Share:

2021-10-13T06:47:28.980Z