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.

 

Search

About

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

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags