1

We charge a $50 setup fee to run made to order moulding that totals less than $250. I have managed to get it to add on the "after adding a product to the cart action as seen here:

    { "rules_setup_fee" : {
    "LABEL" : "Setup Fee",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "setup Fee" ],
    "REQUIRES" : [ "rules", "commerce_price", "commerce_cart" ],
    "ON" : { "commerce_cart_product_add" : [] },
    "IF" : [
      { "entity_is_of_bundle" : {
          "entity" : [ "commerce-product" ],
          "type" : "commerce_product",
          "bundle" : { "value" : { "moulding" : "moulding" } }
        }
      },
      { "data_is" : {
          "data" : [ "commerce-product:field-made-to-order" ],
          "value" : "Made To Order usually ships in 2-3 Weeks"
        }
      },
      { "data_is" : { "data" : [ "commerce-product:field-uom" ], "value" : "LF" } },
      { "commerce_price_compare_price" : {
          "first_price" : [ "commerce-line-item:commerce-total" ],
          "operator" : "\u003C",
          "second_price" : { "value" : { "amount" : 25000, "currency_code" : "USD" } }
        }
      }
    ],
    "DO" : [
      { "commerce_cart_product_add_by_sku" : {
          "USING" : {
            "user" : [ "site:current-user" ],
            "sku" : "0909990000005",
            "quantity" : "1",
            "combine" : 1
          },
          "PROVIDE" : { "product_add_line_item" : { "product_add_line_item" : "Added product line item" } }
        }
      }
    ]
  }
}

however I can't seem to figure out how to get it to remove the fee from the cart when they update their order to over $250 or they remove the moulding from the cart

I have tried following Randy Fays Removing Items From the Cart Using Rules

tutorial and adding a second component loop to check for the setup fee and remove it but it seems to not be able to find the setup fee under a product type of services and fees and the debugger isn't helping me at all because it says that the services and fees bundle comparison is false (even when it should be true) even though its the same as the one for moulding (except of course it's set to services and fees instead of moulding)

If anyone out there knows how I might change this to make it work please enlighten me

edit: thought of another way to possibly do this if I can find moulding that matches and then loop through instead of removing item from list I could check for setup fee and set data value for quantity to 0 either way I still want to be able to only remove one (it shows the setup fee multiple times which is good) but now I need to figure out how to break the loop after it makes a change

edit 2: I think i'm close except that I either get the product duplicated or it counts extra values

{ "rules_setup_fee" : {
    "LABEL" : "Setup Fee",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "setup Fee" ],
    "REQUIRES" : [
      "rules",
      "rules_conditional",
      "commerce_cart",
      "commerce_order",
      "commerce_price",
      "entity"
    ],
    "ON" : { "commerce_order_insert" : [], "commerce_order_update" : [] },
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "component_rules_remove_fee_from_cart" : { "line_item" : [ "list-item" ], "order" : [ "commerce-order" ] } }
          ]
        }
      },
      { "variable_add" : {
          "USING" : { "type" : "integer", "value" : "0" },
          "PROVIDE" : { "variable_added" : { "count_total" : "Count" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "commerce-order:commerce-line-items" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "CONDITIONAL" : [
                {
                  "IF" : { "entity_has_field" : { "entity" : [ "list-item" ], "field" : "commerce_product" } },
                  "DO" : [
                    { "CONDITIONAL" : [
                        {
                          "IF" : { "entity_is_of_bundle" : {
                              "entity" : [ "list-item:commerce-product" ],
                              "type" : "commerce_product",
                              "bundle" : { "value" : { "moulding" : "moulding" } }
                            }
                          },
                          "DO" : [
                            { "CONDITIONAL" : [
                                {
                                  "IF" : { "data_is" : {
                                      "data" : [ "list-item:commerce-product:field-made-to-order" ],
                                      "value" : "Made To Order usually ships in 2-3 Weeks"
                                    }
                                  },
                                  "DO" : [
                                    { "CONDITIONAL" : [
                                        {
                                          "IF" : { "commerce_price_compare_price" : {
                                              "first_price" : [ "list-item:commerce-total" ],
                                              "operator" : "\u003C",
                                              "second_price" : { "value" : { "amount" : 25000, "currency_code" : "USD" } }
                                            }
                                          },
                                          "DO" : [
                                            { "data_calc" : {
                                                "USING" : { "input_1" : [ "count-total" ], "op" : "+", "input_2" : "1" },
                                                "PROVIDE" : { "result" : { "result" : "Calculation result" } }
                                              }
                                            },
                                            { "data_set" : { "data" : [ "count-total" ], "value" : [ "result" ] } },
                                            { "CONDITIONAL" : [
                                                {
                                                  "IF" : { "commerce_order_contains_product" : {
                                                      "commerce_order" : [ "commerce_order" ],
                                                      "product_id" : "0909990000005",
                                                      "operator" : "\u003E=",
                                                      "value" : "1"
                                                    }
                                                  },
                                                  "DO" : [
                                                    { "component_rules_remove_fee_from_cart" : { "line_item" : [ "list-item" ], "order" : [ "commerce-order" ] } },
                                                    { "drupal_message" : { "message" : "Count prod exists: [count-total:value]" } },
                                                    { "commerce_cart_product_add_by_sku" : {
                                                        "USING" : {
                                                          "user" : [ "site:current-user" ],
                                                          "sku" : "0909990000005",
                                                          "quantity" : [ "count-total" ],
                                                          "combine" : 1
                                                        },
                                                        "PROVIDE" : { "product_add_line_item" : { "product_add_line_item" : "Added product line item" } }
                                                      }
                                                    }
                                                  ]
                                                }
                                              ]
                                            },
                                            { "CONDITIONAL" : [
                                                {
                                                  "IF" : { "NOT commerce_order_contains_product" : {
                                                      "commerce_order" : [ "commerce_order" ],
                                                      "product_id" : "0909990000005",
                                                      "operator" : "\u003E=",
                                                      "value" : "1"
                                                    }
                                                  },
                                                  "DO" : [
                                                    { "commerce_cart_product_add_by_sku" : {
                                                        "USING" : {
                                                          "user" : [ "site:current-user" ],
                                                          "sku" : "0909990000005",
                                                          "quantity" : [ "count-total" ],
                                                          "combine" : 1
                                                        },
                                                        "PROVIDE" : { "product_add_line_item" : { "product_add_line_item" : "Added product line item" } }
                                                      }
                                                    },
                                                    { "drupal_message" : { "message" : "Count Prod nonexistent: [count-total:value]" } }
                                                  ]
                                                }
                                              ]
                                            }
                                          ]
                                        }
                                      ]
                                    }
                                  ]
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

and the component for removing the setup fees

{ "rules_remove_fee_from_cart" : {
    "LABEL" : "Remove Fee From Cart",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "TAGS" : [ "setup Fee" ],
    "REQUIRES" : [ "rules", "inline_conditions" ],
    "USES VARIABLES" : {
      "line_item" : { "label" : "Line Item", "type" : "commerce_line_item" },
      "order" : { "label" : "Order", "type" : "commerce_order" }
    },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "line-item" ], "field" : "commerce_product" } },
      { "commerce_product_contains_products" : { "commerce_line_item" : [ "line-item" ], "sku" : "0909990000005" } }
    ],
    "DO" : [
      { "list_remove" : { "list" : [ "order:commerce-line-items" ], "item" : [ "line-item" ] } }
    ]
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.