How to show OUT OF STOCK in dropdown (Product Attribute Value Combinations) 3.2

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hello Victor,
Do you have a version that works with 3.4?
9 years ago
Hi Victor,

I am also interested in a version of this for V3.40.

Regards,

David.
9 years ago
Would love this for latest version I'm about to download too please! :)
9 years ago
I'm also very interested in a 3.4 compliant version!
9 years ago
Hey
I have a working code for this in 3.4. But i only tested it if you have one Attribute on a Product (in my case color).
I know its not the best way to do it but it works for me.

you need to change 3 Files in NopCommerce Source:

First File is  Nop.Web/Models/Catalog/ProductDetailsModel.cs on Line 264 add:
public bool isAvailable { get; set; }


Second File is Nop.Web/Controllers/ProductController.cs from Line 608 do these changes:

foreach (var pvaValue in pvaValues)
                    {
                        //values
                  
                        /*Dont show when out of stock*/
                        bool isAvailable = true;
                        bool foundCombination = false;
                        var allCombinations = _productAttributeService.GetAllProductVariantAttributeCombinations(product.Id);
                        foreach (var combination in allCombinations)
                        {
                            var attributeValues = _productAttributeParser.ParseProductVariantAttributeValues(combination.AttributesXml);
                            foreach (var value in attributeValues)
                            {
                                if (value.Id == pvaValue.Id)
                                {
                                    if (combination.AllowOutOfStockOrders == false && combination.StockQuantity == 0)
                                    {
                                        isAvailable = false;
                                    }
                                    else
                                    {
                                        isAvailable = true;
                                    }
                                    foundCombination = true;
                                    break;
                                }

                            }
                            if (foundCombination == true)
                            {
                                break;
                            }
                        }

                        var pvaValueModel = new ProductDetailsModel.ProductVariantAttributeValueModel()
                        {
                            Id = pvaValue.Id,
                            Name = pvaValue.GetLocalized(x => x.Name),
                            ColorSquaresRgb = pvaValue.ColorSquaresRgb, //used with "Color squares" attribute type
                            IsPreSelected = pvaValue.IsPreSelected,
                            isAvailable = isAvailable,
                        };


Third File ist Nop.Web/Views/Product/_ProductAttributes.cshtml on line from line 45 on do these changes:

@foreach (var pvaValue in attribute.Values)
                            {
                                if (pvaValue.isAvailable == true) {
                                    <option selected="@pvaValue.IsPreSelected" value="@pvaValue.Id">@pvaValue.Name
                                        @(!String.IsNullOrEmpty(pvaValue.PriceAdjustment) ? " [" + pvaValue.PriceAdjustment + "]" : null)
                                    </option>
                                }
                                else
                                {
                                    <option selected="@pvaValue.IsPreSelected" value="@pvaValue.Id" style="color: #999999">@pvaValue.Name
                                        [@T("Attribute.Value.SoldOut")]
                                        @(!String.IsNullOrEmpty(pvaValue.PriceAdjustment) ? " [" + pvaValue.PriceAdjustment + "]" : null)
                                    </option>
                                }
                            }


Last thing to do is to add a language resource for "Attribute.Value.SoldOut".

Hope you enjoy it.

Kind Regards
9 years ago
Hello

It seems that a change in the first value (color) does not affect the 'sold out' of the second value (size) after the initial setup of the form.

Additionally if the first selection of (color) and (size) combination that  it brought back from the select of combinations  has a stock quantity of zero, then the color value shows a 'out of stock'  flag , regardless if other sizes of the same color are in stock.

it seems like some Javascript would be needed to handle the switching of combinations without having to reload the selections from the server.  But , i'm probably  missing something.

Robin
9 years ago
Hi.

This code doesn't seem to apply to Version 3.4 - Do you know how these changes can be made with this version?


Thanks
9 years ago
I've downloaded the latest nopCommerce (3.4) and I don't seem to be able to implement the changes above? I don't seem to have those files??
9 years ago
Greeeeeaaaaaat job Vics... this is very important for me, i have a warehouse program syncronized to nopcommerce, and this is a great help for me :)
9 years ago
Any update on this for 3.5?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.