7 Replies Latest reply: Oct 31, 2012 9:18 AM by RMishra RSS

    Changing line item price before add it to the shopping cart

    971091
      Hi all,

      I have a scenario, that I need to change de line item price without a specific pattern. Customer can change the price what he/she is going to pay before add the item in the basket, decreasing or increasing listPrice. If it is not possible before add the item inside the basket, an alternative can be change inside de shopping cart.

      But I don't know exactly how can I archive that (before or after add the line item). Any help will be great.

      Regards,
        • 1. Re: Changing line item price before add it to the shopping cart
          Nooruddin Shaik
          Create a property customerPrice in commerceItem to store the price user entered.
          Create a new itemprice pre calculator to override the amount after listprice calculator with the new customer price property.

          Peace
          Shaik
          • 2. Re: Changing line item price before add it to the shopping cart
            971091
            Hello Shaik,

            I really appreciate your answer, but I am new in Oracle ATG Commerce. Could you please be a little more specific in what I should do?


            Thanks.

            Edited by: agvedotti on Oct 30, 2012 5:14 PM

            Edited by: agvedotti on Oct 30, 2012 5:18 PM
            • 3. Re: Changing line item price before add it to the shopping cart
              RMishra
              override /atg/commerce/order/OrderRepository.xml:
              <gsa-template xml-combine="append">
              <item-descriptor name="commerceitem">
                        <table name="dcspp_item" type="primary" id-column-name="commerce_item_id">
                             <property name="customerPrice" column-name="customerPrice" data-type="double"/>                    
                        </table>
                   </item-descriptor>     
              </gsa-template>

              override class atg.commerce.order.CommerceItemImpl and create getter/setter for customerPrice property, like:

              in same package atg.commerce.order
              public class CommerceItemImpl extends atg.commerce.order.CommerceItemImpl implements CommerceItem, ChangedProperties{
              private double customerPrice;
              //.............setter/getter

              }

              CommerceItem is a abstract class whose implementation is in CommerceItemImpl, so you can create directly setter/getter in CommerceItemImpl.

              -RMishra
              • 4. Re: Changing line item price before add it to the shopping cart
                Praveer.Rai
                Hi ,

                Below are steps in brief : ( @Shaik : Please correct me if wrong anywhere )

                1- You have to extend orderrepository.xml and add a new property , say customerPrice in commerceItem itemdescriptor , eg :

                <item-descriptor name="commerceItem" item-cache-size="10000">
                          <table shared-table-sequence="1" name="dcspp_item" type="primary"
                               id-column-name="commerce_item_id">
                               <property name="customerPrice" data-type="double" column-name="customer_price " required="false" readable="true"
                                    writable="true" queryable="true" hidden="false" expert="false"
                                    cache-mode="inherit">
                               </property>
                          </table>
                </item-descriptor>

                create a customer_price column in dcspp_item table.

                2- create customCommerceItem.java extending commerceItem and provide getter setters for this property , in OrderTools.properties give defaultCommerceItemType=customCommerceItem

                3- Extend the CartModifierFormHandler method that you are using to add item to order ,capture the customer entered price from JSP in some variable of CartModifierFormHandler , and set it the new property of customCommerceItem.

                4- Create CustomerPriceCalculator extending ItemListPriceCalculator

                http://docs.oracle.com/cd/E24152_01/Platform.10-1/ATGCommProgGuide/html/s1004addinganewpricingcalculator01.html

                in CustomerPriceCalculator implement priceItem method and set the price as the one entered by customer.

                in ItemPricingEngine.properties add it in precalcualtors after listPriceCalcualtor , or i think you can also write it in post calculator.

                eg :

                preCalculators=calculators/ItemListPriceCalculator,\
                                    calculators/CustomerPriceCalculator


                ~ Praveer
                • 5. Re: Changing line item price before add it to the shopping cart
                  971091
                  Many thanks for RMishra & Praveer,

                  I am doing some tests right now! :)

                  Mates, do you know if I should manipulate the lineItem price before add it in the shopping cart ou latter, when it is already in?


                  Thanks again,
                  • 7. Re: Changing line item price before add it to the shopping cart
                    RMishra
                    To add point,
                    Manipulating it before adding item to cart will be costly as we know it will call whole process to change price of all line items by calling PricingEngine component, each time, we call product page. So as Praveer already mentioned, is right way.
                    -RMishra