Invalidating a Order in purchase flow

911 views
Skip to first unread message

Shaik

unread,
Aug 19, 2008, 3:04:04 PM8/19/08
to ATG_Tech
Hi!
I am trying to invoke the refreshOrder pipeline chain in the
purchase flow.
As docs says the refreshOrder pipeline chain will be invoked only when
the order is invalidated or the order is loaded from the repository.

So I am wondering when doing a purchase how could the order be
invalidated and the refreshOrder chain be excecuted?

Or when is the order in the purchase flow invalidated?

Thanks
Shaik

O'Brien, Paul

unread,
Aug 19, 2008, 3:13:40 PM8/19/08
to atg_...@googlegroups.com
Why do you want to invoke the refreshOrder pipeline?

The order is invalidated as part of error-handling. If an error occurs
during a transaction in which the order is being modified, the order is
invalidated so that it can be refreshed to its state prior to the
transaction. If a transaction is marked for rollback,
PurchaseProcessFormHandler will invalidate the order.

If you want to invalidate the order manually, you can just call
OrderImpl.invalidateOrder(), but I would recommend carefully considering
why you want to invalidate the order. For performance reasons, this
isn't something that should be done frequently.

Nooruddin Shaik

unread,
Aug 19, 2008, 3:59:02 PM8/19/08
to atg_...@googlegroups.com
Thanks Paul!
  The reason why I was trying to invoke the refreshOrder pipeline chain was I was getting an exception

**** Warning    Wed Jul 16 06:24:35 PDT 2008    1216214675656  ProcLoadRelationshipObjects    Setting commerceItem to null in order 1013346698889968, relationship col-rship1394347251306
**** Error    Wed Jul 16 06:24:35 PDT 2008    1216214675657    /atg/commerce/order/OrderManager    ---    CONTAINER:atg.service.pipeline.RunProcessException: An exception was thrown from the context of the link named [loadRelationshipObjects].; SOURCE:java.lang.NullPointerException


In a process of reproducing this error was trying to invoke refreshOrder pipeline chain.
In my case I see the commerceItem in null in the shippingGroupCommerceItemRelationship.

And also it seems to be a bug in ATG that doesn't check for invalid relationships where either of the property in the relationship is null.
I am wondering couldn't I add a new processor before the LoadRelationshipObjects to removed the invalid relationships from the order?

If I remove the invalid relationships from the order does it cause any fall-outs?

any thoughts would be appreciated.

Thanks
Shaik

O'Brien, Paul

unread,
Aug 19, 2008, 4:07:07 PM8/19/08
to atg_...@googlegroups.com

Yes, it’s true that it does not check for invalid relationships.  The bug has been fixed for the next release.

 

Yes, you could add a new processor that removes the relationships.  You would need to get to the source of why the relationship became invalid to know if it would cause any fall-outs.  Regardless, removing a bad relationship is clearly better than an error that prevents the order from being loaded at all, so I think you should go ahead with the change.

 


Nooruddin Shaik

unread,
Aug 19, 2008, 4:10:09 PM8/19/08
to atg_...@googlegroups.com
Thanks Paul!

Kartikeya

unread,
Aug 19, 2008, 4:21:45 PM8/19/08
to atg_...@googlegroups.com
Hi Paul,
 
I am experiencing this error in almost all of the server instances. As you
said this problem would be fixed in next release, could you please
share the possible reasons for this? Just FYI, it is intermittent and I am not able to
reproduce this in dev/staging env.
 
-Kartik

O'Brien, Paul

unread,
Aug 19, 2008, 4:36:23 PM8/19/08
to atg_...@googlegroups.com

Sorry, I’ve never been able to reproduce this issue myself to be able to find out why the relationships become invalid.

 


<br

lokivog

unread,
Aug 20, 2008, 3:35:32 PM8/20/08
to ATG_Tech
I’m not sure if this is the same problem that caused the invalid
shipping group commerce item relationship you guys were experiencing
but a couple months ago I was able to determine the cause for the
invalid relationship I was seeing.

This is running on ATG 2006.3 patch 5 and using the B2B module.

The problem occurs when the ShippingGroupDroplet is invoked using the
initBasedOnOrder method and the shipping groups are set to be
cleared. I determined that in this method it is not creating the
ShippingGroupCommerceItemRelationship correctly. What seems to be
happening is it can’t determine the shippingGroupName to set on the
relationship because the shipping groups were already cleared and the
user does not have a default shipping group address assigned to them
yet. When I debug it I can see that it is hitting
ShippingGroupManager.getNewShippingGroupName(…).
If I write my own test class for this method, it always returns null
unless the user already has a default shipping address assigned to
their profile.

Hope this helps.

Michael

