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
This is catastrophic for my customers actually. Does the changes 3 posts above work still?
9 years ago
lintho wrote:
This is catastrophic for my customers actually. Does the changes 3 posts above work still?

Also very interested in this change.
How to do this in 3.5? I have no experience yet with customizing nopCommerce, but that should not become a problem.

Right now I'm deleting the product attribute combinations when stock is zero. Would like to automate that.
9 years ago
You can automate it without touching the nopcommerce code with Microsoft SQL Server Management Studio and using SQL script
8 years ago
I think he would like to do that wthout running SQL queries directly on DB.

I'm new to development but I will give it a go with newest source - If I success I will post my findings here
8 years ago
If anyone has this modification for v3.5 I would really like to see it. As it is we can't use nopCommerce for our products without having each variation manually put in as a separate product.

J
8 years ago
vics wrote:
Hi everyone,

After two years using Nop, Im finally able to give something back to the community. This should definitely be on the next version. Also, I would like to point that I was able to this in the previous 2.5 version, but back then, I had no experience with MVC Razor or the application itself. I ended up making it work but I changed a TON of files and it was going to be a pain in the ass for others trying to implement it. Also, I could't upgrade because It will break my current customizations, so I finally decided to give it another try with 3.2 version. Well, this time, now with more experience I was able to do it with minor changes, only 4 files and much less code, and I accomplished the same result in a more elegant way. Without further a due, lets begin.

THE PROBLEM

Well, we all love the Attribute Values/Combinations in the system to keep track of Stock for each Product Variant Combination. This works great but the problem is that when the customer selects an item from the dropdown list that is out of stock, he gets the "out of stock" message after clicking on BUY NOW button. Not very elegant right? Imagine having 20 combinations and you only have 5 combinations in stock. The customer could get pissed off and think that you have NOTHING in your store at all.

Let's take the classic T-Shirt example for instance. We have in stock as follows (Color : Size : StockQuantity)
Black : S : 10
Black : M : 0
Black : L  : 15
White : S : 3
White : M : 10
White : L : 12

In the product page, we are going to see TWO dropdownlist's. One for Color and other for Size. Correct?
Wouldn't be nice that if the current selection is 'Black', on the Size dropdown, the options will be as follows:

S
M (out of stock)  <--- This option gets DISABLED
L

Then, if the customer selects 'White', the size dropdown will auto-populate with:

S (only 3 left)   <--- Amazon style
M
L

Well, this is exactly what I did. Wanna know how? Don't worry, it's easy. Let me show you how.

STEP 1. Database changes

We have to Add a boolean column to ProductVariantAttributeValue table. Execute this code:

ALTER TABLE ProductVariantAttributeValue
ADD IsMasterAttribute bit
GO

UPDATE ProductVariantAttributeValue --Set all records to 0
SET IsMasterAttribute=0
GO


