Hide a specific checkout attribute in case of a particular vendor's product in cart

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
I want to Hide a specific checkout attribute in case of a particular vendor's  product in cart during the checkout.
Please help where I need to change for this functionality.
7 years ago
The easiest (but not the best) way is to do something like:

@if (Model.IsEditable)
    {
       var dataChackoutAttributes = new ViewDataDictionary();
       var productService = EngineContext.Current.Resolve<IProductService>();
       if (Model.Items.Select(item => productService.GetProductById(item.ProductId)).Any(product => product.VendorId == 1))
           {
             dataChackoutAttributes.Add("hideMyAttrbute", true);
           }

           @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, dataChackoutAttributes)
     }


in the OrderSummary view. Where 1 is the id of your vendor.

And then ckeck in the _CheckoutAttributes:

if (attribute.Name.Equals("MyAttrbute") && (ViewData.ContainsKey("hideMyAttrbute") && Convert.ToBoolean(ViewData["hideMyAttrbute"])))
    {
         continue;
    }

Where MyAttrbute is the name of your attribute.

Note: not tested completely.

The best way is to add a new field to the Checkout attribute edit/create page where an admin could choose vendors. How to add a new field: Updating an existing entity. How to add a new property.
7 years ago
Thanks Mariann its working
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.