Currently working on having different "sites" using Domain Access but don't want the carts being shared across the sites. The only way I can see to do this is to implement hook_commerce_cart_order_id to run a different query and return the relevant cart for the site the user is seeing.
The problem comes when the user first visits site B after making a cart on site A. The way the hook is used, we cannot return a "no cart" for site B without first creating a new cart which isn't a good way of doing things.
A simple change to commerce_cart_order_id() would be to allow the modules implementing hook_commerce_cart_order_id to return FALSE to say that there is no cart for the requested user.
Thoughts?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 1366976-hook-commerce-cart-order-id-no-cart-8.patch | 1.17 KB | mjpa |
| #1 | 1366976-hook-commerce-cart-order-id-no-cart.patch | 1.12 KB | damien tournoud |
Comments
Comment #1
damien tournoud commentedI agree, this is unfortunate. I guess we need something like this?
Comment #2
mjpa commentedThat's pretty much what I was going to submit as a patch yesterday but you beat me to it :)
I'll apply the patch on Monday and give it a test and report back - should be no issues though.
Comment #3
maximpodorov commentedBTW, is it possible to add static caching for commerce_cart_order_id()? This function produces dozens of the same queries for a single page.
Comment #4
mjpa commentedThe patch in #1 works fine for me.
@maximpodorov: there is static caching in commerce_cart_order_load() but I guess adding it to commerce_cart_order_id() can't hurt, quick test on a site and its running at least 10 times.
Comment #5
mjpa commentedSeems to work fine.
Comment #6
damien tournoud commented@maximpodorov: could you please open a separate issue for the static caching, and give more information about where this function is called from in your case?
Comment #7
rszrama commentedOne substantive change from the patch in #1 is that 0 could now feasibly be returned as a valid cart order ID (which we know it wouldn't be). Perhaps FALSE should be checked first leaving the check on actual return values intact.
Comment #8
mjpa commentedGood point, modified the patch so that it checks for FALSE and returns NULL (the database queries return NULL if no cart is found). The original condition is checked then before returning the order_id.
Comment #9
rszrama commentedHmm, in my test the database queries actually returned FALSE if no cart is found. Either way it probably doesn't really matter, but I've split this out a little further and added more documentation to indicate that these hooks are executed in order and their return values are dealt with one at a time.
Commit: http://drupalcode.org/project/commerce.git/commitdiff/ff9bbc7
Comment #10
rszrama commentedForgot the status change. :-/