Hello,

We decided to use Ajax Cart in our project (thanks for the module).
Our customer requirement is to perform significant appearance customization to the cart (both the page and the block).
We do not want to perform these customizations twice - once at the ajax cart block (them) and then to the original cart page (even more of a problem because of the tapir tables).
Thus we would like to add quantity field to the ajax cart block (which is the only item that does not exist when comparing to the page) and override the cart page with our own custom page that will show the ajax cart block. This way we will get rid of the original cart page and we'd invest all our effort in customizing the ajax cart block.

Any hints / thoughts / ideas on how to do that? Is there a better way to achieve the same goal?

Thanks a lot.

Comments

PieterDC’s picture

Version: 6.x-2.0-rc1 » 6.x-2.x-dev
Category: support » feature

@udig Have you made any progress on this yet?

Our customer has the exact same wish.

Looks like there's no easy way to update the quantity of just 1 cart item and re-use the AJAX functionality of the cart page for the cart block, as that requires a (Drupal generated) form to be present, containing the complete cart contents.

But we could extend the UcAjaxCart with similar functionality as there is for the item removal (from cart); removeItemFromCart().
Ps: codewise, removing an item from cart is the same as using the ubercart update function and setting quantity to 0.

The other "option" would be to re-use the cart page form to display in the cart block:
But that makes theming harder because of the tapir tables, as you already said.

My quick hack goes like this: add
$vars['form'] = drupal_get_form('uc_cart_view_form', $vars['items']);
to uc_ajax_cart_preprocess_uc_ajax_cart_block_content()
and replace the contents of uc_ajax_cart_block_content.tpl.php with

<div id="cart-form-pane"><?php print $form; ?></div>
PieterDC’s picture

Status: Active » Needs work

Update:

I placed the preproccess extension, which provides $form to the template file, in a custom module to avoid hacking the core module as much as possible.
But I had to place ajaxCartInitCartView(); at the end of function ajaxCartInitCartBlock() in uc_ajax_cart.js to make it work.

I'm not pleased with the dirtiness of this hack.
But I am pleased with the result ;-)

Ps: I used a hook_tapir_table_alter() implementation and some CSS for visual cleanup.

PieterDC’s picture

Another update:

To fix the fact that this doesn't quite work until the page gets refreshed, a module hack is necessary.

I removed drupal_add_js(array('uc_ajax_cart' => array('AJAXIFY_CART_PAGE' => TRUE)), 'setting'); from uc_ajax_cart_form_alter() and placed 'AJAXIFY_CART_PAGE' => variable_get('uc_ajax_cart_ajaxify_cart_page', 1), in _uc_ajax_cart_load_res() so the javascript setting is also available on non-cart pages (showing the cart block with ajaxified cart page functionality).

And I added drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css'); to _uc_ajax_cart_load_res() so the default cart (page) CSS also gets loaded on every page.

lucasvm’s picture

Can you please add a zip or rar with the final stuff ?