1

I have a Commerce site running on D7 that has three shipping services, two product specific flat rate services, than then one service using the Postal Code and Weight Module. The problem I'm running into is how to remove one or the other shipping service so that the customers cannot choose between the services (and then choose the less expensive one!).

At the moment, here are the three rules I have:

Shipping Service 1: contains one product, does not contain the other enter image description here. The logic here is to check if the cart contains the product for the lower cost special shipping, and not the product for the higher cost special shipping.

Shipping Service 2: contains one product. This one just checks if the order contains the product with the higher shipping rate because it's ok if the cart contains the other product, we'll just apply the higher shipping rate.

Shipping Service 3: This should apply the weight based shipping pricing specified in the Postal code and weight module if the card doesn't contain either of the special shipping productsenter image description here. Here I was trying to check the cart for the presence of the two special shipping products, and if they're not included, then apply the rule; but it doesn't seem to working. Both shipping services are placed in the checkout pane and the users are allowed to choose between the services. I want to only apply one service, based on the contents of the cart. What am I missing, and what's the best way to do this?

Update Here are the exports for the rules and their individual component. Essentially, there should be a primary conditional based on the cart contents If cart contains special shipping items: use flat rate; else use weight rate.

: Export of flat rate rule:
    { "commerce_shipping_method_flat_rate" : {
        "LABEL" : "Collect rates: Flat rate",
        "PLUGIN" : "reaction rule",
        "OWNER" : "rules",
        "REQUIRES" : [ "commerce_shipping" ],
        "ON" : { "commerce_shipping_collect_rates" : [] },
        "DO" : [
          { "commerce_shipping_method_collect_rates" : {
              "shipping_method_name" : "flat_rate",
              "commerce_order" : [ "commerce-order" ]
            }
          }
        ]
      }
    }

Export of Weight based rule

