Problem/Motivation

Hello,

Great module, I found it better than the other commerce ajax cart module.

The only thing I prefer in the other module is that it use a view to render the cart whereas this module reinvent the wheel by creating the cart table from scratch in dc-ajax-shopping-cart.tpl.php

Proposed resolution

So, if you want to use the default shopping cart block provided by drupal commerce, just put that code in dc-ajax-shopping-cart.tpl.php (copy it into your theme directory before, as always).

<div class="ajax-shopping-cart-wrapper">
  <?php print views_embed_view('commerce_cart_block', 'default'); ?>
</div>

It will render the view and you will be able to customize it more easily.

We will also require to do the following:

  • Create views field that will provide a link to remove item from cart

Remaining tasks

  • Identify other aspects of the module that we need to change
  • Write a patch

User interface changes

  • The admin interface may change

API changes

N/A

Data model changes

N/A

Comments

zmove created an issue. See original summary.

subhojit777’s picture

Currently we are re-inventing the wheel, I agree. The AJAX functionality depends on the markup of the cart. Rather than embedding the view, I think it would be better to implement the AJAX functionality in existing shopping cart view itself.

subhojit777’s picture

Issue summary: View changes
subhojit777’s picture

Issue summary: View changes
subhojit777’s picture

Version: 7.x-1.3 » 7.x-2.x-dev
Neo13’s picture

Proposed solution actually works. You just need to modify the view to add remove button and whatever else you need.

prjcarr’s picture

I tried the above and it seems to work fine. Is there any way to add the remove button? I add a delete button in the view but it just redirects to the front page.

subhojit777’s picture

We have to add the remove button in the view itself.

prjcarr’s picture

Does that mean the module needs to be updated or is it possible within views now?

subhojit777’s picture

No the module does not provides remove button for view. I guess it should be possible to do inside views.

doxigo’s picture

When I add the Remove Button in Views using this approach it gives me an error:

EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 737 of /sites/all/modules/entity/includes/entity.wrapper.inc).

So I added Line Item ID and excluded it from display, using Views Base url module as well, I added a Global Text field to my views:

&lt;a href=&quot;[base_url]/remove-product/nojs/[line_item_id]&quot; class=&quot;use-ajax ajax-processed&quot;&gt;Remove from cart&lt;/a&gt;

it does work and removes the item from cart, but it's not ajax! I don't know how to fix this part, also note that the Quantity is whole another issue as well.

subhojit777’s picture

@doxigo Not sure about the error. I guess you need to add drupal.ajax library to ajaxify the custom link. See http://cgit.drupalcode.org/dc_ajax_add_cart/tree/dc_ajax_add_cart.module...

doxigo’s picture

I guess by enabling AJax in views, it adds the library, which I did, but still can't get it to work

sahaj’s picture

@doxino Did you got that remove button working?

maxplus’s picture

Yes great idea,
an update and remove button working with ajax would be great!

arefen’s picture

Hi. thanks for your perfect soulution. but ajax doesn,t work after enable ajax on views.

subhojit777’s picture

The ajax won't work because it depends on specific selectors which comes from the block template, that this module provides.

Making this module compatible with the existing cart view will be a major change, and most probably I would like to see this in 8.x version. Still if anyone would like to do the same for 7.x, they are welcome.

VasyOK’s picture

Hi drupalers!
Delite button worked with this module https://www.drupal.org/sandbox/xandeadx/2621602
Simply check Ajaxify remove button and have a nice day.