disable button Bugs

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 years ago
hi,
1)Minimum Stock quantity 'disable buy button' when stock low dosnt seem to work i have tried various combinations of stock but carnt get it to disable 'add to cart' button.
2)and also noticed if disable buy button checkbox is checked this will only disable the buy button when you preview the details of the product so you can still buy it as long as you click the add to cart button under the details button (It will only remove one of the two add to cart buttons not both)
any ideas?. Thanks
15 years ago
Hi Zentreon,

Please see responses below.

1) I presume you are adjusting stock quantities within administration rather than by purchasing products. Currently when an order is successfully placed the stock quantity is adjusted. If you have set a low stock activity has been set (i.e. disable button) and the new stock quantity is less than or equal to the min stock quantity, then the DisableBuyButton is set to true.

If you are modifying the product variant details within administration and explicitly setting a low stock quantity, then you may as well uncheck the Disable Buy Button checkbox or unpublish the product variant manually (since you have to edit the record to change the quantity anyway).

However, if you would like to do this automatically (depending on your low stock activity selection) you can add the following code to line 210 of administration/ProductVariantDetails.aspx.cs (just below the line "LowStockActivityEnum lowStockActivity = ...."):


                        bool productVariantPublished = cbPublished.Checked;
                        bool productVariantDisableBuyButton = cbDisableBuyButton.Checked;
                        if (txtMinStockQuantity.Value >= txtStockQuantity.Value)
                        {
                            switch (lowStockActivity)
                            {
                                case LowStockActivityEnum.DisableBuyButton:
                                    productVariantDisableBuyButton = true;
                                    break;
                                case LowStockActivityEnum.Unpublish:
                                    productVariantPublished = false;
                                    break;
                                default:
                                    break;
                            }
                        }


You then need to change your ProductManager.UpdateProductVariant method call below to:


                        productVariant = ProductManager.UpdateProductVariant(ProductVariantID, productVariant.ProductID,
                             txtName.Text, txtSKU.Text, txtDescription.Value, txtAdminComment.Text, txtManufacturerPartNumber.Text,
                             cbIsDownload.Checked, productVariantDownloadID, cbIsShipEnabled.Checked, cbIsFreeShipping.Checked,
                             cbIsTaxExempt.Checked,  int.Parse(this.ddlTaxCategory.SelectedItem.Value), txtStockQuantity.Value,
                             txtMinStockQuantity.Value, lowStockActivity,
                             int.Parse(this.ddlWarehouse.SelectedItem.Value), productVariantDisableBuyButton,
                             cbRequiresTextOption.Checked, txtTextOptionPrompt.Text,
                             txtPrice.Value, txtOldPrice.Value, txtWeight.Value, txtLength.Value,
                             txtWidth.Value, txtHeight.Value, productVariantPictureID, productVariantPublished,
                             productVariant.Deleted, txtDisplayOrder.Value, productVariant.CreatedOn, DateTime.Now);


This code just checks the new stock quantity and min stock quantity values and if you have set a low stock activity action, makes the necessary changes for you (i.e. disables buy button or unpublished product).

2) This bug is fixed in next release but I will tell you how to change for 1.10. In /modules/ProductBox1.ascx.cs and /modules/ProductBox2.ascx.cs add the following code at line 96:


                    if (btnAddToCart != null)
                    {
                        btnAddToCart.Visible = !productVariant.DisableBuyButton;
                    }


The complete block should look like:


if (productVariantCollection.Count > 0)
                {
                    ProductVariant productVariant = productVariantCollection[0];

                    decimal oldPrice = productVariant.OldPrice;
                    decimal finalPriceWithoutDiscount = productVariant.GetFinalPrice(NopContext.Current.User, false);

                    decimal oldPriceConverted = CurrencyManager.ConvertCurrency(oldPrice, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                    decimal finalPriceWithoutDiscountConverted = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscount, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                    if (finalPriceWithoutDiscountConverted != oldPriceConverted && oldPriceConverted != decimal.Zero)
                    {
                        lblOldPrice.Text = LocalizationManager.GetCurrencyString(oldPriceConverted, true, NopContext.Current.WorkingCurrency);
                        lblPrice.Text = LocalizationManager.GetCurrencyString(finalPriceWithoutDiscountConverted, true, NopContext.Current.WorkingCurrency);
                    }
                    else
                    {
                        lblOldPrice.Visible = false;
                        lblPrice.Text = LocalizationManager.GetCurrencyString(finalPriceWithoutDiscountConverted, true, NopContext.Current.WorkingCurrency);
                    }
                    if (btnAddToCart != null)
                    {
                        btnAddToCart.Visible = !productVariant.DisableBuyButton;
                    }
                }


Please be aware that whilst this fixes one bug, it produces another (I am working on at the moment). If the product has more than one variant, and the first variant in the collection has it's DisableBuyButton property set to True, then the code above will disable the Add to Cart button on the product lists, even though the another variant in the Products ProductVariant collection, is available for purchase.

If you are not using multiple product variants then this will not affect you but I thought I would mention it.

Hope this helps,

Ben
15 years ago
Hi, thankyou for update, tried adding
if (btnAddToCart != null)
                    {
                        btnAddToCart.Visible = !productVariant.DisableBuyButton;
                    }
this dosnt seem to cure the problem, maybe it cures a bug i have not yet seen, but thanks .
If i check 'Disable buy button' checkbox within admin. On the Category page (/Category/24-car.aspx)the add to cart button is still enabled however on the Products page(Products/35-exhaust.aspx) it is disabled.So i can still click the 'add to cart button' from the Category page and proceed to checkout.Hope this is clearer. Thanks again, Mark
15 years ago
Have you applied this to both ProductBox1.ascx.cs and ProductBox2.ascx.cs?

Please confirm the template you are using for your "Car" category. Has your product "Exhaust" got only one variant?

Thanks,
Ben
15 years ago
Hi, sorry i only updated ProductBox1.ascx.cs not both, its working now and yes it has only got only one variant, tried adding more variants to test but i can not because im getting an error (http://forums.nopcommerce.com/forums/default.aspx?g=posts&t=371)you said update to latest version to cure problem, im running version 1.10.
15 years ago
Please post your [dbo].[Nop_ProductVariantInsert] stored procedure on that post.

Thanks,
Ben
15 years ago
sorted, it will be there in a mo
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.