I'm not sure if this is a Commerce Flat Rate issue, Commerce Shipping 2.x issue, or Rules issue but I'll start here and give it a try. I followed Randy Fay's excellent tutorials on the Commerce Guys website to set up three flat rate shipping options (first class, priority, and express) and an upcharge to flat rate per item which is only supposed to add on to the first class option. Here's the scenario...

The client whose site I am working on has three domestic shipping options.
1) First Class ($4 for first item, +$1 for each additional item)
2) Priority $7
3) Express $25

Each of these three is set up as a Flat Rate Service and titled appropriately. For the First Class I set the base amount to $3 since the add was going to count the first item and add $1 which brings the amount for the first item to the $4 amount.

I followed the tutorial video to create a plus $1 and in the final action (Add an amount to the unit price) specified the First Class item as the Price Component Type. But, it appears that the shipping rate calculation rule I created is actually applying the add +$1 to all three Flat Rate Services (First Class, Priority, and Express) even though I specified in the Price Component Type to apply the calculation to the First Class one.

So, with two items in my cart, at checkout the shipping choices are showing as:

First Class $5 (correct)
Priority $9 (not correct - added $1 for each item to the base $7)
Express $27 (not correct - added $1 for each item to the base $25)

From the video tutorial on adding per-item shipping, the last step in setting up the rule is to affect the Product Component Type. I see all of my unique flat rate service options listed there and only selected the one I wanted the upcharge to apply to, however it appears to be increasing all three of the available flat rate service options presented to customers.

Any guidance extremely appreciated! I need to remove the extra amounts being added to the Priority and Express shipping options so we can move forward with the client's site.

Members fund testing for the Drupal project. Drupal Association Learn more


craigkendall’s picture

see below...

craigkendall’s picture

Title: Add per item amount effects all shipping choices » Add per item amount effects all shipping choices - Rule
1.07 KB

Attached via text is the rule

rfay’s picture

If you can boil this down to a simpler situation (just one shipping rate?) and edit the issue summary (just edit the node) to make it as simple as you can, I'll try to take a look at it.

The debugging process means trying to simplify things as much as possible to make it so you understand exactly what's going on and so you can explain it concisely to others.


craigkendall’s picture

So here is the simplest explanation I can give and I'm changing this to a bug report based on my observation of how I believe the shipping calculation rule component type selector is supposed to work.

If you have more than one Flat Rate Service created and attempt to apply a shipping calculation rule to just one of those services, the Component Type selector (see image) when defining an action doesn't seem to work.

I'll include a series of screenshots so the whole thing is hopefully laid out.

As indicated above, when items are placed in the cart and during checkout, when choosing the shipping method, the first class method is correct, but the $1 per item additional cost from the rule, which is supposed to only be applied to the one Component Type (see screenshot six "As just my First Class Flat Rate item) is actually applied to all of the Flat Rate Services I have created (and that are listed in the Component Type pull down, though I only indicated the one when creating the rule).

I hope that specific and simple enough.

In response to Randy Fay's suggestion on IRC I tried to create a condition so that the rule only applies to my one flat rate service component type, but I don't really see how to specify it when adding a condition to the shipping calculation method.

rfay’s picture

Category: bug » support
Priority: Major » Normal

Still more than I can grok. This will have to be a support request until it's boiled down to a clear statement of something wrong with Commerce Flat Rate instead of something wrong with your application.

As far as I can tell, you don't yet have a condition that limits your rule to acting in the single situation you want it to act in. If you're not familiar with rules components (like subroutines) you may need one of them, with a condition and an action in it, to accomplish some things (especially when something inside a loop needs to have a condition attached to it.)

craigkendall’s picture

Thanks for the feedback, can you point me to the best resources to learn rules in your opinion?

rfay’s picture

Sorry, thought I already had. Itangalo's Learn the Rules Framework is the very best. Then the CommerceGuys channel on Vimeo, which you're already familiar with, provides lots of practical examples.

rfay’s picture

OK, I took a careful look at your work, and it is in fact just a couple of conditions you need. In your shipping "calculation rule", you need conditions that tell it when to fire.

In my case, I made a flat rate type called "Charge Per Item" and added a calculation rule just as in the per-item shipping video, but that rule has to have a couple of conditions added to make sure that it only applies to the correct type of shipping.

FIrst, we do a Data Comparison to check to see if the line item is a shipping line item type.

Then we do a data comparison to make sure that the line item's shipping service is "Charge Per item"

After that, the calculation rule only applies to the service it's supposed to apply to.

When this works out for you, please return to all the places you've posted this and update the actual answer. Thanks!

craigkendall’s picture

Holy Crap! That works... but WOW... I feel like I'm playing twister to figure that out.

Thanks SO much for the guidance... no to dissect it and figure out exactly WHY it works. WOW!

(I can't repeat the words I was yelling at my computer as I tried adding single conditions to get at that... I got pieces of it but never put those two together)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dave-at-sherpa’s picture

This post was extremely helpful for me, so I thought I would expand on it a bit to share how I was able to resolve an issue that this method created on my site. Just as in the original post, I wanted to offer two rates, standard and express. Standard is $4 for the first item, and $1 for each additional; Express is $10 for the first, $2 add'l. I also have bulk quantity discount rules in place: buy 10 or more, save 5%; but 20 or more, save 10%; etc. AND I allow the use of coupons on top of the bulk discounts.

The problem with the method offered here is that it tallies ALL of the line items in an order, which includes the discounts and coupons. So an express order for 12 items should have been $32 shipping. Instead, it counted the bulk discount (save 5% on 10 or more) and the coupon (save an additional 10%) as two more items in my cart, for a total of 14 items at $36.

To get around this, I installed Conditional Rules. Then I placed the two actions in the loop (Calculate a Value and Add an Amount to the Unit Price) beneath a conditional (if) statement that first checked to make sure the line items were of the type "product" before including them in the tally (Data Comparison of list-item:type to Products).

jaclayton’s picture

Absolute Godsend. Between the video here https://commerceguys.com/blog/using-calculation-rules-add-item-shipping-... and this post, I've now got shipping almost exactly where I want it.

Thank you all.

kentjames1980’s picture

Status: Closed (fixed) » Active

dave-at-sherpa in #11

Could you possible post the exported rule for me to take a look at please?

I am having trouble getting this to work how you have stated and I'm sure i am going 'rule blind'!

Thanks in advance

BeatnikDude’s picture

#8 was the key I needed.

I have created ​multiple Flat rate Shipping Services​ that set base fee and have User, Country and Role conditions as to wether they apply.
I use additional Calculation Rules to add per item fees to only some shipping line items with conditions as per #8 to limit the additions to the correct shipping line items.