2 Replies Latest reply: Nov 7, 2012 12:47 PM by karthik chopperla RSS

    Which method should be used to update Cart..?

    Vishnu Bovilla
      Which method should be used to update Cart among handleSetOrderByCommerceId() and handleSetOrderByRelationShipId()..? And When to use which one..?

      Thanks in Advance:-)
        • 1. Re: Which method should be used to update Cart..?
          Nitin Khare
          While both of these methods can be used to modify the cart but usually you can use handleSetOrderByCommerceId() when you have a simple cart page without any complexity. You would need to use handleSetOrderByRelationShipId() if there is some complexity involved. Now by complexity I mean to refer the complexity in the product-SKU relationships such as multiple CommerceItems with the same catalogRefId (SKU ID) or multiple shipping groups and you want very fine control on the relationship while updating it.

          E.g. if a customer order 6 quantity of an item and choose to ship 3 quantity of it each to home and work address. Now later customer decides to remove or update the items being shipped to the work address. So in this case you would have to modify the involved ShippingGroupCommerceItemRelationship instead of modifying the CommerceItem. So here you would modify an Order by ShippingGroupCommerceItemRelationship ID i.e. through handleSetOrderByRelationShipId().
          • 2. Re: Which method should be used to update Cart..?
            karthik chopperla
            You have to remember that both will modify the order based on the changed quantity. To execute any of these methods, you need to pass this parameter CartModifierFormHandler.isCheckForChangedQuantity as true in form.

            handleSetOrderByCommerceId() will only check if the quantity of items changed or not and modifies the order by calling repricing.It would not change any underlying relationships.

            handleSetOrderByRelationshipId() will check if the quantity in commerceitem-shipping group relationship changed or not and reprices and modifies underlying relationships.

            handleSetOrderByCommerceId() in cart pages would suffice because when you change quantity it reprices order and then when you checkout, handleMoveToPurchaseInfo is called, which actually checks if the quantities in relationship have changed or not ( this is similar to handleSetOrderByRelationshipId()) and updates accordingly. Make sure isCheckForChangedQuantity flag is passed in the formhandler as hidden when you checkout.