Needs review
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Cart
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
10 Nov 2014 at 01:39 UTC
Updated:
19 Mar 2018 at 19:17 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
rszrama commentedThis is a great idea, but I think we should simplify it so the new function just returns TRUE or FALSE. It's checking for a specific state in the application, and making it also function as an order loader complicates things. There's no performance hit to using commerce_cart_order_load() after the empty check since it's going to be cached anyways.
Comment #2
FranciscoLuz commentedCheers Ryan!
Here it is, a new patch.
Comment #3
joelpittetTo avoid calling commerce_cart_order_load() twice here, maybe consider passing it in as an optional $order param?
Comment #4
joelpittetComment #5
FranciscoLuz commentedAdded suggestion from #3.
Comment #6
joelpittetThanks for considering my feedback @FranciscoLuz, though it looks like something went sideways on that patch:
May be just whitespace issues but it's got a mix of tabs and spaces.
Could you provide an interdiff between the two patches with your changes? They help people reviewing to see the changes between the two so they don't have to manually compare on each update. @see https://www.drupal.org/documentation/git/interdiff
Comment #7
joelpittetComment #8
mglamanGoing to say, also, needs work because it has tabs and coding standards issues. FranciscoLuz, check out https://www.drupal.org/coding-standards
Comment #9
FranciscoLuz commented@mglaman please point out the issue. Simply handing over a pages long manual does not help.
Comment #10
mglamanTabs not spaces.
Array items should be on own line
EDIT:
Also, why not current_path()
Comment #11
mglamanAttaching interdiff for review. FranciscoLuz, I didn't mean offense, just that it was hard to review the diff because of tabs. Far too used to using Dreditor (https://dreditor.org/) to review patch diffs that I forgot it isn't quite as highlighted when viewing as regular text.
Comment #12
FranciscoLuz commentedI did not take it as an offence bro. Seriously, I am good with your comments. I am sorry if I sounded annoyed, I really am not.
On the current_path() issue. It makes totally sense but $_GET['q'] was not being introduced by my patch. Cheers.
Comment #13
iqbalpk commentedComment #14
vadym.kononenko commentedRe-made patch from #3. Made changes as minimal as possible. Patch respects drupal coding standards as well.
hook_alter() has been added to provide ability to make result management flexible.
Comment #16
joelpittetThanks @vadym.kononenko. Setting back to -dev as that is where the development happens for the next release.
Comment #17
hanskuiters commentedNice patch, just what I needed. I use it to alter the body class.
I placed the code below in my theme's template.php so I can show or hide the cart menu item I added to my menu.
Comment #18
dieuweWhen testing the patch, I found that if a user does not have a cart the function still returns
FALSE(meaning: cart is not empty).I've set the default value of
$is_emptytoTRUEso that we get nicer behaviour.Comment #19
hanskuiters commentedThat is nice. I had an inconcistancy, but not the time yet to look into it. Thanks, this works fine now.
Comment #20
joelpittetThis is looking great, one last thing: there are 4 places in the commerce modules that check for emptiness. It would be nice if this were used in all those places:
Comment #21
pinueve commented#3 +1, just what doctor ordered. https://www.drupal.org/project/commerce/issues/1668816
Comment #22
joelpittet@pinueve thoughts on #20?
Comment #23
subhojit777rerolling
Comment #24
subhojit777Comment #25
millionleaves commented#24 did the trick for me after upgrading to Commerce 7.x-1.14 from 7.x-1.13. I don't recall which version I'd applied to 7.x-1.13, but am guessing it was #18.
Comment #26
joelpittet@millionleaves feel free to update the status to RTBC. I don't have a project to test this out at the moment but the interdiff looks exactly what I asked for in #20
Comment #27
millionleaves commented@joelpittet I don't see "RTBC" as a status option, but have marked it Reviewed and tested by the community
Comment #28
joelpittetSorry, you picked the right one, I got lazy and used the shorthand. Thank you for updating it!
https://www.drupal.org/node/156119#rtbc
Comment #29
torgospizzaConfirmed that this function worked for me and is something we were in need of. Many thanks!
Comment #30
mglamanThere is an edge case and performance fix.
Is there a chance that
FALSEcould be passed and then this breaks?I'm pretty sure entity_load() uses reset($entities) which returns FALSE. So there is a chance this could go sideways.
I don't see any added tests to provide a way to confirm my suspicion or deny it.
Let's not use entity metadata wrappers here. They're a performance hog and
commerce_line_items_quantityconverts a wrapper to entity value anyways.We can use field_get_items and pass the item IDs to commerce_line_item_load_multiple() and pass that result.
Comment #31
torgospizzaNew patch as per @mglaman's feedback, with interdiff.
Comment #32
torgospizzaWhoops, somehow removed my call to field_get_items().
New patch and interdiff attached.
Comment #33
mglaman:) We never end up fetching the line items, the field_get_items seems to be missing.
That's why we also need a test.
EDIT: :D patch rolled
Comment #35
torgospizzaNew patch with tests. Please take a look and let me know if I'm doing it wrong :)
Comment #36
mglamanCould be just assertTrue($is_empty) :) but thanks for adding the test!