Monday, 7 May 2012

Procedure to override Item PriceList using Calculator in ATG10:


Procedure to override ItemPriceListCalculator in ATG10:
Step-1:  implement your own pricing calculator class by extending “ItemListPriceCalculator “class
Sample code like below:
public class XxPriceCalculator extends ItemListPriceCalculator {
private static final String PERFORM_MONITOR_NAME = "XxPriceCalculator";
private static final String TRUE_STRING = "true";
public final static ComponentName SHOPPING_CART= ComponentName.getComponentName("/atg/commerce/ShoppingCart");
private XxRepositoryService priceService ;
/**
* Price a single item in a context. this method will only update the price if the monthlyOnlinePrice has been set, so it should only affect talkplan prices
*
* @param pPriceXx ItemPriceInfo representing the current price Xx for the item
* @param pItem The item to price
* @param pPricingModel A RepositoryItem representing a PricingModel
* @param pProfile The user's profile
* @param pExtraParameters A Map of extra parameters to be used in the pricing, may be null
*/
@SuppressWarnings("unchecked")
@Override
public void priceItem(ItemPriceInfo pPriceXx, CommerceItem pItem, RepositoryItem pPricingModel, Locale pLocale, RepositoryItem pProfile,
Map pExtraParameters) throws PricingException {
String perfName = "priceItem";
PerformanceMonitor.startOperation(PERFORM_MONITOR_NAME, perfName);
boolean perfCancelled = false;

try {
Object priceSource = getPriceSource(pItem);
if (priceSource == null) {
try {
if (!perfCancelled) {
PerformanceMonitor.cancelOperation(PERFORM_MONITOR_NAME, perfName);
perfCancelled = true;
}} catch (PerfStackMismatchException psm) {
if (isLoggingWarning()) {
logWarning(psm);
}}
throw new PricingException(MessageFormat.format(Constants.NO_PRICE_SOURCE, new Object[] { pItem }));
}
RepositoryItem skuItem = (RepositoryItem) priceSource;
if (skuItem != null) {
if (isLoggingDebug()) {
logDebug("Calculating price for " + priceSource);
}
OrderHolder shoppingCart = (OrderHolder) this.resolveName(SHOPPING_CART, false);
if (shoppingCart != null) {
String offerAvailStatus = null;
String priceValue = null;
String XxId = null;
try {
if(null != pProfile) {
XxId = (String) pProfile.getPropertyValue("XxId");
offerAvailStatus = this.priceService.queryOfferAvailabilityStatus
(XxRepositoryService.XX_MANAGEMENT_DESCRIPTOR_NAME, XxId);
priceValue = this.priceService.queryXxPrice
(XxRepositoryService.XX_MANAGEMENT_DESCRIPTOR_NAME, XxId);
if (isLoggingDebug()) {
logDebug("XxPriceCalculator : Xx ID " + XxId
+ "Profile ID" + pProfile.getRepositoryId());
}}
if(null == offerAvailStatus ||
(null != offerAvailStatus && offerAvailStatus.equalsIgnoreCase(TRUE_STRING))) {
if (priceValue != null) {
Double price = Double.parseDouble(priceValue);
//price is not null
if (null != price) {
pPriceXx.setCurrentPriceDetails(new ArrayList());
// only need to update the price if the monthly online price has been set
priceItem(price.doubleValue(), pPriceXx, pItem, pPricingModel, pLocale, pProfile, pExtraParameters);
if (isLoggingDebug()) {
logDebug("ItemPriceInfo for " + priceSource + "=" + pPriceXx);
}
if(null != XxId) {
this.priceService.updateOfferAvailabilityStatus(XxId, TRUE_STRING);
}}}}
} catch (RepositoryException repExec) {
// TODO Auto-generated catch block
repExec.printStackTrace();
}}}
} finally {
try {
if (!perfCancelled) {
PerformanceMonitor.endOperation(PERFORM_MONITOR_NAME, perfName);
perfCancelled = true;
}} catch (PerfStackMismatchException e) {
if (isLoggingWarning()) {
logWarning(e);
}}}// end finally
}
@Override
@SuppressWarnings(XxConstants.UNCHECKED)
public void priceItems(List pPriceXxs, List pItems, RepositoryItem pPricingModel, Locale pLocale, RepositoryItem pProfile, Order pOrder,
Map pExtraParameters) throws PricingException {

for (int i = 0; i < pItems.size(); i++) {
CommerceItem cItem = (CommerceItem) pItems.get(i);
ItemPriceInfo priceInfo = (ItemPriceInfo) pPriceXxs.get(i);
Object priceSource = getPriceSource(cItem);
RepositoryItem skuItem = (RepositoryItem) priceSource;

if (skuItem != null) {
if (isLoggingDebug()) {
logDebug("Calculating price for " + priceSource);
}
String priceValue = null;
String offerAvailStatus = null;
String XxId = null;
try {
if(null != pProfile) {
XxId = (String) pProfile.getPropertyValue("XxId");
offerAvailStatus = this.priceService.queryOfferAvailabilityStatus
(XxRepositoryService.XX_MANAGEMENT_DESCRIPTOR_NAME, XxId);
priceValue = this.priceService.queryXxPrice
(XxRepositoryService.XX_MANAGEMENT_DESCRIPTOR_NAME, XxId);
}
if(null == offerAvailStatus ||
(null != offerAvailStatus && offerAvailStatus.equalsIgnoreCase(TRUE_STRING))) {
if (priceValue != null) {
Double price = Double.parseDouble(priceValue);
//price is not null
if (null != price) {
priceInfo.setCurrentPriceDetails(new ArrayList());
// only need to update the price if the monthly online price has been set
priceItem(price.doubleValue(), priceInfo, cItem, pPricingModel, pLocale, pProfile, pExtraParameters);
if (isLoggingDebug()) {
logDebug("ItemPriceInfo for " + priceSource + "=" + priceInfo);
}}}
if(null != XxId) {
this.priceService.updateOfferAvailabilityStatus(XxId, TRUE_STRING);
}}} catch (RepositoryException repExec) {
// TODO Auto-generated catch block
repExec.printStackTrace();
}}}}
public XxRepositoryService getPriceService() {
return priceService;
}
public void setPriceService(XxRepositoryService priceService) {
this.priceService = priceService;
}}

