Override Disable add to cart button when impersonating

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Hi, I have several products set to disable add to cart button due to wildly fluctuating stocks. When a customer rings me up and enquires about one of those items, I wish to be able to impersonate that customer and add the item to his cart.
Basically I want to override the 'disable buy button when in impersonating mode.

Can anybody please outline for me what steps are involved to achieve this?

Thanks - Helger
13 years ago
Hello Helger,

here is my Proposal:

In ProductVariantsinGrid.aspx.cs and OneVariant.ascx.cs, change


if (!productVariant.DisableBuyButton)


to


if (!productVariant.DisableBuyButton || NopContext.Current.IsCurrentCustomerImpersonated == true)
13 years ago
Thanks Schmidt20,

I have done the changes and the button now shows up when impersonating. But when I click it, the buying disabled warning message still comes up and the item is not added to the cart.

Cheers - Helger
13 years ago
Hi Helger,

in addition to Post #1 please add to the same files:

if (this.SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
{
    this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
}

change to

if (this.SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes")
    && NopContext.Current.IsCurrentCustomerImpersonated == false)
{
    this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
}

also in ShoppingCartService.cs:

if (productVariant.DisableBuyButton)
{
    warnings.Add("Buying is disabled");
}

change to

if (productVariant.DisableBuyButton  && NopContext.Current.IsCurrentCustomerImpersonated == false)
{
    warnings.Add("Buying is disabled");
}

Let me know if it works.

BR

Schmidt
13 years ago
Thanks a lot - that did the trick. For the benefit of others, I am using v. 1.8 and the file referred to above as ShoppingCartService.cs is in my version called ShoppingCartManager.cs

Cheers - Helger
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.