On Aug 19, 3:36 pm, "O'Brien, Paul" <pobr...@atg.com> wrote:
> Sorry, I've never been able to reproduce this issue myself to be able to
> find out why the relationships become invalid.
>
> ________________________________
>
> From: atg_...@googlegroups.com [mailto:atg_...@googlegroups.com] On
> Behalf Of Kartikeya
> Sent: Tuesday, August 19, 2008 4:22 PM
> To: atg_...@googlegroups.com
> Subject: [atg_tech:1570] Re: Invalidating a Order in purchase flow
>
> Hi Paul,
>
> I am experiencing this error in almost all of the server instances. As
> you
>
> said this problem would be fixed in next release, could you please
>
> share the possible reasons for this? Just FYI, it is intermittent and I
> am not able to
>
> reproduce this in dev/staging env.
>
> -Kartik
>

Nooruddin Shaik

unread,
Aug 20, 2008, 4:06:15 PM8/20/08
to atg_...@googlegroups.com
Thanks Micheal!
We are also using ATG 2006.3 B2B module but Patch 3.

Let me verify this in our codebase.

Thanks
Shaik

Nooruddin Shaik

unread,
Aug 20, 2008, 5:19:48 PM8/20/08
to atg_...@googlegroups.com
Hi Micheal!
  you mean to say that if we use the ShippingGroupDroplet then this problem will exist?

But we are not using that droplet.
And also I see the paymentGroup is also null in PaymentGroupOrderRelationship sometimes.

All this happens intermittent.

Any thoughts?

lokivog

unread,
Aug 20, 2008, 6:10:24 PM8/20/08
to ATG_Tech
Shaik, I was just explaining the scenario I saw with the invalid
relationship in chance it might be the cause of yours, unfortunately
it doesn’t look like it. There could be any number of reasons that is
causing your invalid relationships.

Are you able to identify at what stage in the checkout process these
errors are occurring?
Shopping cart, shipping, payment, place order?

Are you using the recommended OOTB form handlers in the checkout
process? These would be the CartModifierFormHandler,
ShippingGroupFormHandler, PaymentGroupFormHandler,
CommitOrderFormHandler which live in atg.commerce.order.purchase. Or
are you using the legacy form handlers which live in
atg.commerce.order?

Do you have a lot of custom code in your for handlers that manipulate
the order?


On Aug 20, 4:19 pm, "Nooruddin Shaik" <shaik.noorud...@gmail.com>
wrote:
> Hi Micheal!
>   you mean to say that if we use the ShippingGroupDroplet then this problem
> will exist?
>
> But we are not using that droplet.
> And also I see the paymentGroup is also null in
> PaymentGroupOrderRelationship sometimes.
>
> All this happens intermittent.
>
> Any thoughts?
>
> On Wed, Aug 20, 2008 at 1:06 PM, Nooruddin Shaik
> <shaik.noorud...@gmail.com>wrote:

jonpallas

unread,
Aug 25, 2008, 2:31:28 AM8/25/08
to ATG_Tech
Hi all
I have been writing a bunch of REST services and found the same
problem.

I used a kind of brute force method below I check to see it the order
has any item in a bad state then i repair the order, you can just put
this in the refresh order pipeline.

cheers
Jon


public void updateOrder(Order pOrder) throws CommerceException {
OrderImpl theOrder = (OrderImpl) pOrder;
theOrder.updateVersion();
orderManager.updateOrder(theOrder);
}


public Order repairOrder(Order order) {
try {
if (order == null) {
return order;
}
// save order makes sure that the order getCommerceItemCount actual
works
order = saveOrder(order);
int orderItemCount = order.getCommerceItemCount();

List<CommerceItemBean> commerceItemBeans =
getAllGoodCommerceItems(order);
int goodItemCount = commerceItemBeans.size();

if (orderItemCount == goodItemCount) {
// its in a good state all items exist
return order;
}

Order newOrder = (OrderImpl)
orderManager.createOrder(order.getProfileId());
orderManager.addOrder(newOrder);
newOrder.setProfileId(order.getProfileId());
addAllCommerceItemBeans(newOrder, commerceItemBeans);

orderManager.removeOrder(order.getId());
order = saveOrder(newOrder);

} catch (CommerceException e) {
if (isLoggingError()) {
logError(e);
}
}
return order;
}



public Order saveOrder(Order order) {
try {
if (order == null) {
return order;
}
updateOrder(order);

order = (OrderImpl) orderManager.loadOrder(order.getId());
repriceOrderItems(order);
return order;
} catch (Exception e) {
if (isLoggingError()) {
logError(e);
}
}
return order;
}


public void repriceOrderItems(Order order) {
repriceOrder(order, PricingConstants.OP_REPRICE_ITEMS);
}

public void repriceOrder(Order order, String repriceMethod) {
DynamoHttpServletRequest request = ServletUtil.getCurrentRequest();
DynamoHttpServletResponse response =
ServletUtil.getCurrentResponse();
try {
PricingModelHolder pricingModelHolder = (PricingModelHolder)
request.resolveName(commerceProfileTools.getUserPricingModelsPath());
Locale locale = commerceProfileTools.getUserLocale(request,
response);
Profile profile = getProfile();

commerceProfileTools.repriceOrder(order, profile,
pricingModelHolder, locale, repriceMethod);
} catch (Exception e) {
if (isLoggingError()) {
logError(e);
}
}
}



