Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

StoreHelper.GetDiscountPrice on Product and Category relations

Vote:
 

We are using the promotion function in Commerce but i'm struggling to get my discount price right.

I keep getting the default price if i set a promotion on a specific product (NOT a variant of a product) or if i set a promotion on a catalog name and add that catalog as a relation catalog to my product.

I do suspect it's a bug in Commerce. Anyone got this to work?

If you look at how StoreHelper implements GetDisountPrice it looks like this:

public Price GetDiscountPrice(Entry entry, string catalogName, string catalogNodeCode, IMarket market, Currency currency)
        {
            if (entry == null)
                throw new NullReferenceException("entry can't be null");

            decimal minQuantity = 1;

            // get min quantity attribute
            if (entry.ItemAttributes != null)
                minQuantity = entry.ItemAttributes.MinQuantity;


            // Get sale price for the current user
            Price price = GetSalePrice(entry, minQuantity, market, currency);
            if (price == null)
            {
                return null;
            }

            string catalogNodes = String.Empty;
            string catalogs = String.Empty;
            // Now cycle through all the catalog nodes where this entry is present filtering by specified catalog and node code
            // The nodes are only populated when Full or Nodes response group is specified.
            if (entry.Nodes != null && entry.Nodes.CatalogNode != null && entry.Nodes.CatalogNode.Length > 0)
            {
                foreach (CatalogNode node in entry.Nodes.CatalogNode)
                {
                    string entryCatalogName = CatalogContext.Current.GetCatalogDto(node.CatalogId).Catalog[0].Name;

                    // Skip filtered catalogs
                    if (!String.IsNullOrEmpty(catalogName) && !entryCatalogName.Equals(catalogName))
                        continue;

                    // Skip filtered catalogs nodes
                    if (!String.IsNullOrEmpty(catalogNodeCode) && !node.ID.Equals(catalogNodeCode, StringComparison.OrdinalIgnoreCase))
                        continue;

                    if (String.IsNullOrEmpty(catalogs))
                        catalogs = entryCatalogName;
                    else
                        catalogs += ";" + entryCatalogName;

                    if (String.IsNullOrEmpty(catalogNodes))
                        catalogNodes = node.ID;
                    else
                        catalogNodes += ";" + node.ID;
                }
            }

            if (String.IsNullOrEmpty(catalogs))
                catalogs = catalogName;

            if (String.IsNullOrEmpty(catalogNodes))
                catalogNodes = catalogNodeCode;
            
            // Create filter
            PromotionFilter filter = new PromotionFilter();
            filter.IgnoreConditions = false;
            filter.IgnorePolicy = false;
            filter.IgnoreSegments = false;
            filter.IncludeCoupons = false;

            // Create new entry
            // TPB: catalogNodes is determined by the front end. GetParentNodes(entry)
            PromotionEntry result = new PromotionEntry(catalogs, catalogNodes, entry.ID, price.Money.Amount);
            var promotionEntryPopulateService = (IPromotionEntryPopulate)MarketingContext.Current.PromotionEntryPopulateFunctionClassInfo.CreateInstance();
            promotionEntryPopulateService.Populate(result, entry, market.MarketId, currency);

            PromotionEntriesSet sourceSet = new PromotionEntriesSet();
            sourceSet.Entries.Add(result);

            Price discountPrice = GetDiscountPrice(filter, price, sourceSet, sourceSet);
            return AddTax(discountPrice.Money, entry, market);
        }

As you can see the code determinates if the price is null. That means you can only check for discount for a variant and not the product it self. 

ALSO note that the catalogsnodes are just the products parent nodes and does NOT include the related catalogs! Also the code is combining the catalognode names with a ";" but in the MarketingContext's EvaluatePromotions there is no split on ";"! So basically if you send in more that one catalognode you get no hits as a result.

Am i missing something here?

#112160
Oct 23, 2014 14:25
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.