1
Answers
Vote up!
0
Vote down!

Can customizable products work out price based on the number of uploaded files?

Hi, I would like to develop an online photo printing service like shutterfly.com and snapfish.com. I would like to find out if it's possible using customizable products to count each uploaded file/photo and charge accordingly? If not, what other way can I achieve this requirement?

Thanks for any help

on September 17, 2014

1 Answer

Vote up!
1
Vote down!

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]" } }
    ]
  }
}
Josh Miller
Answer by: Josh Miller
Posted: Sep 18, 2014

Comments