Advertisement
MrJoshMiller

Order Discount via Line Item Subtraction

Dec 26th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.50 KB | None | 0 0
  1. { "rules__5_off_orders_over_90" : {
  2.     "LABEL" : "$5 off Orders over $90",
  3.     "PLUGIN" : "reaction rule",
  4.     "REQUIRES" : [
  5.       "commerce_payment",
  6.       "rules",
  7.       "commerce_line_item",
  8.       "commerce_product_reference"
  9.     ],
  10.     "ON" : [ "commerce_product_calculate_sell_price" ],
  11.     "IF" : [
  12.       { "commerce_payment_order_balance_comparison" : {
  13.           "commerce_order" : [ "site:current-cart-order" ],
  14.           "operator" : "\u003E=",
  15.           "value" : "9000"
  16.         }
  17.       }
  18.     ],
  19.     "DO" : [
  20.       { "variable_add" : {
  21.           "USING" : { "type" : "integer", "value" : "0" },
  22.           "PROVIDE" : { "variable_added" : { "numproducts" : "Number of Products" } }
  23.         }
  24.       },
  25.       { "LOOP" : {
  26.           "USING" : { "list" : [ "site:current-cart-order:commerce-line-items" ] },
  27.           "ITEM" : { "list_item" : "Current list item" },
  28.           "DO" : [
  29.             { "data_calc" : {
  30.                 "USING" : {
  31.                   "input_1" : [ "numproducts" ],
  32.                   "op" : "+",
  33.                   "input_2" : [ "list-item:quantity" ]
  34.                 },
  35.                 "PROVIDE" : { "result" : { "result" : "Calculation result" } }
  36.               }
  37.             },
  38.             { "data_convert" : {
  39.                 "USING" : { "type" : "integer", "value" : [ "result" ] },
  40.                 "PROVIDE" : { "conversion_result" : { "conversion_result" : "Conversion result" } }
  41.               }
  42.             },
  43.             { "data_set" : { "data" : [ "numproducts" ], "value" : [ "conversion-result" ] } }
  44.           ]
  45.         }
  46.       },
  47.       { "variable_add" : {
  48.           "USING" : { "type" : "integer", "value" : "5" },
  49.           "PROVIDE" : { "variable_added" : { "discounttotal" : "Total Discount" } }
  50.         }
  51.       },
  52.       { "data_calc" : {
  53.           "USING" : {
  54.             "input_1" : [ "discounttotal" ],
  55.             "op" : "\/",
  56.             "input_2" : [ "numproducts" ]
  57.           },
  58.           "PROVIDE" : { "result" : { "result" : "Single discount Line Item" } }
  59.         }
  60.       },
  61.       { "data_calc" : {
  62.           "USING" : { "input_1" : [ "result" ], "op" : "*", "input_2" : "100" },
  63.           "PROVIDE" : { "result" : { "curreny_safe" : "curreny_safe" } }
  64.         }
  65.       },
  66.       { "commerce_line_item_unit_price_subtract" : {
  67.           "commerce_line_item" : [ "commerce_line_item" ],
  68.           "amount" : [ "curreny-safe" ],
  69.           "component_name" : "discount",
  70.           "round_mode" : "1"
  71.         }
  72.       }
  73.     ]
  74.   }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement