Hello,

I have set up an "Order has a product with a particular attribute option" condition, but the Rule does not seem to be taking that condition into account during checkout. Here is an export of the rule:

{ "get_quote_from_flatrate_2" : {
    "LABEL" : "Local Pickup conditions",
    "PLUGIN" : "and",
    "OWNER" : "rules",
    "REQUIRES" : [ "uc_attribute" ],
    "USES VARIABLES" : { "order" : { "label" : "Order", "type" : "uc_order" } },
    "AND" : [
      { "uc_attribute_ordered_product_option" : { "order" : [ "order" ], "option" : "26" } }
    ]
  }
}

In a nutshell, I want the flatrate_2 shipping method to show up in the cart only if the cart product has the attribute option with ID "26".

Thanks for any help!

Comments

TR’s picture

I can partially confirm this. What I see is that the condition DOES work on the /cart/checkout page, but DOESN'T work on the /cart page. Is that what you see too?

I created a flatrate that checks for a specific attribute option. Then I added 1 product with that option to the cart. When I go to /cart, the flatrate doesn't show (assuming you have the shipping panel enabled on /cart). When I go to /cart/checkout, the flatrate does show as expected. If I now negate the condition so that the flatrate applies only for products that DON'T have that option, I see the flatrate at /cart but I don't see it on /cart/checkout.

My flatrate conditions look just like yours:

{ "get_quote_from_flatrate_2" : {
    "LABEL" : "test flatrate conditions",
    "PLUGIN" : "and",
    "OWNER" : "rules",
    "REQUIRES" : [ "uc_attribute" ],
    "USES VARIABLES" : { "order" : { "type" : "uc_order", "label" : "Order" } },
    "AND" : [
      { "uc_attribute_ordered_product_option" : { "order" : [ "order" ], "option" : "9" } }
    ]
  }
}
TR’s picture

Status: Active » Postponed (maintainer needs more info)
nathaniel.metrock’s picture

Hi,
I am also having trouble with this condition.
In my case I have a photo for sale which has the option "Limited Edition", if checked it should charge extra shipping. When I get to the checkout page (after cart page) the shipping is standard until I click the button "calculate shipping". Then it puts the proper charge on.
Problem is the customer would never click that button since there is already shipping costs displayed and checked (only one option so nothing to pick from).
Any luck getting this to calculate properly?

TR’s picture

@nathaniel.metrock: What you describe is not related to this issue. It may be a JavaScript problem on your end, in your theme. Try it with the default Bartik theme as a starting point.

nathaniel.metrock’s picture

Thank you for the response. It seems my problem lies with auto-calculation. The shipping quote updates as soon as the zip is entered. Since it is flat rate I wish it would calculate as soon as the page loads. If anyone knows the solution to this (all the results I found are for drupal 6) please PM.

Janeyc’s picture

I get the same issue with Ubercart 7.x-3.7. There are issues in both cart and checkout.

This seems to be a bug in uc_attribute.rules.inc. I can mostly get it to work if, in the function uc_attribute_condition_ordered_product_option

if(isset($attributes[$oid])) {
is replaced with
if (in_array($oid, $attributes)) {

elseif (isset($attributes[$attribute->name][$oid])) {
is replaced with
elseif (isset($attributes[$attribute->label][$oid])) {

The use of "name" in the second bit of code looks like it ought to be logically correct but, from a bit of debugging, "name" does not seem to be held in the order object. Using "label" gives a quick workaround but is not the full solution as this code will only work if the product labels are not overridden.

TR’s picture

@Janeyc: Are you saying that you see something different than I describe in #1? If so, please provide detailed steps to reproduce your issue on a clean install of Ubercart with no contributed modules.

Janeyc’s picture

TR: Yes, if you reproduce the first issue (in the cart) but also have different values for attribute name and attribute label and then override all products with another different label you will see issue 2 (at checkout).

I've now fixed both issues with these changes to the uc_attribute_condition_ordered_product_option function:
1. Change:
if (isset($attributes[$oid])) {
return TRUE;
}
Replace with:
if (in_array($oid, $attributes)) {
return TRUE;
}

2. Change:
elseif (isset($attributes[$attribute->name][$oid])) {
return TRUE;
}
Replace with:
else {
//Attributes are keyed on the product label (not name) for the attribute - look that up
if (isset($product->attributes[$option->aid])) {
if (isset($attributes[$product->attributes[$option->aid]->label][$oid])) {
return TRUE;
}
}
}

micheled’s picture

#8 worked here. Thanks a lot

markdc’s picture

Ditto #8. Thank you!! (Works with 7x-3.8)

hockey2112’s picture

#8 worked. Thanks! You really saved my bacon!

Morbus Iff’s picture

I can confirm #8 works (and, in the absence of #8, if I rename my attribute to the same value as my label, it also works).