Showing posts with label ATG Commerce. Show all posts
Showing posts with label ATG Commerce. Show all posts

ATG Shipping Groups, methods and calculators

Adding shipping information to shopping carts involves the following sub-processes:
1) Creating a list of shipping groups for potential use in the current order
2) Specifying the shipping groups to use with the current order
3) Selecting the shipping methods, such as Ground or Next Day, for the order’s shipping groups 


What is Shipping Group?
A ShippingGroup contains information on the shipping address and delivery method for a group of commerce items. 

By default, a new Order has one defaultShippingGroup. As items are added to the Order, these items automatically become part of the default ShippingGroup. Once a second ShippingGroup is added to theOrder, all the items in the Order are removed from the default ShippingGroup and must be explicitly added to one of two shipping groups. 
 
How to create new Shipping Groups?
You can create a list of shipping groups for potential use in an Order in one of two ways:
  • from information gathered from the user via forms

  • from information stored in the user’s profile
 Below two form handlers allow user to add new shipping groups  
  • /atg/commerce/order/purchase/CreateHardgoodShippingGroupFormHandler
  • /atg/commerce/order/purchase/CreateElectronicShippingGroupFormHandler
 Both extends PurchaseProcessFormHandler 

How to add Shipping Group to an Order?
Steps:
1) Create Shipping Group
2) Make any changes to the Shipping Group, such as setting the address
3) Add the Shipping Group to the Order


 Here is the code snippet:
// Get a reference to the OrderManager 
OrderManager orderManager = (OrderManager)   request.resolveName("/atg/commerce/order/OrderManager");  
// Create the ShippingGroup 
ShippingGroup shippingGroup shippingGroupManager.createShippingGroup(); 
// Add the ShippingGroup to the Order shippingGroup.addShippingGroupToOrder(pOrder, shippingGroup);

How to find available Shipping methods for a particular Shipping Group?
Use droplet  /atg/commerce/pricing/AvailableShippingMethods


How to initiate Shipping group from Profile?
Use droplet /atg/commerce/order/purchase/ShippingGroupDroplet
 
What is Shipping method? 
Each Shipping method is represented by ShippingCalculator component class.

Shipping methods examples are:
  • Ground
  • 2 day delivery
  • Overnight
  • Calculate Shipping price based on couriers web service
  • etc...
