Disable Quantity for Product in Shopping Cart

Delford Chaffin asked on February 25, 2016 18:04

Is it possible to disable the quantity field for a particular product in the shopping cart?

Correct Answer

Delford Chaffin answered on February 25, 2016 23:08

This is how I ended up doing this if anyone has a similar case. In this case (reserved seat tickets), the likelihood of anyone changing the quantity was low, but I still wanted to trap it if they tried ...

using CMS.Ecommerce;
using CMS.EventLog;
using CMS.SettingsProvider;
using System.Collections.Generic;
using System.Linq;

[TicketItemEvents]
public partial class CMSModuleLoader
{
    private class TicketItemEventsAttribute : CMSLoaderAttribute
    {
        public override void Init()
        {
            ObjectEvents.Update.After += TicketItem_Update_After;
        }
        private void TicketItem_Update_After(object sender, ObjectEventArgs e)
        {
            try
            {
                ShoppingCartItemInfo item = (ShoppingCartItemInfo)e.Object;
                string _TicketSKUs = SettingsKeyProvider.GetStringValue("CMS.CustomSettings.MyCategory.TicketSKUs");
                List<string> _skuList = _TicketSKUs.Split(',').ToList();
                if (_skuList.Contains(item.SKUID.ToString()))
                {
                    if (item.CartItemUnits != 1)
                    {
                        item.CartItemUnits = 1;
                        item.SubmitChanges(false);
                        EventLogProvider.LogInformation("TicketSeating", "TicketItem_Update_After", "User tried to update quantity of a seat.");
                    }                    
                }
            }
            catch { }
        }
    }
}
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.