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.
Hace 9 años
Hello Victor,
Do you have a version that works with 3.4?
Hace 9 años
Hi Victor,

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

Regards,

David.
Hace 9 años
Would love this for latest version I'm about to download too please! :)
Hace 9 años
I'm also very interested in a 3.4 compliant version!
Hace 9 años
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
Hace 9 años
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
Hace 9 años
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
Hace 9 años
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??
Hace 9 años
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 :)
Hace 9 años
Any update on this for 3.5?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.