Different types of Shipping calculators are:
  • FixedPriceShippingCalculator - Flat rate for shipping
            Ex: Ground shipping is always $15
  • PriceRangeShippingCalculator - Define shipping price based price range
             Ex: $0 - $50  ($5)
                   $51 - $100  ($10)
                   $101 - $1000  (FREE)
  • WeightRangeShippingCalculator - Weight Property added at SKU level and price set based on weight
  • PropertyRangeShippingCalculator - Shipping price decided Based on SKU property
          Ex: Volume
    How to Filter Shipping methods?
    In few scenarios, All shipping methods should not be available. To limit shipping methods developer can sub-class Shipping calculator and override the getAvailableMethods().

    Ex: Courier shipping not allowed for PO boxes

    How to write custom shipping calculator?
    Here are the steps:
    1. Create a new custom calculator component 
    /com/commerce/shipping/FixedPriceServiceCaclulator.properties 
    $class=com.xxx.commerce.pricing.calculators.FixedPriceShippingCalculator
    # name of shipping method
    shippingMethod=DEMO
    # costs 
    amount=10.0

    2. Create a custom Java class and this should extends the shippingCalculatorImpl class
    ShippingCalculatorImpl class have two method for override.
    1.getAmount()  - calculate the shipping price

    2.getAvailableMethods()  - Used to restrict your custom shipping method

    public class FixedPriceShippingCalculator extends ShippingCalculatorImpl { 

    protected double getAmount(Order order, ShippingPriceInfo priceQuote, ShippingGroup shippingGroup, RepositoryItem pricingModel, Locale locale, RepositoryItem profile, Map extraParameters) throws PricingException { }

    public void getAvailableMethods(List pMethods, ShippingGroup pShippingGroup, RepositoryItem pPricingModel, Locale pLocale, RepositoryItem pProfile, Map pExtraParameters) throws PricingException {
    }
    }
    3. Add the shipping calculator to Shipping Engine
    /atg/commerce/pricing/ShippingPricingEngine.properties 
    preCalculators+=/com/commerce/shipping/FixedPriceServiceCaclulator

    ATG - How to enable priceLists to store prices?

    Oracle Commerce users do not have a price list functionality available by default. By default prices are stored directly in the product catalog and OOTB configured using below component.

    Component Path: /atg/commerce/pricing/ItemPricingEngine
    Configuration:   /atg/commerce/pricing/ItemPricingEngine/?propertyName=serviceConfiguration

    preCalculators=\
            calculators/ItemListPriceCalculator,\
            calculators/ItemSalePriceCalculator,\
            calculators/ConfigurableItemPriceCalculator



    How to enable priceLists? 
    To add price list functionality, configure the ItemPricingEngine to use the appropriate precalculator. 
    Here is how you can override ItemPricingEngine component:
    Component Path: /atg/commerce/pricing/ItemPricingEngine

    preCalculators=\
        calculators/ItemPriceListCalculator,\
        calculators/ItemPriceListSaleCalculator,\
        calculators/ConfigurableItemPriceListCalculator,\
        calculators/ConfigurableItemPriceListSaleCalculator


    This means the prices are retrieved from the PriceLists repository 
    Price Lists created through BCC 
    Price can be defined at Product, SKU or Product/SKU pairing

    ATG Shopping Cart Basics

    User can use Product Page or Cart page to perform below actions:
    1. Add Item(s) to the cart
    2. Remove Item from the cart
    3. Change quantity of item(s)
    4. Delete item(s) from the cart
    How to add item(s) to the cart?
    • OOTB ATG provides request scope CartModifierFormHandler component with pre-build methods for add, update, delete etc..
    • Component path : /atg/commerce/order/purchase/CartModifierFormHandler


    What happens when user adds item(s) to the cart?
    • When SKUs are added to the order, they become CommerceItem objects
    • CommerceItem Object represent each line item in the order
    • Order may contain many commerce items object
    How to check the order object and commerce Items?
    •    ShoppingCart is session scoped component  (/atg/commerce/ShoppingCart)
    •    ShoppingCart uses OrderHolder Class to hold multiple orders
    •    At any given point only one Order will be active
    •    ShoppingCart holds current, saved and last orders
    •    Current Order object can be accessed by using either ShoppingCart.current or CartModifierFormHandler.order

    ATG Order Reprice and How it works?

    When Order reprice is typically called?
    The Order is typically repriced after the following actions: 
    • Item is added to the cart 
    • Item is removed from the cart 
    • Quantity is changed on items in the cart 
    • User specifies a shipping address or shipping method and pushes "Checkout" button
    How to do repricing on Order?
    Use /atg/commerce/order/purchase/RepriceOrderDroplet to invoke repricing on order:



    How it works behind the scenes?
    Each time the code reprices the order, the ATG Promotions associated with the user's Profile are considered.
    • Fetch all of the Promotions/Discounts that the user is eligible for:
      • (Global + Individual Promotions) minus Promotions they don't qualify for
    • Calculate the price of each individual item on the order
      • Apply Item Level Discounts
    • Calculate the order total price(discounted item prices + shipping price)
      • Apply Order Level discounts
    • Calculate the shipping price
      • Apply Shipping Discounts
    • Generate a total price
    Few scenarios when Order reprice is not working:
    If you don't see your order getting repriced as you expected (the discount isn't being related), these are some things to check on:
    • Was the repricing code called yet?
    • Was the Promotion successfully added to the Profile?
    • Was the Promotion represented correctly in the repository?