I'd like to let my customers adjust their cart (contents) on the checkout page.

Right now I can't as the cart form, built by commerce_cart_form(), isn't a view and thus can't be chosen by the 'Shopping cart contents' checkout pane configuration.

If the cart form were a view...

Comments

rszrama’s picture

Yeah, I'm not sure if a View would help or not... but I bet you can achieve the same result by embedding the shopping cart form in a custom checkout pane. You'll just need to alter the submit buttons a bit to use D7's FAPI #ajax property.

recidive’s picture

Title: Cart view / form as ... view » Shopping cart as a view
Assigned: Unassigned » recidive

I'm working on this as part of #945090: Shopping cart user experience.

recidive’s picture

Status: Active » Needs review
StatusFileSize
new32.56 KB
new32.21 KB

Here is a patch that turns the shopping cart into a view.

It does this by though the "Shopping cart" views display plugin.

It's very handy since you can override the default view to include whatever fields you want.

See attached screenshot to see how the shopping cart will look with this patch.

pieterdc’s picture

Happy to see this :-)

Basically, the patch works.
At first, I didn't realize you can disable / enable the 'Remove', 'Update' and 'Checkout' buttons. But you can do so via the Views 'Shopping cart'-style settings.

Is it possible to put the 'Remove' button in a seperate field / column?

recidive’s picture

@PieterDC: Thanks for testing the patch.

I forgot to mention I added settings for opting to show/hide the buttons.

>Is it possible to put the 'Remove' button in a seperate field / column?

Good question. Perhaps it makes sense to make the delete button a view field?

pieterdc’s picture

It makes sense to me.

That would also mean we don't all have to agree on the position of the delete button - which is mentioned elsewhere in the issue queue. We only have to agree on the default position of that button.

rszrama’s picture

Yeah, delete button should end up its own field... I'll give it a shot this afternoon. Even if it's its own field, you can still display it in the same column as another field (like the Quantity box or Description).

recidive’s picture

StatusFileSize
new46.9 KB

As Ryan and me have talked on IRC, I've changed the patch so it makes uses of 'table' style plugin or any other. This is a great improvement that means you can now have cart formatted using any views style plugin, so you can have total control of output of the cart.

Also, line_item views integration has now two new fields: 'quantity_edit' field that presents the form field to edit line item quantity and 'remove' field that presents a button to remove a line item.

I've implemented an abstract class to make it easy to create other editable line item fields. The new approach is a step forward in enabling it to also allow editing other orders, not only cart.

The patch still have few rough edges, but it's ready for review of the direction it's taking.

There are three known issues:

- it's missing the Subtotal from the other patch
- it's missing a CSS class, so the cart is not formatted as in previous patch yet
- the buttons is appearing on cart block since it's not currently testing if there are quantity edit or remove button fields added to the view before creating the cart form

Also, we should move the cart form buttons to a area handler, so we can control e.g., if forms should appear on views footer, header or both.

recidive’s picture

StatusFileSize
new35.76 KB

Patch in #8 was including the cart style plugin which it shouldn't. Here's a new patch without it.

recidive’s picture

StatusFileSize
new37.96 KB

Here is an updated patch, I've moved CSS code from cart to line item module, so now the output cart form is themed. I also did some code cleanup and moved the line item editing form logic to a separate include file.

What's remaining to do is:

1. Move buttons to a views area handler so to give us control of it's placement.
2. Add back subtotal, as a views area handler as well.
3. Check for the existence of line item editing fields prior to creating the form, to avoid ending up with a form that does nothing.

recidive’s picture

StatusFileSize
new46.95 KB

Ok, the patch is now complete.

I added a new area field to line item views integration 'line_item_actions" that is responsible for outputting the views buttons. I also added hook_line_item_summary_buttons() hook for allowing other modules to add their actions buttons.

The cart views is now using the "line_item_summary".

recidive’s picture

StatusFileSize
new45.26 KB

Updating the patch to reflect new changes in github. Also removing three kitten killers chunks from last patch.

It would be awesome to get some review/testing.

rszrama’s picture

Quick heads up to say I had to fix the price field schema to use "amount" instead of "price" for the numeric value. It was inconsistent before. I'm guessing that affects this patch.

recidive’s picture

StatusFileSize
new45.72 KB

Re-rolling the patch after pulling changes from Ryan's github fork.

recidive’s picture

I'm here wondering if we shouldn't make the hook_line_item_summary_buttons() hooks return a complete form to be added to the area handler, likely this could be used for displaying the "add line item" widget to also enable making the admin order edit form a view.

recidive’s picture

recidive’s picture

StatusFileSize
new45.33 KB

Here is a re-rolled patch. No changes were made to it.

recidive’s picture

StatusFileSize
new45.33 KB

Fixing problem with PHP 5.3 variable references.

rszrama’s picture

Status: Needs review » Needs work
  1. Rename the view to commerce_cart_form / "Shopping cart form"
  2. Rename the button hook to commerce_line_item_action_info() and update the function names as necessary (i.e. the submit handlers)
  3. Let's keep the "Remove" button on the left for now
  4. Let's also remove the Line item summary area handler from the footer and decide what to do... modify that handler, add a new footer handler, or use the action handler
  5. Turns out we don't need to list files[] in .info files unless they have classes, so commerce_line_item.edit_form.inc doesn't need to be declared
  6. Let's see what happens if we just remove the order object from commerce_line_item_edit_form() and the submit handler
  7. Update the Remove button submit handler to use commerce_cart_order_product_line_item_delete(), but that would require an order... so maybe we can alter the form from the Cart module to use it
rszrama’s picture

Issue tags: +dcsprint5

Tagging.

recidive’s picture

StatusFileSize
new44.75 KB

Ok, I did 1, 3 and 5.

4 I started adding some options to the summary area handler.

6 and 7 We figured out we can't remove the order right now, since we need it.

Keeping as need work, will finish it tomorrow morning.

recidive’s picture

Status: Needs work » Needs review
StatusFileSize
new48.84 KB

Ok. I did 2. And for 4 I added options for choosing what info to show in the summary area handler. Also added some css margin for separating the summary from the actions buttons.

pcambra’s picture

It works fine to me.
Maybe we could add an option to let the user to select whether the "Remove" from cart is a button or a checkbox.

rszrama’s picture

We switched away from using checkboxes for usability, though I did try to have the buttons work through hidden checkboxes... that got shot down for some reason (it was either too buggy or just not necessary), and we switched to just using submit buttons. Will review the rest of the patch ASAP.

rszrama’s picture

Status: Needs review » Fixed

Done! Hooray!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pieterdc’s picture

Hooray idd :-)

chinita7’s picture

Does anyone know if this function can be used in Drupal6?
I really need a view for my shopping cart but this forum is only what I could find but it's for Drupal7
Thanks

recidive’s picture

@chino7: Drupal Commerce module is for Drupal 7 only. And this is not a forum, but an issue queue, so it's not the right place to ask.

As far as I know the answer for your question should be no.

chinita7’s picture

Thanks for your quick reply.
I'm sorry I misunderstood that this forum was for Ubercart as I stumbled on this forum while googling with that key word.