New Calculator are fit into existing ATG
commerce pricing architecture ,In ATG four
the calculator are present:
1) atg.commerce.pricing.ItemPricingCalculator
2)
atg.commerce.princing.OrderPricingCalculator
3)
atg.commerce.pricing.ShippingPricingCalculator
4)
atg.commerce.pricing.TaxpricingCaliculator.
For Example: if you want to create new item
pricing, implement
ItemPricingCalulcator.
Condition:- assume you have identified a need
for a calculator that sets an item’s price to half its current price plus one
The existing ATG Commerce tools include an ItemDiscountCalculator
that
discounts items. It can give a percent off a price or an amount off, or it can
set an item’s price to a fixed amount. None of these three options, however,
easily gives a “half off plus one” discount. To achieve that result, you would
have to use two different discounts: one to give 50 percent off, and another to
add 1 to that total. A better alternative would be to create a new calculator
that discounts an item’s price to half its current price plus one.
Step 1:-Create a new Component under
atg/commerce/pricing/HalfPlusOneDiscountCalculator
.properies
$class=com.corbus.commerce.pricing.HalfPlusOneDiscountCalculator
Step:
create new class “HalfPlusOneDiscountCalculator.java
” and extends ItemDiscountCalculator
and override findAdjustedPrice() method.
package
com.corbuse.commerce.pricing;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import
atg.commerce.order.Order;
import
atg.commerce.pricing.DetailedItemPriceInfo;
import
atg.commerce.pricing.ItemDiscountCalculator;
import
atg.commerce.pricing.PricingException;
import
atg.repository.RepositoryItem;
public class
HalfPlusOneItemDiscountCalculator extends ItemDiscountCalculator {
/**
* Override the
findAdjustedPrice to allow us to always compute the
* new price of the
input DetailedItemPriceInfo to be half its current
* price plus one.
* @param
pDetailedItemPriceInfo the details on the item being priced
* @param
pPriceQuotes list of itemPriceInfo
* @param pItems
list of commerceItems
* @param
pPricingModel pricing model being used to calculate price
* @param pProfile
users profile, not used here
* @param pLocale
users locale, not used here
* @param pOrder
users order, not used here
* @param
pExtraParameters map of extra params, not used here
* @return a value
of type 'double'
* @exception
PricingException if an error occurs
*/
public double
findAdjustedPrice(DetailedItemPriceInfo pDetailedItemPriceInfo,
List
pPriceQuotes,
List pItems,
RepositoryItem
pPricingModel,
RepositoryItem
pProfile,
Locale pLocale,
Order pOrder,
Map
pExtraParameters) throws PricingException {
// current
price of an item
double
currentAmount = pDetailedItemPriceInfo.getAmount();
return (
currentAmount / 2) + 1;
} // end findAdjustedPrice
}
Step 2:
Update the pricingModels Repository,
Create
a new pricingModel.xml under the atg/commerce/pricing/pricingMpdel.xml
<gsa-template>
<item-descriptor expert="false" sub-type-value="Item Discount - half off plus one"
id-separator=":"
display-name-resource="itemDiscount -
halfoffplusone" writable="true"
version-property="version" super-type="Item
Discount"
cache-mode="simple"
id-space-name="promotion" content="false"
folder="false" default="false"
query-cache-size="1000" hidden="false"
name="Item Discount
- half off plus one" use-id-for-path="false"
item-cache-size="1000">
<attribute name="resourceBundle" value="atg.commerce.PricingModelsTemplateResources"
/>
<table name="dcs_discount_promo"
id-column-name="promotion_id" type="auxiliary" shared-table-sequence="1">
<property expert="false" readable="true"
category-resource="categoryACCOnly" display-name-resource="pricingCalculatorService" writable="true"
cache-mode="inherit"
column-name="calculator" default="/atg/commerce/pricing/calculators/HalfPlusOneItemDiscountCalculator"
data-type="string"
hidden="false" name="pricingCalculatorService"
required="false" queryable="true">
<attribute name="uiwritable" value="false" />
<attribute name="propertySortPriority" value="100" />
</property>
<property expert="false" readable="true"
category-resource="categoryACCOnly"
column-name="adjuster"
display-name-resource="adjusterPercent"
data-type="double" hidden="false"
writable="true" name="adjuster"
required="false"
cache-mode="inherit" queryable="true">
<attribute name="propertySortPriority" value="60" />
</property>
</table>
<property expert="true" readable="true"
category-resource="categoryACCOnly" default="halfoffplusone" display-name-resource="discountType" data-type="string"
hidden="false"
writable="true" name="discountType"
required="false" cache-mode="inherit"
queryable="true">
<attribute name="uiwritable" value="false" />
<attribute name="propertySortPriority" value="80" />
</property>
</item-descriptor>
<item-descriptor name="promotion">
<table name="dcs_promotion" id-column-name="promotion_id" type="primary">
<property expert="false" readable="true"
category-resource="categoryBasics" column-name="promotion_type" display-name-resource="discountType"
data-type="enumerated"
hidden="true" writable="true"
name="type" required="false"
cache-mode="inherit" queryable="true">
<option value="Item
Discount - half off plus one" code="4"
/>
</property>
</table>
</item-descriptor>
</gsa-template>
Step 3: now Create new promotion
1) Open http:localhost:8080/dyn/admin/
2) Open ATG Control Center Admistrator.
3) Open Pricing tab,under pricing click on promotions .
4) Create new promotions (Note: when you will create on new
promotions you can see Custom item type promotion name).
5) When you will create new Promotion ,you can check the date base
tables also(dcs_promotion, dcs_discount_promo)
6) Check below the screen shot:
7) You can check the way
ItemPricingCalculator oney way you will added new item into card or
check below link:
http://localhost:8080/dyn/admin/nucleus/atg/commerce/order/purchase/CartModifierFormHandler/?propertyName=order.priceInfo