problem on Product Attribute Combinations "always add item to cart" even it's stock 0 ?

Monday, November 25, 2024 8:29:24 PM
  • Posted: Friday, July 26, 2019 12:15 AM
  • 56
Hi

i have try to manage inventory by attribute so i have did:
01. set inventory to be Manage Stock By Attributes.
02. product has 3 Attribute (2 dropdown list, one textbox)  - and i have add Attribute combinations for size attribute only as

Attributes  Stock quantity  Allow out of stock  Sku  
Size: m                     100                                  gghgh        
Size: s                        22                                      rtrt        
Size: l                         0                                    cxxcx

03. now when i try to add item with Size: l  to cart - it accept it - and i dont get out of stock message ?! - i try to debug i see that in this method "GetStandardWarnings" in ShoppingCartService - in this line

var combination = _productAttributeParser.FindProductAttributeCombination(product, attributesXml);


always return null - and i don't know why ?

"ProductAttributeCombinations" : [
        {
            "_id" : "5d3a4457452e35465cee81a1",
            "AttributesXml" : "<Attributes><ProductAttribute ID=\"5d3a3fdda758f453c0e1898d\"><ProductAttributeValue><Value>5d3a4058a758f453c0e19662</Value></ProductAttributeValue></ProductAttribute></Attributes>",
            "StockQuantity" : NumberInt(100),
            "AllowOutOfStockOrders" : false,
            "Text" : null,
            "Sku" : "gghgh",
            "ManufacturerPartNumber" : null,
            "Gtin" : null,
            "OverriddenPrice" : null,
            "NotifyAdminForQuantityBelow" : NumberInt(1),
            "PictureId" : null,
            "WarehouseInventory" : [

            ],
            "TierPrices" : [

            ]
        },
        {
            "_id" : "5d3a4469452e35465cee81fc",
            "AttributesXml" : "<Attributes><ProductAttribute ID=\"5d3a3fdda758f453c0e1898d\"><ProductAttributeValue><Value>5d3a405ea758f453c0e19680</Value></ProductAttributeValue></ProductAttribute></Attributes>",
            "StockQuantity" : NumberInt(22),
            "AllowOutOfStockOrders" : false,
            "Text" : null,
            "Sku" : "rtrt",
            "ManufacturerPartNumber" : null,
            "Gtin" : null,
            "OverriddenPrice" : null,
            "NotifyAdminForQuantityBelow" : NumberInt(1),
            "PictureId" : null,
            "WarehouseInventory" : [

            ],
            "TierPrices" : [

            ]
        },
        {
            "_id" : "5d3a4483452e35465cee825c",
            "AttributesXml" : "<Attributes><ProductAttribute ID=\"5d3a3fdda758f453c0e1898d\"><ProductAttributeValue><Value>5d3a407da758f453c0e1a2fe</Value></ProductAttributeValue></ProductAttribute></Attributes>",
            "StockQuantity" : NumberInt(0),
            "AllowOutOfStockOrders" : false,
            "Text" : null,
            "Sku" : "cxxcx",
            "ManufacturerPartNumber" : null,
            "Gtin" : null,
            "OverriddenPrice" : null,
            "NotifyAdminForQuantityBelow" : NumberInt(1),
            "PictureId" : null,
            "WarehouseInventory" : [

            ],
            "TierPrices" : [

            ]
        }
    ],


hop to get help plz ?
0
  • Posted: Friday, July 26, 2019 10:36 AM
  • 953
It looks like you've modified the source code of GrandNode. I've checked it on our dev environment and everything worked as expected.
Best regards,
Patryk

GrandNode Team
0
  • Posted: Friday, July 26, 2019 12:50 PM
  • 56
i have add new property only to attribute class , i don't change any thing on the method i have talk about ??!!

i have version 4.30 and this is code i have in source code


                    case ManageInventoryMethod.ManageStockByAttributes:
                        {
                            var combination = _productAttributeParser.FindProductAttributeCombination(product, attributesXml);
                            if (combination != null)
                            {
                                //combination exists
                                //let's check stock level
                                var stockquantity = product.GetTotalStockQuantityForCombination(combination, warehouseId: _storeContext.CurrentStore.DefaultWarehouseId);
                                if (!combination.AllowOutOfStockOrders && stockquantity < quantity)
                                {
                                    int maximumQuantityCanBeAdded = stockquantity;
                                    if (maximumQuantityCanBeAdded <= 0)
                                    {
                                        warnings.Add(_localizationService.GetResource("ShoppingCart.OutOfStock"));
                                    }
                                    else
                                    {
                                        warnings.Add(string.Format(_localizationService.GetResource("ShoppingCart.QuantityExceedsStock"), maximumQuantityCanBeAdded));
                                    }
                                }
                            }
                            else
                            {
                                //combination doesn't exist
                                if (product.AllowAddingOnlyExistingAttributeCombinations)
                                {
                                    //maybe, is it better  to display something like "No such product/combination" message?
                                    warnings.Add(_localizationService.GetResource("ShoppingCart.OutOfStock"));
                                }
                            }
                        }
                        break;


        public virtual ProductAttributeCombination FindProductAttributeCombination(Product product,
            string attributesXml, bool ignoreNonCombinableAttributes = true)
        {
            if (product == null)
                throw new ArgumentNullException("product");

            var combinations = product.ProductAttributeCombinations;
            return combinations.FirstOrDefault(x => AreProductAttributesEqual(product, x.AttributesXml, attributesXml, ignoreNonCombinableAttributes));
        }


[code]        public virtual bool AreProductAttributesEqual(Product product, string attributesXml1, string attributesXml2, bool ignoreNonCombinableAttributes)
        {
            var attributes1 = ParseProductAttributeMappings(product, attributesXml1);
            
            if (ignoreNonCombinableAttributes)
            {
                attributes1 = attributes1.Where(x => !x.IsNonCombinable()).ToList();
            }
            var attributes2 = ParseProductAttributeMappings(product, attributesXml2);
            if (ignoreNonCombinableAttributes)
            {
                attributes2 = attributes2.Where(x => !x.IsNonCombinable()).ToList();
            }
            if (attributes1.Count != attributes2.Count)
                return false;

            bool attributesEqual = true;
            foreach (var a1 in attributes1)
            {
                bool hasAttribute = false;
                foreach (var a2 in attributes2)
                {
                    if (a1.Id == a2.Id)
                    {
                        hasAttribute = true;
                        var values1Str = ParseValues(attributesXml1, a1.Id);
                        var value
0
  • Posted: Tuesday, July 30, 2019 9:19 AM
  • 953
Can you simulate it on our demo? As I said, I'm not able to reproduce it, so I'm not able to help you.
Best regards,
Patryk

GrandNode Team
0
back to top
Filters