Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
TR CreditAttribution: TR commentedI 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:
Comment #2
TR CreditAttribution: TR commentedComment #3
nathaniel.metrock CreditAttribution: nathaniel.metrock commentedHi,
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?
Comment #4
TR CreditAttribution: TR commented@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.
Comment #5
nathaniel.metrock CreditAttribution: nathaniel.metrock commentedThank 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.
Comment #6
Janeyc CreditAttribution: Janeyc commentedI 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.
Comment #7
TR CreditAttribution: TR commented@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.
Comment #8
Janeyc CreditAttribution: Janeyc commentedTR: 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;
}
}
}
Comment #9
micheled CreditAttribution: micheled commented#8 worked here. Thanks a lot
Comment #10
markdcDitto #8. Thank you!! (Works with 7x-3.8)
Comment #11
hockey2112 CreditAttribution: hockey2112 commented#8 worked. Thanks! You really saved my bacon!
Comment #12
Morbus IffI 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).