3 replies [Last post]
ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Was this information Helpful?

I'm using the below code to mark products as shippable or not based on the value of the item's weight field. My reason for doing this is outlined here: http://www.ubercart.org/forum/support/18791/free_shipping_specific_produ...

The code works as expected. I commented some code out because I am deciding which is more efficient. Normally I just select the Remove checkbox associated with the item, then click Update cart. When I do that with this module enabled, it reloads the page as normal with the "Your cart has been updated" notification and NO errors. Unfortunately, it does NOT remove the item from the cart. There's no way to remove the item without disabling this code first.

My problem is that when using this code I am unable to remove the item that matches the if test from the cart.
Example: If I use the code that is not comment out ($item->weight !== 1) I am not able to remove any items that do not have weight = 1. If I use the commented code, I cannot remove any items.

What's wrong with my code that's causing this? I followed this information as much as possible: http://www.ubercart.org/docs/api/hook_cart_item

<?php
/**
* This module checks the item's weight and if '1' it marks the item as shippable. If '0' marks as non-shippable.
*/
function uc_nonshippable_cart_item($op, &$item) {
    switch (
$op) {
    case
'load':
   
        if(
$item->weight !== 1) {
           
$item->data['shippable'] = '0';
        }
   
       
/*if($item->weight == 1) {
            $item->data['shippable'] = '1';
        } else {
            $item->data['shippable'] = '0';
        }*/
       
break;
    }
}
?>
ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Re: Can't remove item from cart - hook_cart_item

Sorry to bump... but I must. These forums are pretty inactive lately Sad

vega's picture
Offline
Joined: 11/17/2009
Juice: 16
$item in cart needs to be updated

ryanschmidt,

I ran into a similar situation, where I was modifying an attribute for an item that was added to the cart. Then, remove didn't work. To resolve / solve this, I updated the item in the cart to reflect my updated value. To do this, pass $item to uc_cart_update_item() after you modify $item.

Hope that helps.

Dan

dsdeiz's picture
Offline
Joined: 12/08/2009
Juice: 73
Re: $item in cart needs to be updated

I did this as well. Unfortunately, I had an issue in which when I alter the attribute and did uc_cart_update_item(), I need to refresh the page in order for the alterations to take effect (say I updated the quantity of a product in the cart). Any ideas?

Apologies for bumping.