Page 1 of 1

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

Posted: Fri Jul 10, 2009 9:27 am
by ZLA
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

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

Posted: Fri Jul 10, 2009 12:41 pm
by Logan Rhodehamel
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.

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

Posted: Fri Jul 10, 2009 1:11 pm
by ZLA
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.

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

Posted: Fri Jul 10, 2009 1:29 pm
by Logan Rhodehamel
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.

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

Posted: Fri Jul 10, 2009 2:34 pm
by ZLA
I agree with the inheriting. The goal is to make it more easily customizable and / or extensible, not how to achieve it.

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

Posted: Sun Jul 12, 2009 9:27 am
by ZLA
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.

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

Posted: Sun Jul 12, 2009 10:17 am
by Logan Rhodehamel
OrderItemType arguments can be null. In that case, all types are included.

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

Posted: Sun Jul 12, 2009 11:25 am
by ZLA
Thanks Logan.