Drupal 7.x - Display AJAX Commerce Block (AJAX breaks)...

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Drupal 7.x - Display AJAX Commerce Block (AJAX breaks)...

Post by Wolf_22 »

I'm using https://www.drupal.org/project/dc_cart_ajax (Drupal Commerce Cart AJAX) to display a small block that contains a customer's Commerce cart order details. It's pretty simple but really neat... It's just a small block that gets displayed if someone clicks on a little cart icon (this part I added myself) but in the revealed block, it displays every line item, the individual and total cost, etc. One thing I've noticed, however, is that the cart's contents do not maintain order consistency. For example, if more than one page is opened in the users' browsers and they add something to their cart from one of the windows / tabs, it will not reflect the same order details over in one of the other opened windows / tabs. Depending on the kind of customer, this can lead to headaches. But in the bigger scheme of things, do you think this is a big deal if the customer is forced to review their orders before confirmations?

I get tunnel vision from issues like this, so I decided to modify the module to allow the block to be displayed in a special URL location so that this variable number of pages' carts can be updated every 10 seconds if and only if the contents of the block displayed at the URL endpoint I created are different than those found from the opened pages. In other words, if I display my special cart block at, say, "http://website.com/?q=ajax-cart-block", I can use this to determine if any carts are different from this "centralized cart contents." If they are, I'll then use jQuery to clone the contents of this endpoint to update accordingly the carts that are opened in the browser pages / tabs. Thoughts?

I've modified dc_ajax_add_cart.module (the main module file) with the following:

Code: Select all

$items['ajax-cart-block'] = array(
   'title' => '',
   'description' => 'Your current cart',
   'page callback' => 'dc_get_cart',
   'access arguments' => array('access content'),
);
...and in the page callback (dc_get_cart), I have the following:

Code: Select all

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 block loads perfectly fine except that I think some AJAX classes aren't being applied... (This is an AJAX cart that can update contents using AJAX.)

The problem is that when I go to view the cart at http://website.com/?q=ajax-cart-block, I get the block as expected but the forms in the block code (the line items, that is) do not update as expected whenever I try to either remove or update one of the items. I examined the markup and one difference between the markup from this block and those found on the "normal pages" is that it's missing the "ajax-processed" class on some of the elements. Any idea why this might be? Should I just scrap this entire idea and rely on my customers being intelligent enough to check their own orders at confirmation? (Bad question, I know! Ha.)

Thanks in advance.
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Re: Drupal 7.x - Display AJAX Commerce Block (AJAX breaks)..

Post by Wolf_22 »

I wound up using the following in the callback... It's working now. :)

Code: Select all

function dc_get_cart(){
	return dc_ajax_add_cart_block_view('ajax_shopping_cart');
}
...which is the code in the module responsible for generating the block. (I just didn't realize it until lately after going over some of the code more.)
Post Reply