When a paypernode order goes through it grants a certain number of allowed nodes. However if I cancel the order the nodes are still allowed to be created. This would be helpful so I don't have to manually edit the nodes on an order cancellation. (using with ubercart)

Comments

maurizio.ganovelli’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Assigned: Unassigned » maurizio.ganovelli
Category: bug » feature
Status: Active » Fixed

I think that this can be done using rules (7.x) or conditional action (6.x).
For D7 you can use the rule below (you can import the code from admin/config/workflow/rules/reaction/import):

{ "rules_update_the_user_pay_per_node_balance_when_order_is_cancell" : {
    "LABEL" : "Update the user pay-per-node balance when order is cancelled.",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "uc_order", "php", "rules" ],
    "ON" : [ "uc_order_status_update" ],
    "IF" : [
      { "uc_order_condition_order_state" : { "order" : [ "order" ], "order_state" : "completed" } },
      { "AND" : [] },
      { "uc_order_condition_order_state" : { "order" : [ "updated-order" ], "order_state" : "canceled" } }
    ],
    "DO" : [
      { "php_eval" : { "code" : "  \/\/ Loop through all the products on the order.\r\n  foreach ($updated_order-\u003Eproducts as $product) {\r\n    \/\/ Look for any paypernode features assigned to the product.\r\n    $query = db_query(\u0022SELECT * FROM {uc_paypernode_products} WHERE nid = :nid\u0022, array(\u0027:nid\u0027 =\u003E $product-\u003Enid));\r\n    while ($paypernode = $query-\u003EfetchObject()) {\r\n      $creation_qty = $product-\u003Eqty * $paypernode-\u003Eqty;\r\n      paypernode_update_user_balance($updated_order-\u003Euid, $paypernode-\u003Etype,-$creation_qty);\r\n      $comment = t(\u0027Removed from pay per node balance %qty of type %type.\u0027, array(\u0027%qty\u0027 =\u003E $creation_qty, \u0027%type\u0027 =\u003E $paypernode-\u003Etype));\r\n      uc_order_comment_save($updated_order-\u003Eorder_id, $updated_order-\u003Euid, $comment);\r\n    }\r\n  }" } }
    ]
  }
}

This rule removes from user's balance all nodes charged by ppn, when order status change from "Completed" to "Cancelled" status. "PHP filter" core module must be enabled.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.