summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjucallme2012-10-26 10:38:02 (GMT)
committer Pedro Cambra2012-10-26 10:38:02 (GMT)
commit46485e248090f59bde6f79fd82f530baf797e58d (patch)
tree0f403664df33b9f67e6399cd243bcb93e595c61d
parent25d18499e216d0482b696141adb141097fef6aed (diff)
Issue #1538158 by jucallme, idflood: Added Limit number of coupons applied to the order.
-rw-r--r--commerce_coupon.module33
-rw-r--r--commerce_coupon.rules.inc18
2 files changed, 51 insertions, 0 deletions
diff --git a/commerce_coupon.module b/commerce_coupon.module
index 9f9050d..5adb5f8 100644
--- a/commerce_coupon.module
+++ b/commerce_coupon.module
@@ -1071,3 +1071,36 @@ function commerce_coupon_commerce_cart_order_refresh($order_wrapper) {
}
}
}
+
+/**
+ * Returns the number of uses for this coupon.
+ *
+ * @param $coupon_id
+ * Coupon id to check.
+ *
+ * @return integer
+ * Returns number of uses of the coupon in all orders.
+ */
+function commerce_coupon_get_coupons_in_order($order_id) {
+ $order_wrapper = entity_metadata_wrapper('commerce_order', $order_id);
+ $coupons = array();
+ foreach ($order_wrapper->commerce_coupon_order_reference as $coupon_wrapper) {
+ if ($coupon_wrapper->value()->is_active == 1) {
+ $coupons[] = $coupon_wrapper->value();
+ }
+ }
+ return $coupons;
+}
+
+/**
+ * Returns a list of coupons that have been attached to the order.
+ *
+ * @param $commerce_order
+ * The order which is to be checked.
+ */
+function commerce_coupon_action_get_coupons_for_order($commerce_order) {
+ if (!$commerce_order) {
+ return array();
+ }
+ return array('order_coupons' => commerce_coupon_get_coupons_in_order($commerce_order->order_id));
+}
diff --git a/commerce_coupon.rules.inc b/commerce_coupon.rules.inc
index 7d7cd65..579a54a 100644
--- a/commerce_coupon.rules.inc
+++ b/commerce_coupon.rules.inc
@@ -117,6 +117,24 @@ function commerce_coupon_rules_action_info() {
),
);
+ $actions['commerce_coupon_action_get_coupons_for_order'] = array(
+ 'label' => t('Get coupons for order'),
+ 'parameter' => array(
+ 'commerce_order' => array(
+ 'type' => 'commerce_order',
+ 'label' => t('Commerce order'),
+ ),
+ ),
+ 'provides' => array(
+ 'order_coupons' => array(
+ 'type' => 'list<commerce_coupon>',
+ 'label' => t('Coupons attached to this order'),
+ ),
+ ),
+ 'group' => t('Commerce Coupon'),
+ 'base' => 'commerce_coupon_action_get_coupons_for_order',
+ );
+
$actions['commerce_coupon_action_get_coupon_uses'] = array(
'label' => t('Get the redemption number of a coupon'),
'parameter' => array(