3

I'm doing a favor for a family member by helping set up their store. I've never worked with Drupal before.

They are selling one item, but they want the shipping cost per item to change based on the number of items purchased.

  • 1 item - $3.50 shipping
  • 2 to 9 items - $2.75 shipping PER ITEM
  • more than 10 items - $2.00 shipping PER ITEM

After a few hours of research I half-understand the rules system, but I can't figure out how to combine rules like this. Can anyone point me in the right direction?

2

Pontus Nilsson has the right idea, just shared it as a comment instead of an answer?

I decided this was a good teachable moment (this also turned out to be a head scratcher at more than one turn), so below is the screencast of how to do this and a step-by-step:

https://www.youtube.com/watch?v=trLydGpimD4

STEP BY STEP

  1. Install https://www.drupal.org/project/commerce_shipping and https://www.drupal.org/project/commerce_flat_rate

  2. Create three different flat rates (I recommend you keep the "Title" different, but change the "Display Title" to be the same, so the rate change is transparent to the user)

  3. Configure each flat rate component to have a condition on "Total product quantity comparison" so that only the appropriate rates show up based on number of products. Note this will only work if you use the standard line item type "Product" ... if you have custom line item types, you will have to create a component that does the comparison/counting that you need.

  4. In order to count the number of eligible products, we will need to create a component rule that has a "line item" parameter and has an "number decimal" provided called "is_a_product".

This component simply needs to have a condition on entity bundle for "Product" and needs an action that "sets a data value" ... the is_a_product ... to the line-item:quantity.

  1. Next, we will need to create a pricing rule for your first "Medium" level shipping price calculation.

    A. Once you discover where to create the shipping price calculation rule you will need to create two conditions:

    • Entity has field (it should have the shipping service field)
    • Data Comparison (the shipping service field should equal the medium shipping service)

    B. Now you will need to count the number of products. Let's add an action "create a variable" for an number decimal called "num_products"

    C. Next you will need to loop over all the line items in the order.

    D. Next you will add an action for the component you created in step 4.

    E. Then you will need to "Calculate a value" by adding the "num_products" and the "is_a_product" (through some testing I confirmed the integer is zero by default) and then save the result by "setting a data value" and setting "num_products" to the result value

    F. Finally, you will need to "Multiply the unit price by some amount" and select the num_products as the multiplier

  2. Repeat step 5 for each breakdown of product quantity rate change

| improve this answer | |
  • Thanks! That's basically what I figured out, but I'm glad I inspired a video tutorial! – dreadpiratebrown Sep 20 '14 at 20:37

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.