Closed (fixed)
Project:
Commerce Flat Rate
Version:
7.x-1.0-beta1
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
24 May 2012 at 08:29 UTC
Updated:
18 Jul 2014 at 20:24 UTC
Jump to comment: Most recent
Comments
Comment #1
simon georges commentedClosing #1598076: Different shipping services with one calculation rule? as a duplicate of this one.
Comment #2
simon georges commentedClosing #1596476: Help with shipping services rules as a duplicate of this one.
Comment #3
NickWebman commentedwould love to know as well.
Comment #4
johnnynia commentedAnyone figured out how to do this in the meantime?
Comment #5
rszrama commentedYou would simply create two flat rate shipping services and then add two rate calculation rules to handle the additions. The base price would be $10 / $15 respectively, and what you'd want is a condition that checked the value of the commerce-line-item:commerce-shipping-service field to make sure you were incrementing the price the appropriate amount based on the service being calculated for. (Make sure you use "Entity has field" on the commerce-line-item to ensure the commerce-shipping-service field is there first.)
Now, once you make sure you have the right shipping line item type for the increment value (i.e. $4 vs. $6), you're going to have to use Rules' "Calculate a data value" action to prepare the amount you're going to increment the unit price amount by. Remember that prices are calculated in cents, so what you'd want to do is multiply the total quantity of all products by 400 or 600 respectively. The challenge is getting ahold of the total product quantity - there's a condition that can check it, but there is no simple token that you can use to calculate it.
What I would do is loop over the commerce-line-item:order:commerce-line-items, check to make sure it's a product line item, and then increment the shipping amount that number * the quantity of each line item. Unfortunately, because this means we need a condition in the actions section (where the loop is), we need to pass each line item in the list to a Rules component to perform the actual calculation.
Here's an exported example that you can see; you just first need to create a flat rate service called "Standard shipping" with a machine-name of standard_shipping to make sure the tokens all line up. Let's assume it's the $10 + $4 / per. example.
Import this Rules component first:
Then import this Rule:
One caveat - this works as advertised, but I'm seeing a Rules warning that looks to me like a bug in Rules itself. I'm running Rules 7.x-2.2, and the code for the notice looks pretty innocuous to me, so I posted a patch here that folks can use until Rules is fixed: #1843174-1: Calculating a data value results in an illegal offset warning
Comment #6
rszrama commentedComment #8
mrP commentedIs this still valid for commerce_shipping 2.x? I tried running through this example and couldn't get it working.
Comment #9
mrP commentedNever mind, just ran across Randy's video on the topic -- Using Calculation Rules to Add Per-Item Shipping in Commerce Shipping