Sure you can! I created this rule that looks at line items with a field called "upload all the files" that multiplies the price per file ... you change that for a particular fixed fee or some other way of determining prices (maybe a pdf module out there could tell you how many pages were in it?)
{ "rules_files_price_multiplier" : {
"LABEL" : "Files Price Multiplier",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference" ],
"ON" : { "commerce_product_calculate_sell_price" : [] },
"IF" : [
{ "entity_is_of_type" : { "entity" : [ "commerce-line-item" ], "type" : "commerce_line_item" } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item" ],
"field" : "field_upload_all_the_files"
}
},
{ "list_count_is" : {
"list" : [ "commerce-line-item:field-upload-all-the-files" ],
"op" : "\u003E",
"value" : "0"
}
}
],
"DO" : [
{ "variable_add" : {
"USING" : { "type" : "integer", "value" : "1" },
"PROVIDE" : { "variable_added" : { "file_multiplier" : "file_multiplier" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "commerce-line-item:field-upload-all-the-files" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "data_calc" : {
"USING" : { "input_1" : [ "file-multiplier" ], "op" : "+", "input_2" : "1" },
"PROVIDE" : { "result" : { "result" : "Calculation result" } }
}
},
{ "data_set" : { "data" : [ "file-multiplier" ], "value" : [ "result" ] } }
]
}
},
{ "commerce_line_item_unit_price_multiply" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : [ "file-multiplier" ],
"component_name" : "fee",
"round_mode" : "1"
}
},
{ "drupal_message" : { "message" : "[commerce-line-item:line-item-id]: File Multiplier = [file-multiplier:value]" } }
]
}
}
Comments
Thanks Josh, I'm gonna try this.