How to get product related retail promotions/discounts

static void testGetAvailableDiscountsByItem2(Args _args)
{
    ItemId                                  itemId          = '0006';
    InventTable                             inventTable     = InventTable::find(itemId);
    RetailPricingDataManager                retailPricingDataManager = RetailPricingDataManager::construct(5637145360);
    Container                               promotions,
                                            priceGroups;

    MCRChannelUser                          channelUser = MCRChannelUser::find();
    RetailChannelPriceGroup                 retailChannelPriceGroup;

    while select RecId, PriceGroup from retailChannelPriceGroup
        where retailChannelPriceGroup.RetailChannel == channelUser.Channel
    {
        priceGroups += retailChannelPriceGroup.PriceGroup;
    }
    

    promotions = retailPricingDataManager.getPeriodicDiscounts(
            inventTable.Product,
            0,
            priceGroups,
            'USD',
            DateTimeUtil::getSystemDateTime()
        );
}

static void testGetAvailableDiscountsByItem(Args _args)
{
    ItemId                                  itemId = '0006';
    InventTable                             inventTable     = InventTable::find(itemId);
    RetailAllProductCategories              retailAllProductCategories;
    RetailGroupMemberLine                   retailGroupMemberLine;
    RetailPeriodicDiscountLine              retailPeriodicDiscountLine;
    RetailPeriodicDiscount                  retailPeriodicDiscount;

    // Discounts assigned to product directly
    while select retailGroupMemberLine
        where retailGroupMemberLine.Product == inventTable.Product
        join retailPeriodicDiscountLine
            where retailPeriodicDiscountLine.RetailGroupMemberLine == retailGroupMemberLine.RecId
        join retailPeriodicDiscount
            where retailPeriodicDiscount.OfferId == retailPeriodicDiscountLine.OfferId
    {
        abs(1);
    }

    // Discounts assigned to category
    while select retailGroupMemberLine
        where retailGroupMemberLine.Product == 0
        join retailAllProductCategories
            where retailAllProductCategories.Category   == retailGroupMemberLine.Category
                &&retailAllProductCategories.Product    == inventTable.Product
        join retailPeriodicDiscountLine
            where retailPeriodicDiscountLine.RetailGroupMemberLine == retailGroupMemberLine.RecId
        join retailPeriodicDiscount
            where retailPeriodicDiscount.OfferId == retailPeriodicDiscountLine.OfferId
    {
        abs(1);
    }

}
But method \Classes\RetailPricingDataManager\getPeriodicDiscounts should be slightly changed.
We need to change
    while select
            OfferId, ValidFrom, ValidTo, ConcurrencyMode, DateValidationType, ValidationPeriodId, PriceDiscGroup, Name, PeriodicDiscountType, IsDiscountCodeRequired, DiscountPercentValue
To:
    while select
            OfferId, ValidFrom, ValidTo, ConcurrencyMode, DateValidationType, ValidationPeriodId, PriceDiscGroup, Name, PeriodicDiscountType, IsDiscountCodeRequired, DiscountPercentValue, CurrencyCode
In other words just add CurrencyCode to selected fields. Otherwise it will fail in method \Classes\RetailPricingDataManager\buildRetailDiscountContainer as CurrencyCode has never been selected.

Support The Author

 If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.

Buy Me a Coffee

Post a Comment


All Comments


No comments. Be the first one to comment on this post.

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics 365 FO.

Authors are allowed to set their own "buy me a coffee" link.
Join us.

Blog Tags