add item hook

Contrib type: 
Code/CSS Snippet
Status: 
Initial upload
Moderation: 
Awaiting moderation

Downloads

Latest version: 
1.15.2.36
Compatibility: 
Ubercart 2.x

When an item is updated into cart, uc_cart module call hook 'update_cart_item':
module_invoke($data['module'], 'update_cart_item', $node->nid, $data, min($qty, 999999), $cid);

but when new item is added no hook is called for this action. I think to provide a specific hook for this option is desirable to maintain concordance between flows.

Attached a patch for uc_cart.module,v 1.15.2.36 2010/08/11 15:09:54 islandusurper


PreviewAttachmentSize
uc_cart.patch497 bytes
Max_Headroom's picture
Offline
Joined: 09/01/2008
Juice: 47
+1

Vote +1 to add this to Ubercart.

Max_Headroom's picture
Offline
Joined: 09/01/2008
Juice: 47
OK, I ran into two problems

OK, I ran into two problems:

1) Hook does not call my module when using:

<?php
module_invoke
($data['module'], 'add_cart_item', $node->nid, $data, min($qty, 999999), $cid);
?>

Instead I used:

<?php
module_invoke_all
('add_cart_item', $node->nid, $data, min($qty, 999999), $cid);
?>

2) When the hook in your module saves the item, such as in my case I flagged the node, it will add the item twice in the cart. I changed the patch. See attached.

AttachmentSize
hook_add_cart_item.patch 982 bytes
Gorka Guridi's picture
Offline
Joined: 11/23/2010
Juice: 9
Consider 'add_to_cart' hook

In relation with 2)
Have you considered the option to use the 'add_to_cart' hook that is called before?
If you create your own hook and your method returns (ex.) array( 'my_module' => array( 'success' => false, 'silent' => true ) ); after you insert the item into cart by yourself, the process will avoid to insert this item twice.

The main idea of this hook is notify that an item has been added to cart (after it has been set into database) in order to maintain concordance with update process.