Step-2:  create ATG pricing calculator componend by using above implementation class
Ex: XxPriceCalculator.properties
#
# The ItemPricingCalculator which gets the differential handset price
#

$class=com.Xx.pricing.QuotePriceCalculator

loggingIdentifier=ItemListPriceCalculator

pricePropertyName=listPrice
requirePriceValue=false
priceFromCatalogRef=true

pricingTools=/atg/commerce/pricing/PricingTools

repository=/atg/commerce/catalog/ProductCatalog
priceListsRepository=/atg/commerce/pricing/priceLists/PriceLists

priceListService=/shop/service/PriceListService

priceService=/com/Xx/service/PriceMatchingRepositoryService
Step-3: configure your own pricing calculator component in bellow path /atg/commerce/pricing/ItemPricingEngine
EX: ItemPricingEngine.properties  
# @version $Id: //hosting-blueprint/B2CBlueprint/version/10.0.2/EStore/config/atg/commerce/pricing/ItemPricingEngine.properties#2 $$Change: 635969 $

# This set is used if you are using priceLists to store your
# prices.  This means the prices are retrived from the PriceLists
# repository.
preCalculators=\
        calculators/ItemPriceListCalculator,\
        calculators/ItemPriceListSaleCalculator,\
        /com/Xx/pricing/QuotePriceCalculator,\
        calculators/ConfigurableItemPriceListCalculator,\
        calculators/ConfigurableItemPriceListSaleCalculator
       
priceInfoClass=atg.projects.store.pricing.StoreItemPriceInfo
Step-4: configure PricingTools component in bellow path /atg/commerce/pricing/PricingTools
EX: PricingTools.properties
# @version $Id: //hosting-blueprint/B2CBlueprint/version/10.0.2/EStore/config/atg/commerce/pricing/PricingTools.properties#2 $$Change: 635969 $
$class=atg.projects.store.pricing.StorePricingTools

Step-5: configure PricingModelProperties component in bellow path /atg/commerce/pricing/PricingModelProperties
EX: PricingModelProperties.properties
# @version $Id: //hosting-blueprint/B2CBlueprint/version/10.0.2/EStore/config/atg/commerce/pricing/PricingModelProperties.properties#2 $$Change: 635969 $
# $Id: //hosting-blueprint/B2CBlueprint/version/10.0.2/EStore/config/atg/commerce/pricing/PricingModelProperties.properties#2 $
$class=atg.projects.store.pricing.StorePricingModelProperties





No comments:

Post a Comment