This is the flag to tell us that the current Attribute is a Master (I couldn't think of a better name, sorry).
In our example, T-Shirt COLOR will be our master attributes. So, you will have to manually set as 1 the values Attributes of Black and White like this:

UPDATE ProductVariantAttributeValue
SET IsMasterAttribute=1
where id in (829,835)
GO



Ok great, this is all thats needed for db changes.



STEP 2.
Add

public bool IsMasterAttribute { get; set; } //VAS

to ProductVariantAttributevalue.cs in Core\Domain\Catalog

STEP 3.
Modify Nop.Web\Models\Catalog\ProductDetailsModel.cs and add this to the ProductVariantAttributeValueModel class
            public bool IsMasterAttribute { get; set; } //VAS
            public string AffectsObjectId { get; set; } //VAS
            public string CurrentObjectId { get; set; } //VAS
            public List<RenderCombinationModel> RenderCombinations { get; set; } //VAS
            public int GetStockQuantityById(int CombinationValue, List<RenderCombinationModel> Combinations)//VAS
            {
                foreach (RenderCombinationModel combination in Combinations)
                    if (combination.Value == CombinationValue)
                        return combination.Quantity;
                return 0; //this will happen when the are no combinations added to the variant
            }


Also, add a new class below to the same file.

        public partial class RenderCombinationModel : BaseNopEntityModel //VAS
        {
            public string Name { get; set; }
            public int Value { get; set; }
            public int Quantity { get; set; }
            public RenderCombinationModel(string Name, int Value, int Quantity)
            {
                this.Name = Name;
                this.Value = Value;
                this.Quantity = Quantity;
            }
        }




STEP 4.
Modify Nop.Web\Controllers\CatalogController.cs
In the PrepareProductDetailsPageModel method, add this code: (Line 871)

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,
                            IsMasterAttribute = pvaValue.IsMasterAttribute
                        };
                        if (pvaValueModel.IsMasterAttribute)
                        {
                            pvaValueModel.RenderCombinations = new List<ProductDetailsModel.RenderCombinationModel>();
                            IList<ProductVariantAttributeCombination> combinations = _productAttributeService.GetAllProductVariantAttributeCombinations(pvaModel.ProductId);
                            foreach(ProductVariantAttributeCombination comb in combinations)
                            {
                                IList<ProductVariantAttributeValue> values = _productAttributeParser.ParseProductVariantAttributeValues(comb.AttributesXml);
                                    if (values[0].Id == pvaValueModel.Id)
                                    {
                                        pvaValueModel.RenderCombinations.Add(new ProductDetailsModel.RenderCombinationModel(values[1].Name, values[1].Id, comb.StockQuantity));
                                        if(pvaValueModel.AffectsObjectId == null)
                                        {
                                            pvaValueModel.CurrentObjectId = "product_attribute_" + pvaModel.ProductId.ToString() + "_" +
                                                                            values[0].ProductVariantAttribute.ProductAttributeId.ToString() + "_" +
                                                                            values[0].ProductVariantAttributeId.ToString();
                                            pvaValueModel.AffectsObjectId = "product_attribute_" + pvaModel.ProductId.ToString() + "_" +
                                                                            values[1].ProductVariantAttribute.ProductAttributeId.ToString() +  "_" +
                                                                            values[1].ProductVariantAttributeId.ToString();
                                        }
                                    }
                            }
                            
                        }

                        pvaModel.Values.Add(pvaValueModel);



STEP 5.
Update your View. in Nop.Web\Views\Catalog.

Well, i didn't include the code here because it has several modifications along the file, and Its better to just replace with my updated file. Please download all files from here:

https://www.mediafire.com/folder/36lk4dz9fcufm/PVAChanges


All comments are in english. There are only two hardcoded words in spanish:  'Agotado' which means Out of Stock and 'Queda n piezas' means n items in stock left.

I've done basic testing and it works great. I haven't tested with multiple variants, but it should work.
Let me know if it works for you. I'll be check this post for questions.

Regards

Victor


[[[UPDATE 1.0]]]
I added a couple of validations in two files. For non-mastered items.
Also, In the shared webfolder, you will find ADMIN folder, which contains all the files necessary to set the Master Flag to true from the admin UI. I'm extending this, so I will keep posting stuff.



hi,


I'm using nopcommerce 2.6 version. I just wonder does it even show the out of stock message on attribute combination,when we have manage inventory method as track inventory on product attributes?

What i have experienced is it doesnt show the message at all, Correct me Please if i'm doing something wrong

Thanks in advance.
8 years ago
This really needs to be worked out! Could anyone be of assistance?

// Johan -Sweden
8 years ago
Hi,

according to the description in the "Add an option to display only attribute combinations that exist and have stock greater than zero" codeplex issue:

"please note that we already support display of stock levels for attribute combinations (dynamic)"
https://nopcommerce.codeplex.com/workitem/11907

I should be able to display the stock level for attribute combinations? How should I do this in nop v3.60?

tx
8 years ago
rudgr wrote:


"please note that we already support display of stock levels for attribute combinations (dynamic)"
https://nopcommerce.codeplex.com/workitem/11907


I should be able to display the stock level for attribute combinations? How should I do this in nop v3.60?



Sorry for the obvious question... but yeah - how?  I see the 'Out of stock' red flash at the bottom of the screen if you select an item with no inventory, but is that it?

I'm shooting for this sort-of look.....

Small [+13.00] [0 avail]
Medium [+13.00] [14 avail]
Large [+13.00] [8 avail]
X-Large [+15.00] [21 avail]
XX-Large [+17.00] [4 avail]

Is this available with some series of switches that I just can't find...?  (running version 3.60)

I set a 'Simple' product with "Track Qty by Attribute" set and the above attributes, connected to specific products; still doesn't show like this. Am I missing something?
7 years ago
Can anyone tell me if this works with 3.8?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.