private List<CommerceItemBean> getAllGoodCommerceItems(Order order) {
List<CommerceItemBean> result = new ArrayList<CommerceItemBean>();
try {
List<CommerceItem> commerceItems = order.getCommerceItems();

for (CommerceItem commerceItem : commerceItems) {
if (isItemInGoodState(commerceItem)) {
CommerceItemBean commerceItemBean =
createCommerceItemBean(commerceItem);
if (commerceItemBean != null) {
result.add(commerceItemBean);
}
}
}
} catch (Exception e) {
if (isLoggingError()) {
logError(e);
}
}
return result;
}


private CommerceItemBean createCommerceItemBean(CommerceItem
commerceItem) {
CommerceItemBean commerceItemBean = null;
try {
commerceItemBean = new CommerceItemBean();
commerceItemBean.setCatalogRefId(commerceItem.getCatalogRefId());

commerceItemBean.setProductId(commerceItem.getAuxiliaryData().getProductId());
commerceItemBean.setQuantity(commerceItem.getQuantity());
} catch (Exception e) {
if (isLoggingError()) {
logError(e);
}
}
return commerceItemBean;
}


private boolean isItemInGoodState(CommerceItem commerceItem) {
if (commerceItem == null){
return false;
}
if (commerceItem.getAuxiliaryData() == null){
return false;
}
if (commerceItem.getAuxiliaryData().getProductId() == null){
return false;
}
return true;

Nooruddin Shaik

unread,
Aug 25, 2008, 3:05:58 AM8/25/08
to atg_...@googlegroups.com
Hi Jon!
  Its nice. But I am wondering what could be the possible root cause for this problem?
If we don't synchronize the Order and modify it and the call the orderManager.updateOrder(order) will this cause these type of errors?

Can you tell me how can we be sure that we(developers) are not modifying the order which the user has created it?
Might be there could be flaw in creating the order in our code and we are tailoring the order as code developer needs.

Any thoughts would be highly appreciated!

Thanks
Shaik

Jon Pallas

unread,
Aug 25, 2008, 4:53:03 AM8/25/08
to atg_...@googlegroups.com
Hi Shaik

My code "might" be of use in fix the error you were having


"In a process of reproducing this error was trying to invoke refreshOrder pipeline chain. In my case I see the commerceItem in null in the
shippingGroupCommerceItemRelationship."


yep you should synchronize the Order or have some synchronization, this is just some sample code that don't contain that portion of the code

This code does actual modify the users order it removes invalid items. The site that im at gets Ordes into this stated because they physically remove skus from the database(this is not a good idea). Then the Order gets is a bad state and it is unrecoverable without removing the bad items



  private boolean isItemInGoodState(CommerceItem commerceItem) {
               if (commerceItem == null){
                       return false;
               }
               if (commerceItem.getAuxiliaryData() == null){
                       return false;
               }
               if (commerceItem.getAuxiliaryData().getProductId() == null){
                       return false;
               }
               return true;
       }
 


I only ever use this code on the Cart, an Order whos state is INCOMPLETE.

cheers
Jon

Nooruddin Shaik

unread,
Aug 26, 2008, 12:08:11 AM8/26/08
to atg_...@googlegroups.com
Thanks Jon!
I had similar thing in my mind.

I am not sure the error I am getting is because of the sku's which were deleted. If its so then I think I should be getting errors in setCartalogRef processor instead of in LoadRelationshipObjects processor.

I see in our code that we are not synchonizing the order before we modify it and call updateOrder(). Could there be any possibility that it might be causing the invalid relationship objects?

Thanks
Shaik

Jon Pallas

unread,
Aug 26, 2008, 2:08:38 AM8/26/08
to atg_...@googlegroups.com
Hi Shaik

This is just sample code, in fact all of this code is wrapped using the lock manager to ensure that is not only synchronized on the vm but for the cluster... because my code is stateless and i can be guaranteed that vm it will run on.

but you are correct if you where to use this code you should synchronize it in some way.

Cheers
Jon

Nooruddin Shaik

unread,
Aug 26, 2008, 2:16:41 AM8/26/08
to atg_...@googlegroups.com
Hi Jon!
  I think I didn't make my point clear. I am not questioning about your piece of code.

I am trying to find the root cause of my problem.
In my current implementation codeline, order is not synchronized, so I am asking whether this could be the cause for invalid relationships in my order?

I am trying to hunt the root cause before going for fix.

Thanks
Shaik

Jon Pallas

unread,
Aug 26, 2008, 2:28:06 AM8/26/08
to atg_...@googlegroups.com
Hi Shaik

Its possible but i have never seen that happen.

Cheers
Jon
Reply all
Reply to author
Forward
0 new messages