is it possible to calculate shipping costs taking only in consideration the total of the products of a certain type of product?

thanks!

Comments

facine’s picture

Would that be correct? Or is there a better alternative?

Thanks

      { "OR" : [
          { "AND" : [
              { "data_is" : {
                  "data" : [ "commerce-order:commerce-line-items:0:type" ],
                  "value" : "product"
                }
              },
              { "data_is" : {
                  "data" : [ "commerce-order:commerce-line-items:0:commerce-total:amount" ],
                  "op" : "\u003E",
                  "value" : "30000"
                }
              }
            ]
          },
          { "AND" : [
              { "data_is" : {
                  "data" : [ "commerce-order:commerce-line-items:1:type" ],
                  "value" : "product"
                }
              },
              { "data_is" : {
                  "data" : [ "commerce-order:commerce-line-items:1:commerce-total:amount" ],
                  "op" : "\u003E",
                  "value" : "30000"
                }
              }
            ]
          },
          { "AND" : [
              { "data_is" : {
                  "data" : [ "commerce-order:commerce-line-items:2:type" ],
                  "value" : "product"
                }
              },
              { "data_is" : {
                  "data" : [ "commerce-order:commerce-line-items:2:commerce-total:amount" ],
                  "op" : "\u003E",
                  "value" : "30000"
                }
              }
            ]
          },
          { "AND" : [
              { "data_is" : {
                  "data" : [ "commerce-order:commerce-line-items:3:type" ],
                  "value" : "product"
                }
              },
              { "data_is" : {
                  "data" : [ "commerce-order:commerce-line-items:3:commerce-total:amount" ],
                  "op" : "\u003E",
                  "value" : "30000"
                }
              }
            ]
          }
        ]
      }
mortona2k’s picture

Hey, I'm new to commerce/shipping/flat rate. Where do you put this code? I just want to start by adding the flat rate for every 10 items in the cart.

rszrama’s picture

Status: Active » Closed (won't fix)

What you're doing in this example is looking at the line item type, which is different from the product type. There is a core Drupal Commerce condition called "Total product quantity comparison" that can compare against the total of all products in the cart, but it doesn't differentiate by product type. You could loop over the line items and tally up the total of all products of a particular type, but it would get cumbersome. Best to write a custom integration instead of trying to build it solely through the Rules interface.