As a follow-up to #1033050: Support customizable products via the Add to Cart form, we now have everything in place to use commerce_cart_add_to_cart_form() as an edit form for existing cart line items. It just requires a few changes to the submit handler and the ability for the Add to Cart form display formatter to check to see if there is a "combinable" product already in the shopping cart that the form should be used to edit. The only usability challenge with automatically using the Add to Cart form as an edit form is providing visual indication that the item already exists in the user's cart.
See #1033050-10: Support customizable products via the Add to Cart form for more details.
Comment | File | Size | Author |
---|---|---|---|
#95 | where-is-my-widget.png | 61.58 KB | bisonbleu |
#92 | commerce-line-items-edit-in-cart-1211278-92.patch | 23.92 KB | NotGoddess |
#80 | Screen Shot 2015-08-10 at 3.22.19 PM.png | 56.04 KB | rszrama |
#78 | 1211278-77-78.interdiff.patch | 5.27 KB | rszrama |
#78 | 1211278-78.update_cart_attributes.patch | 8.04 KB | rszrama |
Comments
Comment #1
BenStallings CreditAttribution: BenStallings commentedI am highly motivated to get this working by January, and I should have the time to devote to it, but I'm not yet up to speed with what needs to be done. Ryan, could you be more specific about what you said above?
Comment #2
BenStallings CreditAttribution: BenStallings commentedIt looks like assigning this to myself had the effect of causing everyone else to ignore it. Sorry for the misunderstanding. I can't begin work without some answers to the questions above. Thank you in advance!
Comment #3
BenStallings CreditAttribution: BenStallings commentedI'm changing this to a support request in the hopes of getting the information I need to proceed with writing a patch ASAP.
After looking into this some, I think that the submit handler Ryan mentioned is commerce_cart_add_to_cart_form_submit() ... correct?
I think the display formatter is commerce_cart_add_to_cart_form(), but I'm not clear on where/how the $form_state variable gets populated, so I'm not sure how to pre-populate it in a wrapper page, if indeed that needs to be done. The $line_item variable seems straightforward enough... I assume that comes from commerce_line_item_load(), but I'm not clear on whether this is a generic line item that may be added to a cart or a completed line item that has already been added to a cart. That is, I'm not sure where the field values for the specific line item being edited should show up.
Regarding appearing within a node, I'm thinking the edit form should *not* be within a node, since that would make it too easy for the customer to switch products, when the goal here is to edit a product that's already been in the cart.
Am I on the right track? Any guidance would be greatly appreciated.
Comment #4
cimo75 CreditAttribution: cimo75 commentedHi
I need this myself too, I tried with http://drupal.org/project/editablefields but it doesn t seem to work, probably because D7 is still missing http://drupal.org/project/ajax_load .
Simone
Comment #5
no2e CreditAttribution: no2e commentedcommerce_product_attributes offers functionality like this.
It links the products (in the cart) with the line-item id in URL parameter.
· If you visit such a product with the URL parameter, the "Add to cart" button changes to a "Update cart" button.
· If you visit that product without the URL parameter, you see the usual "Add to cart" button and can add the product again (not edit the line item of that product already in cart).
Comment #6
cimo75 CreditAttribution: cimo75 commentedno2e: this is not what I need: what I need is a custom field in the line item that can be edited in the cart itself
Comment #7
recrit CreditAttribution: recrit commentedI believe there are 2 issues here:
The second one should be separate issue since it is more of a UI/UX feature request for the product reference add to cart formatter and the cart line edit capability.
The attached patch is a first pass at the first issue - Allow commerce_cart_add_to_cart_form() to edit line items.
Comment #8
recrit CreditAttribution: recrit commentedComment #9
Damien Tournoud CreditAttribution: Damien Tournoud commentedI haven't reviewed the patch into detail, but that seems like a good start.
That probably should be handled by access control.
Comment #10
recrit CreditAttribution: recrit commentedupdated patch as follows:
Comment #11
dpolant CreditAttribution: dpolant commentedPatch works for me.
On the line item edit form, maybe we should display the price field so that users can see what the price is when they change attributes and line item fields.
Comment #12
dpolant CreditAttribution: dpolant commentedUpdated patch provides a price field display that updates when you change the attribute widget.
Comment #13
recrit CreditAttribution: recrit commentedre-rolled to worked with latest Commerce 1.x-dev.
Comment #14
rszrama CreditAttribution: rszrama commentedAssigning to helior for a quick review, as he's been digging through Views code lately. ; )
Comment #15
helior CreditAttribution: helior commentedTracking.
Comment #16
helior CreditAttribution: helior commentedThis is neat! Although, has very little to do with Views :P Nonetheless, now that there is a menu item I can finally add Devel and Devel Token support for line items in Commerce Devel! The menu item had to be modified just a little to make it more consistent with the other menu items in order to make that work, though! :)
Overall, the patch looks good to me and everything is functioning as expected. I'll leave it as Needs Review in case anyone else wants to weigh in on this.
Comment #17
pcambraI've given this a try and fixed some things.
Not sure why we're using a dedicated function for this: "commerce_cart_line_item_form_menu_item_access" I'd say we should define an independent permission and use the generic commerce access api.
Patch attached
Comment #18
pcambraOh, and we'd need tests
Comment #19
recrit CreditAttribution: recrit commentedComment #20
recrit CreditAttribution: recrit commentedupdated -17 to work with the latest dev
Comment #21
vasikehas no success patching with the last one
#20: commerce_cart-edit-cart-lines-1211278-20.patch queued for re-testing.
Comment #23
recrit CreditAttribution: recrit commented@vasike - it fails b/c this patch was for the 1.x-dev over a month ago. It will need re-rolled.
Comment #24
recrit CreditAttribution: recrit commentedupdated patch that works with 7.x-1.x as of a48de19
Comment #25
recrit CreditAttribution: recrit commentedComment #26
vasikemy test results
- combine : works
- "Cart Line Item Edit link" works
what about Cart Line Item Edit page display? is there a way to control what and how should be displayed on that page
is there anything else to be checked?
Comment #27
recrit CreditAttribution: recrit commented@vasike:
Currently, its mostly the add to cart form with the price field added to the form array. A custom view mode could be added on the product or line item to customize what fields would show on the "line item: edit form" , then the $show_price and price field in the form array wouldn't be needed.
Comment #28
lsolesen CreditAttribution: lsolesen commentedI applied the patch to an existing commerce installation. How will I get the cart to show the editable custom line items?
Comment #29
recrit CreditAttribution: recrit commentedYou can edit the cart view and then add the field "Cart Line Item Edit link" .
Comment #30
ultimikeThis is a fine addition to the Commerce module. I just installed patch 24 on a site we're building and so far so good.
I'll report back if we see any issues moving forward. I'd love to see this committed to the next version of Commerce.
Thanks,
-mike
Comment #31
rszrama CreditAttribution: rszrama commentedGreat, thanks for the review Mike.
Comment #32
jasen CreditAttribution: jasen commentedFor those who may be interested, I've created a module in a sandbox project that allows editing of all line items after they've been added to the shopping cart:
http://drupal.org/sandbox/jasen/1858212
And here's one that you can use in tandem with the above module to allow administrators to edit the line items in the backend:
http://drupal.org/sandbox/jasen/1858214
Please note that these are sandbox projects, but are working great for me on a few websites...
--
Jasen
Comment #33
akalata CreditAttribution: akalata commented#24 is also working for me.
Comment #34
SandraVdv CreditAttribution: SandraVdv commentedThis patch won't apply to 7.x-1.5...
What functionality will the patch provide exactly? Will it be able to show an attribute field as a select list on the cart page view and change the line item when it's changed?
Comment #35
kepford CreditAttribution: kepford commentedRerolled patch from #24 against SHA:b18f77832228953a0fd96a1167d91504a7332194. Have not tested it on 7.x-1.5 yet.
Comment #36
tribsinpa CreditAttribution: tribsinpa commentedThere is an issue with editing a line item if it has an image/file field attached. Error is thrown on when there is an existing image attached that is not modified. There is no error thrown if all images are removed or if a new "fresh" images are attached.
Using
Drupal 7.19
Commerce 7.x-1.4
Comment #37
tribsinpa CreditAttribution: tribsinpa commentedComment #38
tribsinpa CreditAttribution: tribsinpa commentedI found the issue, in #36. It has to do with the Commerce Product Attributes module. This module adds a submit callback to the commerce_cart_add_to_cart_form that deletes the line item completely when it is "edited". When the line item is deleted it also deletes the managed file from the system. Once the managed file is gone it starts throwing those errors
The fix is the commerce_product_attributes_add_to_cart_form_submit function removes the line item REFERENCE to the order, rather than delete the entire line item. The caveat is that there may be cron function needed that periodically cleans up the orphaned line items.
I altered commerce_products_attributes/commerce_products_attributes.module
lines 256-273
Comment #39
akalata CreditAttribution: akalata commentedAttached an update of #35 that should work with 7.x-1.5 (patch was applying to commerce_cart.views.inc in the wrong place).
There is some views-related refactoring in commerce_cart.views.inc in 7.x-1.x-dev, but I don't know enough about what's going on to make additional updates just yet.
Comment #40
akalata CreditAttribution: akalata commentedAttaching the file might actually help.
Comment #42
akalata CreditAttribution: akalata commentedTrying against 7.x-1.x. If you're trying to apply #40, I missed a new file (commerce_cart_handler_field_cart_line_item_link_edit.inc - still figuring out this patching stuff).
Comment #43
akalata CreditAttribution: akalata commentedComment #44
pcambraComment #45
ADrupalUser CreditAttribution: ADrupalUser commentedNot working for me against 7.x-1.7.
Comment #46
askibinski CreditAttribution: askibinski commentedI tested the patch at #42 against 1.7 and -dev, but I think it's made for an older version? Patch didn't apply cleanly, however I got to the following steps:
I Added the new field 'Cart Line Item Edit link' to the /cart view 'commerce_cart_form'.
After saving the view I got the notices below and the view does not display anymore.
I'm using the latest stable version of Views, Drupal, etc. I'm not very familiar with views handlers but hope this will help. Would be a great patch!
BTW: I might mention that I got 2 products in my cart in the above scenario: one with 3 variations (products) available and one which is always one parent node <-> one product, but the results were the same with just one of the products.
Comment #47
askibinski CreditAttribution: askibinski commentedFor anyone struggling with this, I found this module, which does mostly what I needed:
http://drupal.org/project/commerce_line_item_cart_form
Comment #48
akalata CreditAttribution: akalata commentedHey askibinski -- I realized a few weeks ago I didn't have the views stuff working, finally got around to fixing it. Woohoo!
Thanks for sharing the module in #47, but for me I needed an edit page.
Patch below is against 7.x-1.x from 4/30/13.
Comment #49
Marc Angles CreditAttribution: Marc Angles commentedHI, akalata, thanks a lot for this !
Patch #48 applies well on 7.x-1.7.
Unfortunatelly, when I add the "Cart Line Item Edit link" to my view, it asks for confirmation of the relationship and we end up with a "Broken/missing handler"
Comment #50
Marc Angles CreditAttribution: Marc Angles commentedThere was a views release soon after the patch was submitted https://drupal.org/node/1965242. Could it be the cause of the broken/missing handler bug ?
Comment #51
Marc Angles CreditAttribution: Marc Angles commentedHere is some debug messages
What happen is that the handler does not show at all. I needed to disable cache in views, restart php and memcached, empty the cache. Then the handler appears in the views config and display this message when trying to add it. It is not a test in a brand new drupal installation.
Comment #52
Marc Angles CreditAttribution: Marc Angles commentedOk, last patch did not create modules/cart/includes/views/handlers/commerce_cart_handler_field_cart_line_item_link_edit.inc
Here is another one.
It is magik :)
Thanks a lot.
Comment #53
kepford CreditAttribution: kepford commented#52: line-items-edit-in-cart.patch queued for re-testing.
Comment #55
kepford CreditAttribution: kepford commentedRerolled line-items-edit-in-cart.patch from #52. This time against 1.8.
Comment #56
kepford CreditAttribution: kepford commentedLet's try that again. Rerolled line-items-edit-in-cart.patch from #52. This time against 1.8.
Comment #57
Marc Angles CreditAttribution: Marc Angles commentedHmmm... the patch applies.
But the edit form is completely empty. No fields, just the price...
@kepford, do you have good results ? Is this functioning well for you ?
Comment #58
kepford CreditAttribution: kepford commented@Marc Angles it's working perfectly for me.
Comment #59
Marc Angles CreditAttribution: Marc Angles commentedOk, it is working now. But on some products I have this Fatal error
Fatal error: Class name must be a valid object or a string in /drupal-7-2013.08.22/includes/common.inc on line 7827
I don't know if this error is caused by this patch.I can confirm it is not caused by this patch.Comment #60
abelwang CreditAttribution: abelwang commented#24: commerce_cart-edit-cart-lines-1211278-24.patch queued for re-testing.
Comment #61
botrisConfirming #56 to work for 1.8
Comment #62
darrenmothersele CreditAttribution: darrenmothersele commentedconfirmed #56 works for 1.8 (dev).
Comment #63
Anybody#56 works great! Time for RTBC?
Comment #64
halloffame CreditAttribution: halloffame commentedSuccessfully applied patch #56 against 1.8 and 1.x-dev but nothing happens upon clicking the edit link, it just reloads the cart page.
Comment #65
darrenmothersele CreditAttribution: darrenmothersele commentedI had confirmed for 1.8, against a D7 site with commerce modules.
Tried on Commerce Kickstart and found same as comment #64, but didn't have time to look further into what was going on.
Comment #66
darrenmothersele CreditAttribution: darrenmothersele commentedJust to confirm, the version without Commerce Kickstart, just the 1.8 commerce module, is working fine with this patch.
Comment #67
mglaman#56 applied clean and worked on Commerce 1.8 bundled in Commerce Kickstart.
Comment #68
halloffame CreditAttribution: halloffame commentedIs this committed to the latest 7.x-1.9?
Comment #69
rszrama CreditAttribution: rszrama commentedThis would be marked fixed if it was. : )
Comment #70
pixeldroid CreditAttribution: pixeldroid commentedThis doesn't work with Commerce Pricing Attributes. Items with price attributes are not added to cart. System shows "Product added to cart" but the cart is empty.
Comment #71
Marc Angles CreditAttribution: Marc Angles commented#56 applies correctly on 1.9.
And it works fine.
Comment #74
Marc Angles CreditAttribution: Marc Angles commentedI applied the patch on 7.x-1.10
Now, anonymous cannot see the line-items anymore.
When logged-in they see it without problem.
Comment #75
rszrama CreditAttribution: rszrama commentedWow, I completely forgot about this issue and the patches it had. I had a requirement for a client to allow editing of attributes in the cart form, so I created a custom Views form field handler that basically builds the Add to Cart form using the line item data as expected and embeds the resulting attribute widgets in the form.
I still need to ensure it reloads the full View when a line item changes, but otherwise it's golden. One thing it doesn't have is line item fields, but those could be added in a like manner using a separate field handler.
I'm inclined to go this route over the full edit form approach in the patches above, as it's a much smaller footprint and something that anyone can easily add to their Views without disrupting any existing site. Anyone wanna review?
Comment #76
serundeputy CreditAttribution: serundeputy at Common Media commentedApplied patch: https://www.drupal.org/files/issues/1211278-75.edit_attributes_in_cart.p...
I added an attribute field to my commerce cart view: `/admin/structure/views/view/commerce_cart_form/edit`, but received an error when trying to visit the shopping cart.
unapplied the patch and I'm able to get back to the shopping cart.
Am I doing it wrong?
~Geoff
Comment #77
serundeputy CreditAttribution: serundeputy at Common Media commentedIssue #1211278: Commerce Module
Why:
* Allow editing of product attributes from the cart.
This change addresses the need by:
* Check isset($subform['product_id']['#value']) make sure there is a #value index.
Comment #78
rszrama CreditAttribution: rszrama commentedGreat lead on the error there - it turns out the reason you saw the error was because your products weren't using attributes but the basic product select list element. In that case, we needed to look in its #default_value property instead of #value. I've updated the code to pull it from there instead and to function if it can't find the product_id element at all.
I've also updated the refresh callback to completely re-render the View when it's called and drop it in as a full replacement. That was the clearest way I could see to update the entire cart form when a line item product changed. It's a bit hacky to unset $_POST variables directly like this, but I just disable what I needed to to ensure the Views form wouldn't be re-processed when we manually rebuilt the View.
Comment #80
rszrama CreditAttribution: rszrama commentedI just remembered I need to test this with Commerce Stock to make sure it's gravy. In any event, here's a screenie of this sucker in action working both for a product with attributes (including attributes that collide) and a simple product selector:
Comment #81
rszrama CreditAttribution: rszrama commentedDid some additional testing and committing this sucker. Whoop whoop.
Comment #83
AnybodyWhao, thank you so much! Great work!! Whoop whoop! ;)
Comment #84
rszrama CreditAttribution: rszrama commentedhehe, thanks. : )
To use, you just edit the Shopping Cart Form View and add the attribute widgets field handler. Should be plug and play. File new issues in the queue if you can break it. : P
Comment #86
scotty014 CreditAttribution: scotty014 as a volunteer commentedIs this feature still available? Looking at the most recent commerce version I don't see any of the changes from this commit.
Comment #87
rszrama CreditAttribution: rszrama at Centarro commentedYep, it's there. You just need to edit the View and plug in the new field handler. I haven't written a tutorial for it yet...
Comment #88
scotty014 CreditAttribution: scotty014 as a volunteer commentedI figured it out. Didn't realize I needed the Dev version of the commerce module to get the updated code.
Comment #89
rszrama CreditAttribution: rszrama at Centarro commentedAhh, yeah, I've been trying to roll a 1.12 for months now and it just keeps slipping. :-/
Comment #90
NotGoddess CreditAttribution: NotGoddess commentedI'd like clarification on just what was committed.
It appears that the patch that was committed doesn't have the same features as the one in #56.
#56 allowed an 'edit' link to go to the line item entity and edit it.
The patch committed #82 seems to allow editing attributes from the cart form.
#56 worked great for me - but the version committed doesn't appear to since I have line items with multiple fields and don't display them individually - I need the separate form.
If I'm just mistaken can you provide some instructions, or do I need to roll a version of #56 that'll work with 1.13?
Thanks
Comment #91
rszrama CreditAttribution: rszrama at Centarro commentedYeah, what was committed was not a full line item edit form. I did suggest if we need line item fields as opposed to attribute selection widgets to appear in the Cart that a similar Views field handler could be committed.
Comment #92
NotGoddess CreditAttribution: NotGoddess commentedOkay. I re-rolled the line item version against the latest dev.
Comment #93
bunset CreditAttribution: bunset commentedHello!. I am new applying a patch and I don't get it.
Please. What am I doing bad please? Thanks!
After seeing what is the patch for my commerce version,
I try to apply path #92 over commerce 1.13, then I download the patch file and I put it in directory profiles/commerce_kickstart/modules/contrib/commerce.
And there, I type the command: patch < commerce-line-items-edit-in-cart-1211278-92.patch
but it says this error:
---------------------------------------
can't find file to patch at input line 5
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/modules/cart/commerce_cart.info b/modules/cart/commerce_cart.info
|index d7195fc..11ff819 100644
|--- a/modules/cart/commerce_cart.info
|+++ b/modules/cart/commerce_cart.info
--------------------------
File to patch:
-------------------------------------------------
Comment #94
bisonbleu CreditAttribution: bisonbleu commented@bunset, try with
patch -p1 < commerce-line-items-edit-in-cart-1211278-92.patch
Comment #95
bisonbleu CreditAttribution: bisonbleu commentedOK, I'm officially jealous. It's not fair, product types get all the love...
Can we also have Attribute field widgets for line item type fields... please!
I added a List (float) field to the Product line item type in CK2 then added the Commerce Line Item: Attribute field widgets in the cart view but I only see product type attributes (color & size), snif~
Comment #96
rszrama CreditAttribution: rszrama at Centarro commentedIs that not already possible with the editable fields module? I suppose it's just not directly integrated with the cart submit.
In any event, that would be a separate feature request. Those aren't attribute fields, just line item fields.
Comment #97
bisonbleu CreditAttribution: bisonbleu commented@rszrama, thanks for the quick reply. I created a separate feature request: #2735065: Allow commerce_cart_add_to_cart_form() to edit line item fields
Comment #98
iyyappan.govindHi How to do this in Drupal 8?