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.
Comment | File | Size | Author |
---|---|---|---|
#8 | shipping_rule_per_line_item.txt | 1.24 KB | rfay |
#8 | rule_adding_dollar_per_item.png | 105.57 KB | rfay |
#8 | rfay_mac_airbook_screenshot 2012-01-26 at 5.23.02 PM.png | 56.33 KB | rfay |
#4 | Screen shot 2012-01-25 at 12.36.50 PM.png | 66.6 KB | craigkendall |
#4 | Screen shot 2012-01-25 at 12.36.36 PM.png | 101.84 KB | craigkendall |
Comments
Comment #1
craigkendall CreditAttribution: craigkendall commentedsee below...
Comment #2
craigkendall CreditAttribution: craigkendall commentedAttached via text is the rule
Comment #3
rfayIf 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.
Thanks!
Comment #4
craigkendall CreditAttribution: craigkendall commentedSo 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.
Comment #5
rfayStill 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.)
Comment #6
craigkendall CreditAttribution: craigkendall commentedThanks for the feedback, can you point me to the best resources to learn rules in your opinion?
Comment #7
rfaySorry, 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.
Comment #8
rfayOK, 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!
Comment #9
craigkendall CreditAttribution: craigkendall commentedHoly 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)
Comment #11
dave-at-sherpa CreditAttribution: dave-at-sherpa commentedThis 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).
Comment #12
jaclayton CreditAttribution: jaclayton commentedAbsolute 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.
Comment #13
kentjames1980 CreditAttribution: kentjames1980 commenteddave-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
Comment #14
BeatnikDude CreditAttribution: BeatnikDude as a volunteer commented#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.
Comment #15
jrochate CreditAttribution: jrochate at ADJ 3 Sistemas commentedI would to post a solution to a problem I was having when following the suggestions on this post.
On the step of #8
, the select box was empty, although I had several shipping services correctly configured.
That means I could not have the second Data Comparison rule:
The value was not available on Rules interface, and even if I hand built the rule and imported, it would not be validated.
So, after some time debuggin I came to the conclusion that was Field Translation module that had problems, under i18n suite.
To make everything work, I had to patch Field Module with:
https://www.drupal.org/project/i18n/issues/1829050#comment-12289963
I hope this can help someone in the future.
Comment #16
aliweng CreditAttribution: aliweng commentedHi there and sorry for bringing this issue up after such a long time. I am trying to figure a way to apply the solution of step #8.
However when i select "data to compare" the selector "commerce-line-iltem:commerce-shipping-service" is not an available option.
I get the error message >
"Data selector commerce-line-item:commerce-shipping-service for parameter data is invalid."
Any ideas?
Comment #17
JOoxis CreditAttribution: JOoxis commentedHi @aliweng,
Check the link provided by @jrochate. Once the patch applied you shouldn't have any problems.