3 replies [Last post]
drfuzetto@yahoo.com's picture
Offline
Joined: 01/17/2009
Juice: 91
Was this information Helpful?

I want to add an item to the cart if a certain item added to the cart has a specific attribute.

I tried doing this using hook_cart_item but it adds the item like 600 times.

Where is the best place to do this?

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: using uc_cart_add_item

Probably with a custom form submit handler added to the add to cart form using hook_form_alter().

glennnz's picture
Offline
Joined: 01/20/2009
Juice: 451
Re: Re: using uc_cart_add_item

Ryan, why won't uc_cart_add_item() work in this case?

Same for me, I get a PHP stack overflow and the item is added until I cancel the page.

My code is:

<?php

function role_price_cart_item($op, &$item) {
 
cache_clear_all();
  global
$user;
  switch (
$op) {
    case
'load':
   
$nid = $item->nid;
   
$type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $nid));
    if (
$type == 'product_type') {
        if (
$item->data['attributes'][7] == '17') {
         
uc_cart_add_item(320);
      }
    }
  }
}
?>
glennnz's picture
Offline
Joined: 01/20/2009
Juice: 451
Re: Re: Re: using uc_cart_add_item

Ah, I see why mine isn't working..... hook_cart_item() is entirely the wrong place for this...