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

I am having a heck of a time trying to get this setup. I have scoured the forums and found several solutions but NONE seem to work correctly. I'm hoping that I am either doing something wrong or that someone will be gracious enough to take a few minutes to help.

In short, how do I setup ubercart to only charge shipping if certain attribute options are added to the shopping cart?

The issue:
I have 6 attributes and a total of 16 total options. These are going to be pretty static so I'm willing to manually set this all up in CA. I need to provide free shipping (technically they are non-shippable but I don't think there is a way to set that on the option level, which is kinda dumb if you ask me...) for 8 of the options while the other 8 are flat rate shipping based on country. I have the country based charges setup and working just fine. Obviously, if the user adds two shippable products and 1 non-shippable product to their cart it should charge them shipping.

The solutions I've tried that don't work:
Attempt #1. I setup a Domestic and Non-Shippable Product flat rate shipping method. The Domestic would charge a flat rate of $5 per product and the Non-Shippable would charge nothing. My CA would use "Order has product with particular attribute option" and then I would setup 8 conditions with the shippable attribute options OR'ed together in a condition group. I would then do the same thing for the Non-Shippable CA but would negate all the conditions. This results in the Non-Shippable Product shipping method ALWAYS being chosen regardless of what type of product I add to the cart.

Attempt #2. I then tried to use the weight setting for each option to handle the shipping charge. This client does not have a need to use the weight settings so I was going to repurpose it. I set all the options that needed a shipping charge as "1" in their weight field on the options page. The options without shipping stayed at 0 or null. Then using CA I chose "Check an order's total weight". I set the Domestic shipping method CA to quote if the total weight was "equal to or greater than" 1. And then I did the same for the Non-Shippable Product CA only negated it.

In addition to the above issues (both #1 and #2), I receive this error 27 times on the cart page AND on the product page when I go from the cart page to the product page. Refreshing the page normally gets rid of the error but it consistently errors. warning: key() [function.key]: Passed variable is not an array or object in /var/www/sites/all/modules/contrib/ubercart/uc_attribute/uc_attribute.ca.inc on line 47.

ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Re: Free Shipping for specific Product Attributes

Anybody?

ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Re: Re: Free Shipping for specific Product Attributes

Not even one kind sole willing to comment on this issue? Am I the only one that's ever had a problem with setting up the shipping?

ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Re: Free Shipping for specific Product Attributes

I came up with my own solution that I like much better that conditional actions, etc. Because I am not using the weight field but rather doing flat rate shipping, I decided to repurpose the weight field (which is option specific) for Yes/No shippable.

<?php
function uc_nonshippable_cart_item($op, &$item) {
    switch (
$op) {
    case
'load':
   
        if(
$item->weight === 1) {
           
$item->data['shippable'] = "1";
        } else {
           
$item->data['shippable'] = "0";
        }
       
        break;
    }
}
?>

now if you set the option as weight = 1 the product will be marked as shippable. If you leave it at 0 it will be marked as non-shippable and will not be used to calculate shipping cost, etc.

hellomobe's picture
Offline
Joined: 02/15/2011
Juice: 16
Use based on cart total?

Ryan, is it possible to use this same structure based on the cart's total? I'm not fully grasping when cart_item gets called in the chain of events (code).

This is the code I have so far, but the $item->data doesn't change (I'm looking at the tag on the view cart page.) You can see the other thread I started for some background - http://www.ubercart.org/forum/support/20851/free_shipping_qualified_prod.... I also see your comment here - did you get this work, and if so, how? http://www.ubercart.org/forum/support/18913/cant_remove_item_cart

<?php
function cart_total(){
   
$products = uc_cart_get_contents();
    if (!empty(
$products)) {
           foreach (
$products as $product) {
       
$nid=$product->nid;
       
$node=node_load($nid);   
        if(
$node->field_shipping_extra[0]['value'] !='1'){
     
//Calculate total of qualified products
     
$total += ($product->price) * $product->qty;
        }
        }
    if (
$total >= 250.0){
    return
TRUE;
    }
}
}
function
customsite_cart_item($op, &$item) {
       if (
cart_total() == TRUE){ '**Note: Is this line okay?'
   
switch ($op) {
    case
'load':
           
$nid=$item->nid;
           
$node=node_load($nid);
            if(
$node->field_shipping_extra[0]['value'] !='1'){
                  
//if a qualified product, set shipping to 0 so it won't calculate           
               
$item->data['shippable']= "0";                       
               
            }
     break;
    }
}
}
}
?>
ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Re: Use based on cart total?

Nothing is standing out to me as wrong with the code you have there. Just to confirm, is your module called "customsite"? If not you need to change the "cart_item" function to match.

Are you using devel? dpm, etc?

hellomobe's picture
Offline
Joined: 02/15/2011
Juice: 16
Update

Ryan: thank you so much for your reply and reminding me to use dpm - huge help.

Here is an update of the solution that I ended up with and why the code above wasn't working. http://www.ubercart.org/comment/61231

ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Re: Update

dpm() is a lifesaver! Smiling