Active
Project:
Ubercart
Version:
7.x-3.x-dev
Component:
Documentation
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
1 Feb 2012 at 19:13 UTC
Updated:
22 Sep 2013 at 09:23 UTC
Hello,
I used to use hook_uc_cart_item with the load op to interact with cart items but it has been removed from the beta 4.
I search how to interact again with cart items, I've seen hook_uc_cart_display but it was only launched on checkout page ... not on cart page
Is there a solution in beta 4 for that ?
Thanks
Comments
Comment #1
wodenx commentedCart items are now entities - so you can use the full entity-api to interact (see system.api.php).
Comment #2
longwaveI guess some example code would be useful to help people migrate from hook_uc_cart_item to the entity system. Perhaps we could document the entity hooks in the cart API docs file?
Comment #3
longwaveComment #4
bensey commentedHi there,
can someone please just make a quick comment about this here to point some of us in the right direction?
I'd love to be running rc4 but as described in #1 I can't make it do what I need it to do either.
A few simple lines of code using the straightforward
hook_uc_cart_itemwas all that was needed to adjust prices and quantities for various customer's wishes, and they carried through to the checkout. Easy!Now since cart items as entities this process seems rather bewildering. I thought I had found the solution with
hook_uc_cart_panebut changes there do not carry through to the checkout. Cart items as entities is going to be awesome, but entity api documents are way to complex for me to get a handle on how to do something as simple as described above.I've spent hours trawling through google and the code of other contrib modules, most of which are currently broken in rc4 also.
Any clues as to which entity hooks we should start looking at would be much appreciated,
ASAP please if someone can spare even just 5 or 10 minutes...
Thanks.
Comment #5
wodenx commentedNot sure exactly what it is you want to do.
If you want to adjust the *display* of an item (e.g. add some text, change the price that's displayed), use hook_entity_view() or hook_entity_view_alter() (both are documented in system.api.php, and look at uc_taxes.module for an example). This is roughly the equivalent of the old hook_uc_cart_item('display',...).
If you want to make a persistent alteration to the item (e.g. create a discount), use hook_uc_product_alter() - which is documented in uc_product.api.php. This corresponds to the old hook_uc_cart_item('load', ...).
Hope that's helpful.
Comment #6
wodenx commentedBut note that changes made using hook_uc_product_alter() may appear on the node display page - the hook is designed to allow you to use the contents of the $product->data array to alter price, qty and other fields. Usually the data array is populated when the item is added to the cart via hook_uc_add_to_cart_data(), which is invoked by both uc_product and uc_product_kit when processing the add-to-cart form.
Comment #7
wodenx commentedOh - there's also hook_node_load() which can be used to alter a product when it's first loaded. The difference between doing that and using hook_uc_product_alter() is as described above -- the latter can react to a fully populated $product->data array (which will usually be empty when the node is loaded).
Comment #8
bensey commentedThanks for the speedy reply wodenx, and for more info that I was hoping for.
That gives me something to get me started, I think I really need to bite the bullet and delve into entities in a big way..!
In answer to what it is I wish to do in #5,
right now it is pretty basic stuff (simplified here with dummy variables):
And then have the adjusted results carry through to the checkout.
Got it all working well in the cart with
hook_uc_cart_panebut all adjustments were left behind when moving to the checkout.Thanks again for your speedy feedback..!
Comment #9
mgiffordWhere is the handbook page for the D7 version. Is there at least a stub page available for this? The switch to entities is huge.
Comment #10
seanrUgh. This change just really wrecked my day. Thanks a lot (and this is part of why I'm moving to Commerce for all new work).
I need to be able to handle quantity related pricing including during updates in the cart; will hook_uc_product_alter get me there?
Comment #11
markusa commentedYeah this really sucks.....would be great if there was ANY documentation as you'll make big changes
Comment #12
markusa commentedDoes anyone have any example code?
Comment #13
gary.evans commentedHere you go, Hope this Helps:
Example Updating Price based on Attribute;
Example Updating Price based on QTY;
Comment #14
SilviuChingaru commentedI also thin those entity hooks should be docume ted in *.api.* files. Someone should add them on each Uc module that uses entities now.