{ "commerce_shipping_method_postal_code_weight_shipping_method" : {
    "LABEL" : "Collect rates: Postcode weight shipping method",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "1",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_shipping" ],
    "ON" : { "commerce_shipping_collect_rates" : [] },
    "IF" : [
      { "OR" : [] },
      { "NOT commerce_order_contains_product" : {
          "commerce_order" : [ "commerce_order" ],
          "product_id" : "1100.4.1",
          "operator" : "\u003E=",
          "value" : "1"
        }
      },
      { "NOT commerce_order_contains_product" : {
          "commerce_order" : [ "commerce_order" ],
          "product_id" : "1700.6.1",
          "operator" : "\u003E=",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "commerce_shipping_method_collect_rates" : {
          "shipping_method_name" : "postal_code_weight_shipping_method",
          "commerce_order" : [ "commerce-order" ]
        }
      }
    ]
  }
}

Padfolio Shipping Component:

{ "commerce_shipping_service_padfolio_shipping" : {
    "LABEL" : "Rate Padfolio Shipping",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_shipping" ],
    "USES VARIABLES" : { "commerce_order" : { "type" : "commerce_order", "label" : "Order" } },
    "IF" : [
      { "commerce_order_contains_product" : {
          "commerce_order" : [ "commerce_order" ],
          "product_id" : "1700.6.1",
          "operator" : "\u003E=",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "commerce_shipping_service_rate_order" : {
          "shipping_service_name" : "padfolio_shipping",
          "commerce_order" : [ "commerce-order" ]
        }
      }
    ]
  }
}

Export of License component

{ "commerce_shipping_service_license_plate_holder_shipping_ra" : {
    "LABEL" : "Rate License Plate Holder Shipping Rate",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_shipping" ],
    "USES VARIABLES" : { "commerce_order" : { "type" : "commerce_order", "label" : "Order" } },
    "IF" : [
      { "NOT commerce_order_contains_product" : {
          "commerce_order" : [ "commerce_order" ],
          "product_id" : "1700.6.1",
          "operator" : "\u003E=",
          "value" : "1"
        }
      },
      { "AND" : [] },
      { "commerce_order_contains_product" : {
          "commerce_order" : [ "commerce_order" ],
          "product_id" : "1100.4.1",
          "operator" : "\u003E=",
          "value" : "1"
        }
      }
    ],
    "DO" : [
      { "commerce_shipping_service_rate_order" : {
          "shipping_service_name" : "license_plate_holder_shipping_ra",
          "commerce_order" : [ "commerce-order" ]
        }
      }
    ]
  }
}

Export of Weight based component

{ "commerce_shipping_service_postal_code_weight_shipping_service" : {
    "LABEL" : "Rate Postcode weight shipping service",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_shipping" ],
    "USES VARIABLES" : { "commerce_order" : { "label" : "Order", "type" : "commerce_order" } },
    "IF" : [
      { "OR" : [
          { "NOT commerce_order_contains_product" : {
              "commerce_order" : [ "commerce_order" ],
              "product_id" : "1100.4.1",
              "operator" : "\u003E=",
              "value" : "1"
            }
          },
          { "NOT commerce_order_contains_product" : {
              "commerce_order" : [ "commerce_order" ],
              "product_id" : "1700.6.1",
              "operator" : "\u003E=",
              "value" : "1"
            }
          }
        ]
      }
    ],
    "DO" : [
      { "commerce_shipping_delete_shipping_line_items" : { "commerce_order" : [ "commerce_order" ] } },
      { "commerce_shipping_service_rate_order" : {
          "shipping_service_name" : "postal_code_weight_shipping_service",
          "commerce_order" : [ "commerce-order" ]
        }
      }
    ]
  }
}
0

A possible alternative to trying to "remove" these shipping services, is to combine those rules so that in all scenarios you only have 1 shipping service.

The way to do so, is to rework those rules in a singe rule, in which you take advantage of the Conditional Rules module. By using this module, you can include any relevant conditional logic (and Rules Conditions!) as part of your Rules Actions. So if you do want to consider such rework of your rules, all you need to do is that in all possible scenarios, you will only select the (single) shipping service that applies.

For an example of a rule that uses this module, refer to "Part 2 (within Option 2)" of my answer to this question (which include a rule in Rules export format): How to include only an updated custom field in an email created using Rules?

  • Hi @Pierrre, thanks for the tip, is there any documentation on this or examples to follow? – nizz0k Mar 5 '17 at 11:41
  • @nizz0k : have a look at the example-suggestion I added (at the end of my answer). – Pierre.Vriens Mar 5 '17 at 13:08
  • Thanks Pierre, I will take a close look, looks exactly like what I need ! – nizz0k Mar 5 '17 at 14:20
  • @nizz0k "exactly", really? What else did you expect if I'm asked about the Rules module in D7. BTW, are you familiar with this showstopper (for D8)? – Pierre.Vriens Mar 5 '17 at 14:31
  • Well, I am now! – nizz0k Mar 5 '17 at 14:33
0

So, the answer was a different rules configuration than I had tried.rules config visual. I'm still not sure why this correct, but I got part of the answer from comments on my first question and part of the answer from the #drupal-commerce IRC which tipped me off to using the rules debugger on the pages rather than checking in the log (which is super tedious).

Here is the export if anyone wants to see it:

{ "commerce_shipping_service_postal_code_weight_shipping_service" : {
    "LABEL" : "Rate Postcode weight shipping service",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_order", "commerce_shipping" ],
    "USES VARIABLES" : { "commerce_order" : { "label" : "Order", "type" : "commerce_order" } },
    "IF" : [
      { "NOT commerce_order_contains_product" : {
          "commerce_order" : [ "commerce_order" ],
          "product_id" : "1100.4.1",
          "operator" : "\u003E=",
          "value" : "1"
        }
      },
      { "OR" : [
          { "AND" : [
              { "NOT commerce_order_contains_product" : {
                  "commerce_order" : [ "commerce_order" ],
                  "product_id" : "1700.6.1",
                  "operator" : "\u003E=",
                  "value" : "1"
                }
              }
            ]
          }
        ]
      }
    ],
    "DO" : [
      { "commerce_shipping_service_rate_order" : {
          "shipping_service_name" : "postal_code_weight_shipping_service",
          "commerce_order" : [ "commerce-order" ]
        }
      }
    ]
  }
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.