1

I need to customize ATG promotions applied to "highest priced item" but that it considers when there is a sale price and uses it rather than the default list price.

Based on what I read from atg.ui.commerce.pricing.DescriptionBuilder.java when configuring the "Condition and offer" in BCC to generate the PMDL rule when marking the option:

"Highest priced item first" under "Apply Discount To" it generates a PDML rule with this section:

<up-to-and-including number="1" sort-by="priceInfo.listPrice" sort-order="descending">

But as you can see ATG always uses priceInfo.listPrice hardcoded within the PDML rule.

How could I do so my promotion is intelligent enough to detect when an item has sale price so it uses it rather than the list price?

Juan Pablo
  • 11
  • 2
  • When an item is discounted, isn't the real list price loaded into the discounted price field and the discounted price in the list price field? This way you know when an item is discounted (the field is populated) and your PMDL rule works (discounted value is in the list price field). – radimpe Aug 30 '16 at 04:52
  • thanks for your answer! In my case for every product variant (SKU) we handle two price lists, one which code is “listPrices” and the other is “salePrices” So in this case our “salePrice” hasn’t been discounted by ATG yet; is just another price list we handle for products; that is why I need to find where I can change logic so when PDML rule is evaluated it considers this other “salePrice” price list. – Juan Pablo Sep 01 '16 at 19:58

1 Answers1

0

Sorry for my delay to reply your answer, It took long since I started digging into it and I want to share my findings:

  1. In my company we implemented a sale list price based on ATG suggestion; it means on atg/commerce/pricing/ItemPriceInfo we'll populate listPrice from "List Price" list and salePrice from "Sale Price" list.

  2. Across the site in order to display an item price we have to chose in between both lists by applying next logic to give priority to sale price:

    isOnSale() && getSalePrice() < getListPrice ? getSalePrice() : getListPrice();

  3. The problem comes when creating a new promotion on BCC and picked the option to apply the promotion to highest (or lowest) priced item since BCC by default will add in the PDML rules a XML tag like:

    < up-to-and-including number="1" sort-by="priceInfo.listPrice" sort-order="descending" >

  4. As you may notice, the trick the PDML does is to sort all items based on "priceInfo.listPrice" and then pick the first.

When the PDML is evaluated, ATG maps this XML tag by an instance of atg/commerce/pricing/definition/UpToAndIncludingElem; there the method "evaluate" will call the method "resolveCollectionList" living in atg/commerce/pricing.definition.CompoundPricingModelExpression which at the end ends up calling the method "sortList" of the same class.

  1. This is a hacky approach worked for me but I already dropped:

5.a I decompiled UpToAndIncludingElem.class and added its own version of the method sortList, since this method receives a parameter "sortBy" I added a condition so if its value is "priceInfo.listPrice" I changed it to acustom new attribute "priceInfo.finalPrice"

5.b Since we had already extended atg/commerce/pricing/ItemPriceInfo class I added a new attribute called "finalPrice" with its setter and a custom getter which evaluates if there is a sale price to use as I explained in step #2

Now every time a promotion with that XML tag within the PDML rules to apply the promotion to highest (or lowest) priced item, my custom UpToAndIncludingElem's sortList method will replace the sortBy parameter to use "priceInfo.finalPrice" which getter method will consider sale price.

Why am I dropping this approach?

  1. Because the way I overrode the class relies on order classes are added to the project within the class path and feels risky to me
  2. I used a decompiling tool which I can't guarantee is the optimal JAVA code
  3. If later with another ATG version this flow changes I may run into trouble

What am I going to do?

I'll keep the definition of "priceInfo.finalPrice" I added on our custom class from ItemPriceInfo class

I'll look how I can change the promotion template so hardcodes my custom attribute "priceInfo.finalPrice" rather than "priceInfo.listPrice"

Thanks to people who has taken the time to read and reply my question and I hope my discovery and approach could work to you.

Of course feel confident to ask or suggest things.

Juan Pablo
  • 11
  • 2