Discussions

Flat Shipping Per Product

I've been looking at this for a couple of hours, have come across a lot of similar topics, but nothing specifically matching, and that leaves me stuck on one point. Here's what I'm trying to accomplish. There's the base flat shipping price, and then each product has a "flat shipping" field where I can enter an additional shipping price for that item. I can't just roll shipping prices into product prices because local pickup is configured using the free shipping service and has to remain available.

I've tried setting up a rule to add that value to the shipping cost, but simply can't get any conditions or actions to access that field. I've tried entity has field on commerce-order:commerce-line-items:0 / field_flat_shipping, which I've seen suggested in a few places, but this doesn't add any new data selectors to my actions. In fact, I'm not entirely sure which action to use - right now I'm just experimenting with add a rate to a shipping service for an order, but I don't know if that's correct.

Anyone have any suggestions?

Posted: May 1, 2013

Comments

maciej.zgadzaj on May 2, 2013

Starting from commerce_line_item, conditions like this should do the trick for you:

"IF" : [
  { "entity_has_field" : {
    "entity" : [ "commerce-line-item" ],
      "field" : "commerce_product"
    }
  },
  { "entity_has_field" : {
    "entity" : [ "commerce-line-item:commerce-product" ],
      "field" : "field_flat_shipping"
    }
  }
],

If you starting from commerce_order, you might want to add a loop on all commerce_order:commerce_line_items and put the rest in a component.

AshleyByrom on September 23, 2013

Hi,

I am trying to use your method to add a shipping cost per product to the order.

I have created a calculation rule for the event "Calculating a shipping rate". In this I loop through site:current-cart-order:commerce-line-items and have a component rule that checks each item is a product with the correct flat rate field. Then I calculate quantity * field_flat_shipping (in the component rule) to get a price to add.

How do I then add that price to the order shipping? In my component rule I can't affect the shipping line item (only the product line item) and in my calculation rule I can't work out how to get the value out of the component rule.

I hope this makes sense.

Thanks,
Ashley