If a user has more than one browser tab open, the order details can be different on both pages unless the user refreshes the pages with the most up-to-date information.

I would like to fix data consistency issue by using jQuery to clone from a "central block" and replace the inconsistent cart contents with the central block's contents if and only if the contents from the pages are different than those found from the cart block. Can this be done and if so, how?

I've modified dc_ajax_add_cart.module with the following:

  $items['ajax-cart-block'] = array(
	'title' => '',
	'description' => 'Your current cart',
	'page callback' => 'dc_get_cart',
	'access arguments' => array('access content'),
   );

...and in the callback, I have the following:

function dc_get_cart() {
	$block = block_load('dc_ajax_add_cart', "ajax_shopping_cart");
	$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
	print $output;
}

The problem is that the AJAX-specific classes (i.e. - ajax-processed) are missing whenever I go to "http://mywebsite.com/?q=ajax-cart-block". The information is there and appears to be consistent but updating the form doesn't work and, well, it just doesn't act like it should. Clearly, this isn't the best way to do this.

Any thoughts on this? I would love some insight into knowing how to make this work. I think I'm going about this entirely wrong and could use some guidance. Maybe I shouldn't worry that much about someone's multiple tab use case? (Maybe I'm being overkill about it, I mean?) And yes, I know I shouldn't modify the module itself but I wanted to do this to learn more about the development of the module and to simply test things with it.

Thanks in advance.

Comments

tterranigma’s picture

Project: Commerce Cart Ajax » Commerce Ajax Add to Cart
subhojit777’s picture

Status: Active » Closed (won't fix)

Sorry for the "severe" late reply. A cleaner approach would be to use websockets.

It is beyond the scope of this module. I'm closing this issue.