What is purpose of Basket Content Hash and How is it Used?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

What is purpose of Basket Content Hash and How is it Used?

Post by ZLA » Fri Jul 10, 2009 9:27 am

What is purpose of the ContentHash field in ac_Baskets? How is it used?

When I looked through the code, it only seems to be used by Google Checkout but it's not clear what it represents and when it is assigned a value or have its value changed.

Thanks

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: What is purpose of Basket Content Hash and How is it Used?

Post by Logan Rhodehamel » Fri Jul 10, 2009 12:41 pm

It is a hash value that helps us determine if anything within the basket has changed. This allows us to do things like caching of shipping rates or asynchronous checkouts (like google). The value is constructed something like

basket id:shipment 1 id:shipment 1 address:shipment 1 contents:shipment 2 id:etc

Then that is turned into an MD5 hash.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: What is purpose of Basket Content Hash and How is it Used?

Post by ZLA » Fri Jul 10, 2009 1:11 pm

I would recommend you use this in the future to make the checkout smarter. If any basket changes updated this hash value, you could then check for changes inside the Basket.Package() method and prevent the basket shipment information being lost whenever the user leaves the checkout process but doesn't make any changes. For example, if you use multiple destinations, the checkout process is not forgiving.

I can't find the post now but as an additional comment, it would be useful if the proprietary CommerceBuilder classes were completely inherited by source code stubs that just called the internal base methods. If the rest of the AC code called these stubs, users could then add their own logic around existing functions without having to track down every instance of a particular call.

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: What is purpose of Basket Content Hash and How is it Used?

Post by Logan Rhodehamel » Fri Jul 10, 2009 1:29 pm

ZLA wrote:I would recommend you use this in the future to make the checkout smarter. If any basket changes updated this hash value, you could then check for changes inside the Basket.Package() method and prevent the basket shipment information being lost whenever the user leaves the checkout process but doesn't make any changes. For example, if you use multiple destinations, the checkout process is not forgiving.
A bug stating something similar was registered recently I believe.
ZLA wrote:I can't find the post now but as an additional comment, it would be useful if the proprietary CommerceBuilder classes were completely inherited by source code stubs that just called the internal base methods. If the rest of the AC code called these stubs, users could then add their own logic around existing functions without having to track down every instance of a particular call.
If it were that simple. We could make a library of stubs that inherited from the base classes. This library would have to reference the base library. But in order for this to work the base library would in turn have to reference the stub library. Circular references aren't allowed that way.

We have internally discussed other approaches that have the same goal. It would be nice if on a custom basis you could inherit from any of our classes and override with your own functionality. I much prefer that to selling source packages because of the difficulty that comes with upgrading customized source.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: What is purpose of Basket Content Hash and How is it Used?

Post by ZLA » Fri Jul 10, 2009 2:34 pm

I agree with the inheriting. The goal is to make it more easily customizable and / or extensible, not how to achieve it.

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: What is purpose of Basket Content Hash and How is it Used?

Post by ZLA » Sun Jul 12, 2009 9:27 am

Logan_AbleCommerce wrote:It is a hash value that helps us determine if anything within the basket has changed.
There are two overloads for GetContentHash that include an array of OrderItemType:
  • GetContentHash(OrderItemType[])
  • GetContentHash(bool includeUserAddress, bool includeShipments, bool includeUserInputFields, OrderItemType[])
If the OrderItemType[] array is left blank, are a) all types included in the hash or b) no types included in the hash?
If the latter, what would I need to pass in to include all OrderItemTypes?

Thanks.

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: What is purpose of Basket Content Hash and How is it Used?

Post by Logan Rhodehamel » Sun Jul 12, 2009 10:17 am

OrderItemType arguments can be null. In that case, all types are included.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

ZLA
Commodore (COMO)
Commodore (COMO)
Posts: 496
Joined: Fri Mar 13, 2009 2:55 pm

Re: What is purpose of Basket Content Hash and How is it Used?

Post by ZLA » Sun Jul 12, 2009 11:25 am

Thanks Logan.

Post Reply