summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPedro Cambra2012-09-07 08:57:08 (GMT)
committer Pedro Cambra2012-09-07 08:57:08 (GMT)
commitc888ae0ad474347520b62db7a7a6b868b051e809 (patch)
treea11cca312d59642744d1a9e288cdbe5e1449efff
parentfccf3ca05d6a9d4058040bdd26bc8d756b1fa187 (diff)
Removed files from deprecated master branch.
-rw-r--r--README.txt1
-rw-r--r--classes/commerce_coupon.inc15
-rw-r--r--classes/commerce_coupon_log.inc19
-rw-r--r--classes/commerce_coupon_type.inc24
-rw-r--r--classes/commerce_coupons_metadata_controller.inc4
-rw-r--r--commerce_coupon.admin.inc164
-rw-r--r--commerce_coupon.info13
-rw-r--r--commerce_coupon.install197
-rw-r--r--commerce_coupon.module765
-rw-r--r--commerce_coupon.rules.inc178
-rw-r--r--commerce_coupon.rules_defaults.inc69
-rw-r--r--includes/commerce_coupon.checkout_pane.inc43
-rw-r--r--modules/batch/commerce_coupon_batch.info9
-rw-r--r--modules/batch/commerce_coupon_batch.module79
-rw-r--r--modules/batch/includes/commerce_coupon_batch.form.inc92
15 files changed, 1 insertions, 1671 deletions
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..9ddedd2
--- /dev/null
+++ b/README.txt
@@ -0,0 +1 @@
+See major version branches.
diff --git a/classes/commerce_coupon.inc b/classes/commerce_coupon.inc
deleted file mode 100644
index 353c5fb..0000000
--- a/classes/commerce_coupon.inc
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-class CommerceCoupon extends Entity {
-
- public $amount;
- public $code;
- public $is_percentage;
- public $is_active = true;
- public $type;
-
- public function __construct($values = array()) {
- parent::__construct($values, 'commerce_coupon');
- }
-}
-
diff --git a/classes/commerce_coupon_log.inc b/classes/commerce_coupon_log.inc
deleted file mode 100644
index 0fd465b..0000000
--- a/classes/commerce_coupon_log.inc
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-
-class CommerceCouponLog extends Entity {
-
- public $log_id;
- public $coupon_id;
- public $uid;
- public $order_id;
- public $is_accepted;
- public $is_processed;
- public $created;
- public $changed;
-
-
- public function __construct($values = array()) {
- parent::__construct($values, 'commerce_coupon_log');
- }
-}
-
diff --git a/classes/commerce_coupon_type.inc b/classes/commerce_coupon_type.inc
deleted file mode 100644
index d30787d..0000000
--- a/classes/commerce_coupon_type.inc
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-
-
-
-class CommerceCouponType extends Entity {
-
- public $type;
- public $label;
- public $weight = 0;
-
- public function __construct($values = array()) {
- parent::__construct($values, 'commerce_coupon_type');
- }
-
- /**
- * Returns whether the profile type is locked, thus may not be deleted or renamed.
- *
- * Profile types provided in code are automatically treated as locked, as well
- * as any fixed profile type.
- */
- public function isLocked() {
- return isset($this->status) && empty($this->is_new) && (($this->status & ENTITY_IN_CODE) || ($this->status & ENTITY_FIXED));
- }
-}
diff --git a/classes/commerce_coupons_metadata_controller.inc b/classes/commerce_coupons_metadata_controller.inc
deleted file mode 100644
index 80f01c4..0000000
--- a/classes/commerce_coupons_metadata_controller.inc
+++ /dev/null
@@ -1,4 +0,0 @@
-<?php
-
-
-//class CommerceCouponsMetadataController extends
diff --git a/commerce_coupon.admin.inc b/commerce_coupon.admin.inc
deleted file mode 100644
index 6e85ed7..0000000
--- a/commerce_coupon.admin.inc
+++ /dev/null
@@ -1,164 +0,0 @@
-<?php
-
-/**
- * @file
- * Commerce Coupon type editing UI.
- */
-
-/**
- * Generates the commerce coupon type editing form.
- */
-function commerce_coupon_type_form($form, &$form_state, $coupon_type, $op = 'edit') {
-
- if ($op == 'clone') {
- $coupon_type->label .= ' (cloned)';
- $coupon_type->type = '';
- }
-
- $form['label'] = array(
- '#title' => t('Label'),
- '#type' => 'textfield',
- '#default_value' => $coupon_type->label,
- '#description' => t('The human-readable name of this coupon type.'),
- '#required' => TRUE,
- '#size' => 30,
- );
-
- // Machine-readable type name.
- $form['type'] = array(
- '#type' => 'machine_name',
- '#default_value' => isset($coupon_type->type) ? $coupon_type->type : '',
- '#maxlength' => 32,
- '#disabled' => $coupon_type->isLocked() && $op != 'clone',
- '#machine_name' => array(
- 'exists' => 'commerce_coupon_get_types',
- 'source' => array('label'),
- ),
- '#description' => t('A unique machine-readable name for this coupon type. It must only contain lowercase letters, numbers, and underscores.'),
- );
-
- $form['data']['#tree'] = TRUE;
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save coupon type'),
- '#weight' => 40,
- );
-
- if (!$coupon_type->isLocked() && $op != 'add') {
- $form['actions']['delete'] = array(
- '#type' => 'submit',
- '#value' => t('Delete coupon type'),
- '#weight' => 45,
- '#limit_validation_errors' => array(),
- '#submit' => array('commerce_coupon_type_form_submit_delete')
- );
- }
- return $form;
-}
-
-/**
- * Form API submit callback for the type form.
- */
-function commerce_coupon_type_form_submit(&$form, &$form_state) {
- $commerce_coupon_type = entity_ui_form_submit_build_entity($form, $form_state);
- // Save and go back.
- $commerce_coupon_type->save();
- $form_state['redirect'] = 'admin/commerce/coupons/types';
-}
-
-/**
- * Form API submit callback for the delete button.
- */
-function commerce_coupon_type_form_submit_delete(&$form, &$form_state) {
- $form_state['redirect'] = 'admin/commerce/coupons/types/manage/' . $form_state['commerce_coupon_type']->type . '/delete';
-}
-
-
-
-
-/**
- * Generates the commerce coupon editing form.
- */
-function commerce_coupon_form($form, &$form_state, $coupon, $op = 'edit') {
-
- if ($op == 'clone') {
- $coupon_type->label .= ' (cloned)';
- $coupon_type->type = '';
- }
-
- $form['amount'] = array(
- '#title' => t('Amount'),
- '#type' => 'textfield',
- '#default_value' => $coupon->amount,
- '#description' => t('The amount of the coupon.'),
- '#required' => TRUE,
- '#size' => 30,
- );
-
- $form['is_percentage'] = array(
- '#title' => t('Percentage'),
- '#type' => 'checkbox',
- '#default_value' => $coupon->is_percentage,
- '#description' => t('Indicates if the amount is a percentage of the order or a fixed amount.'),
- );
-
- $form['code'] = array(
- '#title' => t('Coupon Code'),
- '#type' => 'textfield',
- '#default_value' => $coupon->code,
- '#description' => t('Enter here the code of the coupon. When the customer enter this code, he get the reduction indicated by the amount. Leave it empty to auto generate a code.'),
- '#size' => 30,
- );
- // TODO: add a validation method to check, that the code is not a duplicate!
-
- $form['is_active'] = array(
- '#title' => t('Active'),
- '#type' => 'checkbox',
- '#default_value' => $coupon->is_active,
- '#description' => t('Indicates if the coupon can be used or not.'),
- '#size' => 30,
- );
-
- // Add the field related form elements.
- $form_state['commerce_coupon'] = $coupon;
- field_attach_form('commerce_coupon', $coupon, $form, $form_state);
-
- $form['data']['#tree'] = TRUE;
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save coupon'),
- '#weight' => 40,
- );
-
- if ($op != 'add') {
- $form['actions']['delete'] = array(
- '#type' => 'submit',
- '#value' => t('Delete coupon'),
- '#weight' => 45,
- '#limit_validation_errors' => array(),
- '#submit' => array('commerce_coupon_form_submit_delete')
- );
- }
- return $form;
-}
-
-/**
- * Form API submit callback for the type form.
- */
-function commerce_coupon_form_submit(&$form, &$form_state) {
- $commerce_coupon = entity_ui_form_submit_build_entity($form, $form_state);
- // Save and go back.
- commerce_coupon_save($commerce_coupon);
- $form_state['redirect'] = 'admin/commerce/coupons';
-}
-
-/**
- * Form API submit callback for the delete button.
- */
-function commerce_coupon_form_submit_delete(&$form, &$form_state) {
- $form_state['redirect'] = 'admin/commerce/coupons/manage/' . $form_state['commerce_coupon']->coupon_id . '/delete';
-}
diff --git a/commerce_coupon.info b/commerce_coupon.info
deleted file mode 100644
index 2bf53bc..0000000
--- a/commerce_coupon.info
+++ /dev/null
@@ -1,13 +0,0 @@
-name = Commerce Coupon
-description = "Coupon module for the commerce shopping cart."
-dependencies[] = commerce
-package = Commerce Coupon
-core = 7.x
-
-files[] = commerce_coupon.module
-
-files[] = classes/commerce_coupon.inc
-files[] = classes/commerce_coupon_log.inc
-files[] = classes/commerce_coupon_type.inc
-
-files[] = commerce_coupon.admin.inc
diff --git a/commerce_coupon.install b/commerce_coupon.install
deleted file mode 100644
index d916a06..0000000
--- a/commerce_coupon.install
+++ /dev/null
@@ -1,197 +0,0 @@
-<?php
-
-
-/**
- * Implements hook_schema().
- */
-function commerce_coupon_schema() {
- $schema = array();
-
- $schema['commerce_coupon'] = array(
- 'description' => 'The base table for coupons.',
- 'fields' => array(
- 'coupon_id' => array(
- 'description' => 'The primary identifier for the coupon.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'type' => array(
- 'description' => 'The {commerce_coupon_type}.type of this coupon.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'code' => array(
- 'description' => 'The code provided to the customer.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'amount' => array(
- 'description' => 'The coupon amount.',
- 'type' => 'float',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'is_percentage' => array(
- 'description' => 'Indicates if this coupon is a percentage or an fixed amount.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'is_active' => array(
- 'description' => 'Indicates if this coupon is active or not.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'created' => array(
- 'description' => 'The Unix timestamp when the coupon was created.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'changed' => array(
- 'description' => 'The Unix timestamp when the coupon was most recently saved.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'data' => array(
- 'type' => 'blob',
- 'size' => 'big',
- 'not null' => FALSE,
- 'serialize' => TRUE,
- 'description' => 'Everything else, serialized.',
- ),
- ),
- 'primary key' => array('coupon_id'),
- 'unique keys' => array(
- 'code' => array('code'),
- ),
-
- );
-
- $schema['commerce_coupon_type'] = array(
- 'description' => 'Stores information about all defined coupon types.',
- 'fields' => array(
- 'type_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique coupon type ID.',
- ),
- 'type' => array(
- 'description' => 'The machine-readable name of this coupon type.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- ),
- 'label' => array(
- 'description' => 'The human-readable name of this coupon type.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'weight' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- 'description' => 'The weight of this coupon type in relation to others.',
- ),
- 'data' => array(
- 'type' => 'text',
- 'not null' => FALSE,
- 'size' => 'big',
- 'serialize' => TRUE,
- 'description' => 'A serialized array of additional data related to this coupon type.',
- ),
- ) + entity_exportable_schema_fields(),
- 'primary key' => array('type_id'),
- 'unique keys' => array(
- 'type' => array('type'),
- ),
- );
-
-
-
- $schema['commerce_coupon_log'] = array(
- 'description' => 'Stores the usage of coupons.',
- 'fields' => array(
- 'log_id' => array(
- 'description' => 'The primary identifier for the log entry.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'coupon_id' => array(
- 'description' => 'The referenced coupon.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'uid' => array(
- 'description' => 'The referenced user.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'order_id' => array(
- 'description' => 'The referenced order id.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'is_accepted' => array(
- 'description' => 'Indicates if this coupon is accepted.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'is_processed' => array(
- 'description' => 'Indicates if this coupon is processed. This is set to true, when the order is completed.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'created' => array(
- 'description' => 'The Unix timestamp when the log was created.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'changed' => array(
- 'description' => 'The Unix timestamp when the log was most recently saved.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('log_id'),
- 'foreign keys' => array(
- 'coupon' => array(
- 'table' => 'commerce_coupon',
- 'columns' => array('coupon_id' => 'coupon_id'),
- ),
- 'order' => array(
- 'table' => 'commerce_order',
- 'columns' => array('order_id' => 'order_id'),
- ),
- 'user' => array(
- 'table' => 'users',
- 'columns' => array('uid' => 'uid'),
- ),
- ),
- );
-
-
-
-
-
-
- return $schema;
-}
diff --git a/commerce_coupon.module b/commerce_coupon.module
deleted file mode 100644
index 8509531..0000000
--- a/commerce_coupon.module
+++ /dev/null
@@ -1,765 +0,0 @@
-<?php
-
-function commerce_coupon_entity_info() {
- $return = array();
-
- $return['commerce_coupon'] = array(
- 'label' => t('Commerce Coupon'),
- 'entity class' => 'CommerceCoupon',
- 'controller class' => 'EntityAPIController',
- 'base table' => 'commerce_coupon',
- 'fieldable' => TRUE,
-
- 'entity keys' => array(
- 'id' => 'coupon_id',
- 'bundle' => 'type',
- 'label' => 'code',
- ),
- 'bundles' => array(),
- 'bundle keys' => array(
- 'bundle' => 'type',
- ),
- 'access callback' => 'commerce_coupon_access',
- 'module' => 'commerce_coupon',
- 'save callback' => 'commerce_coupon_save',
-
- 'admin ui' => array(
- 'path' => 'admin/commerce/coupons',
- 'file' => 'commerce_coupon.admin.inc',
- ),
- );
-
- $return['commerce_coupon_log'] = array(
- 'label' => t('Commerce Coupon Log'),
- 'entity class' => 'CommerceCouponLog',
- 'controller class' => 'EntityAPIController',
- 'base table' => 'commerce_coupon_log',
- 'fieldable' => FALSE,
-
- 'entity keys' => array(
- 'id' => 'log_id',
- ),
- 'access callback' => 'commerce_coupon_access',
- 'module' => 'commerce_coupon',
- 'save callback' => 'commerce_coupon_log_save',
- );
-
- $return['commerce_coupon_type'] = array(
- 'label' => t('Commerce Coupon Type'),
- 'entity class' => 'CommerceCouponType',
- 'controller class' => 'EntityAPIController',
- 'base table' => 'commerce_coupon_type',
- 'fieldable' => FALSE,
- 'bundle of' => 'commerce_coupon',
- 'exportable' => TRUE,
- 'entity keys' => array(
- 'id' => 'type',
- 'name' => 'type',
- 'label' => 'label',
- ),
- 'access callback' => 'commerce_coupon_type_access',
- 'module' => 'commerce_coupon',
-
- // Enable the entity API's admin UI.
- 'admin ui' => array(
- 'path' => 'admin/commerce/coupons/types',
- 'file' => 'commerce_coupon.admin.inc',
- ),
- );
-
-
- return $return;
-}
-
-function commerce_coupon_log_save(CommerceCouponLog $log) {
- $log->changed = time();
- return $log->save();
-}
-
-
-/**
- * Implements hook_commerce_checkout_pane_info().
- */
-function commerce_coupon_commerce_checkout_pane_info() {
- $checkout_panes = array();
-
- $checkout_panes['commerce_coupon'] = array(
- 'title' => t('Coupon'),
- 'page' => 'checkout',
- 'locked' => TRUE,
- 'file' => 'includes/commerce_coupon.checkout_pane.inc',
- 'base' => 'commerce_coupon_pane',
- 'weight' => 9,
- );
-
-
- return $checkout_panes;
-}
-
-function commerce_coupon_menu() {
- $items = array();
-
- foreach (commerce_coupon_get_types() as $type => $info) {
- $entity = entity_create('commerce_coupon', array('type' => $type));
- $type_arg = strtr($type, '_', '-');
- $items['admin/commerce/coupons/add/'.$type_arg] = array(
- 'title' => 'Create @name',
- 'title arguments' => array('@name' => $info->label),
- 'page callback' => 'entity_ui_get_form',
- 'page arguments' => array('commerce_coupon', $entity, 'add'),
- 'file' => 'commerce_coupon.admin.inc',
- 'access callback' => 'commerce_coupon_access',
- 'access arguments' => array('create', $type),
- 'module' => 'commerce_coupon',
- );
- }
-
- return $items;
-}
-
-function commerce_coupon_menu_alter(&$items) {
- $items['admin/commerce/coupons/types']['type'] = MENU_LOCAL_TASK;
-
- $items['admin/commerce/coupons/list'] = array(
- 'title' => 'Coupons',
- 'description' => 'Manage the coupons.',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => -10,
- ) + $items['admin/commerce/coupons'];
-
- $items['admin/commerce/coupons/add'] = array(
- 'title' => 'Create Coupon',
- 'page callback' => 'commerce_coupons_add_page',
- 'access callback' => 'commerce_coupon_access',
- 'access arguments' => array('create'),
- 'module' => 'commerce_coupon',
- );
-
- $items['admin/commerce/coupons/create'] = array(
- 'title' => 'Create Coupon',
- 'page callback' => 'commerce_coupons_create_page',
- 'access callback' => 'commerce_coupon_access',
- 'access arguments' => array('create'),
- 'module' => 'commerce_coupon',
- 'type' => MENU_LOCAL_ACTION,
- );
-}
-
-function commerce_coupons_create_page() {
- drupal_goto('admin/commerce/coupons/add');
-}
-
-function commerce_coupons_add_page() {
- $item = menu_get_item();
- $content = system_admin_menu_block($item);
-
- // Bypass the admin/commerce/coupon/add listing if only one coupon type is
- // available.
- if (count($content) == 1) {
- $item = array_shift($content);
- drupal_goto($item['href']);
- }
- return theme('commerce_coupon_add_list', array('content' => $content));
-}
-
-
-function commerce_coupon_theme() {
- return array(
- 'commerce_coupon_add_list' => array(
- 'variables' => array('content' => NULL),
- )
- );
-}
-
-
-function theme_commerce_coupon_add_list($variables) {
- $content = $variables['content'];
- $output = '';
-
- if ($content) {
- $output = '<dl class="commerce-coupon-type-list">';
- foreach ($content as $item) {
- $output .= '<dt>' . l($item['title'], $item['href'], $item['localized_options']) . '</dt>';
- $output .= '<dd>' . filter_xss_admin($item['description']) . '</dd>';
- }
- $output .= '</dl>';
- }
- else {
- if (user_access('administer coupon types')) {
- $output = '<p>' . t('You have not created any coupon types yet. Go to the <a href="@create-coupon-type">coupon type creation page</a> to add a new coupon type.', array('@create-coupon-type' => url('admin/commerce/coupons/types/add'))) . '</p>';
- }
- else {
- $output = '<p>' . t('No coupon type have been created yet for you to use.') . '</p>';
- }
- }
-
- return $output;
-}
-
-
-/**
- * Implements hook_entity_info_alter().
- *
- * Use this hook to specify commerce coupon bundles to avoid a recursion, as loading
- * the commerce coupon types needs the entity info too.
- */
-function commerce_coupon_entity_info_alter(&$entity_info) {
- foreach (commerce_coupon_get_types() as $type => $info) {
- $entity_info['commerce_coupon']['bundles'][$type] = array(
- 'label' => $info->label,
- 'admin' => array(
- 'path' => 'admin/commerce/coupons/types/manage/%commerce_coupon_type',
- 'real path' => 'admin/commerce/coupons/types/manage/' . $type,
- 'bundle argument' => $type,
- 'access arguments' => array('administer coupon types'),
- ),
- );
- }
-}
-
-
-
-function commerce_coupon_type_access($op, $type = NULL, $account = NULL) {
- return user_access('administer coupon types', $account);
-}
-
-function commerce_coupon_access($op, $type = NULL, $account = NULL) {
- return user_access('administer coupons', $account);
-}
-
-
-function commerce_coupon_permission() {
- $permissions = array(
- 'administer coupon types' => array(
- 'title' => t('Administer Coupon Types'),
- 'description' => t('Allows users to manage coupon types.'),
- ),
- 'administer coupons' => array(
- 'title' => t('Administer Coupons'),
- 'description' => t('Allows users to manage coupons.'),
- ),
- );
- return $permissions;
-}
-
-
-
-/**
- * Gets an array of all coupon types, keyed by the type name.
- *
- * @param $type_name
- * If set, the type with the given name is returned.
- * @return CouponType[]
- * Depending whether $type isset, an array of coupon types or a single one.
- */
-function commerce_coupon_get_types($type_name = NULL) {
- $types = entity_load('commerce_coupon_type', isset($type_name) ? array($type_name) : FALSE);
- return isset($type_name) ? reset($types) : $types;
-}
-
-
-
-/**
- * Menu argument loader; Load a coupon type by string.
- *
- * @param $type
- * The machine-readable name of a coupon type to load.
- * @return
- * A commerce coupon type array or FALSE if $type does not exist.
- */
-function commerce_coupon_type_load($type) {
- return commerce_coupon_get_types($type);
-}
-
-
-
-/**
- * Fetch a coupon object.
- *
- * @param $coupon_id
- * Integer specifying the coupon id.
- * @param $reset
- * A boolean indicating that the internal cache should be reset.
- * @return
- * A fully-loaded $coupon object or FALSE if it cannot be loaded.
- *
- * @see commerce_coupon_load_multiple()
- */
-function commerce_coupon_load($coupon_id, $reset = FALSE) {
- $coupons = commerce_coupon_load_multiple(array($coupon_id), array(), $reset);
- return reset($coupons);
-}
-
-/**
- * Load multiple coupons based on certain conditions.
- *
- * @param $pids
- * An array of coupon IDs.
- * @param $conditions
- * An array of conditions to match against the {commerce_coupon} table.
- * @param $reset
- * A boolean indicating that the internal cache should be reset.
- * @return
- * An array of coupon objects, indexed by pid.
- *
- * @see entity_load()
- * @see commerce_coupon_load()
- */
-function commerce_coupon_load_multiple($coupon_ids = array(), $conditions = array(), $reset = FALSE) {
- return entity_load('commerce_coupon', $coupon_ids, $conditions, $reset);
-}
-
-
-function commerce_coupon_log_load_multiple($log_ids = array(), $conditions = array(), $reset = FALSE) {
- return entity_load('commerce_coupon_log', $log_ids, $conditions, $reset);
-}
-
-
-function commerce_coupon_load_by_code($code) {
- $coupon = db_select('commerce_coupon')
- ->fields('commerce_coupon')
- ->condition('is_active', '1','=')
- ->condition('code', $code,'=')
- ->execute()
- ->fetchAssoc();
-
- if($coupon == NULL or !is_array($coupon)) {
- return NULL;
- }
-
- // TODO: Find a better way to load the entity
- return commerce_coupon_load($coupon['coupon_id']);
-}
-
-
-function commerce_coupon_get_coupons_by_order($order_id) {
-
- $coupon_raw = db_query('SELECT coupon_id, log_id FROM {commerce_coupon_log} WHERE order_id = :order_id', array(':order_id' => $order_id))->fetchAllAssoc('log_id', PDO::FETCH_ASSOC);
-
-
-
- if(!is_array($coupon_raw) or count($coupon_raw) <= 0) {
- return array();
- }
-
- $coupon_ids = array();
-
- foreach($coupon_raw as $coupon) {
- $coupon_ids[] = $coupon['coupon_id'];
- }
-
- return commerce_coupon_load_multiple($coupon_ids);
-}
-
-
-
-/**
- * Deletes a coupon.
- */
-function commerce_coupon_delete(Coupon $coupon) {
- $coupon->delete();
-}
-
-/**
- * Delete multiple coupons.
- *
- * @param $pids
- * An array of coupon IDs.
- */
-function commerce_coupon_delete_multiple(array $pids) {
- entity_get_controller('commerce_coupon')->delete($pids);
-}
-
-/**
- * Implements hook_user_cancel().
- */
-function commerce_coupon_user_cancel($edit, $account, $method) {
- // Delete all coupons of the user in any case.
- foreach (commerce_coupon_load_by_user($account) as $coupon) {
- commerce_coupon_delete($coupon);
- }
-}
-
-/**
- * Create a new coupon object.
- */
-function commerce_coupon_create(array $values) {
- return new CommerceCoupon($values);
-}
-
-/**
- * Create a new coupon object.
- */
-function commerce_coupon_log_create(array $values) {
- return new CommerceCouponLog($values);
-}
-
-/**
- * Saves a coupon to the database.
- *
- * @param $coupon
- * The coupon object.
- */
-function commerce_coupon_save(CommerceCoupon $coupon) {
-
- // Generate a code if no is set:
- if(!isset($coupon->code) || empty($coupon->code)) {
- $coupon->code = commerce_coupon_generate_coupon_code();
- }
- return $coupon->save();
-}
-
-function commerce_coupon_generate_coupon_code($length = NULL) {
-
- // We define the possible characters. No 'l','1', 'i' to prevent
- // reconisation problems.
- $characters = array(
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
- 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- '2','3','4','5','6','7','8','9'
- );
-
- $numberOfCharacters = count($characters);
-
- $codeFound = false;
-
- if($length == NULL) {
- // TODO: Replace this hardcoded value with a setting
- $length = 8;
- }
-
- // We need to check if the produced coupon code is already in the
- // database. We try this for 1000 iteration. If we then not found a
- // a code, we stop. There must be an error in this case.
- for($i = 0; $i < 1000 && $codeFound == false; $i++) {
-
- $code = '';
-
- // Create the code per character
- for($c = 0; $c < $length; $c++) {
- $randIndex = mt_rand(0, $numberOfCharacters);
- $code .= $characters[$randIndex];
- }
-
- // Check in the database if the generated code is already defined.
- if (commerce_coupon_code_exists($code) == false) {
- $codeFound = true;
- }
- }
- return $code;
-}
-
-function commerce_coupon_code_exists($code) {
-
- // TODO: Replace this query with drupal 7 api
- $rs = db_query('SELECT * FROM {commerce_coupon} WHERE code = :code', array(':code' => $code));
- $codeObject = $rs->fetchObject();
-
- if ($codeObject == null) {
- return false;
- }
- else {
- return true;
- }
-}
-
-function commerce_coupon_code_is_active($code) {
-
- // TODO: Replace this query with drupal 7 api
- $rs = db_query('SELECT * FROM {commerce_coupon} WHERE code = :code AND is_active = 1', array(':code' => $code));
- $codeObject = $rs->fetchObject();
-
- if ($codeObject == null) {
- return false;
- }
- else {
- return true;
- }
-
-}
-
-function commerce_coupon_code_is_valid($code, $order) {
-
- $coupon = commerce_coupon_load_by_code($code);
-
- // if no such coupon found, the $code is invalid
- if(!is_object($coupon)) {
- return false;
- }
-
- // We use the drupal_static function to generate a global variable.
- // We set per default the result to true. The rules can modify this values,
- // by invoking the valid or invalid action.
- $validation_results = &drupal_static('commerce_coupon_action_validation_results');
- $validation_results = true;
-
- // We invoke the rules. The defined action callback methods sets then the
- // validation result appropriate.
- rules_invoke_event('commerce_coupon_validate', $order, $coupon);
-
- // We get our global variable and return the result.
- return drupal_static('commerce_coupon_action_validation_results');
-}
-
-
-/**
- * Implements hook_commerce_price_component_type_info().
- */
-function commerce_coupon_commerce_price_component_type_info() {
- $components = array();
-
- // Add a price component type for each tax rate that specifies it.
- foreach (commerce_coupon_get_types() as $type => $coupon_type) {
- $components['commerce_coupon_' . $type] = array(
- 'title' => $coupon_type->label,
- // TODO: Add addtional field to coupon type
- 'display_title' => $coupon_type->label,
- );
- }
-
- return $components;
-}
-
-
-function commerce_coupon_redeem_coupon($coupon, $order) {
- global $user;
-
- if(!isset($order->order_id) or !isset($coupon->coupon_id) ) {
- drupal_set_message(t('Your coupon code cannot be redeem.'), 'error');
- return;
- }
-
-
- // Log the redemption
- $log = commerce_coupon_log_create(array(
- 'uid' => $user,
- 'order_id' => $order->order_id,
- 'coupon_id' => $coupon->coupon_id,
- 'is_accepted' => TRUE,
- ));
- $log->save();
-
- if(!($order instanceof EntityMetadataWrapper)) {
- $order = entity_metadata_wrapper('commerce_order', $order);
- }
-
- if (!$coupon->is_percentage) {
- $line_item = commerce_coupon_line_item_new($coupon, $order->order_id->value());
- commerce_line_item_save($line_item);
- $order->commerce_line_items[] = $line_item;
- $order->save();
- }
-
-}
-
-
-/**
- * Saves a coupon type to the db.
- */
-function commerce_coupon_type_save(CommerceCouponType $type) {
- $type->save();
-
- // Ensure the creation of the rules (components)
- entity_defaults_rebuild();
-
- return $type;
-}
-
-/**
- * Deletes a coupon type from.
- */
-function commerce_coupon_type_delete(CommerceCouponType $type) {
- $type->delete();
-}
-
-
-/**
- * Implements hook_commerce_coupon_type_delete()
- */
-function commerce_coupon_commerce_coupon_type_delete($type) {
- // Delete all coupons of this type.
- if ($pids = array_keys(commerce_coupon_load_multiple(FALSE, array('type' => $type->type)))) {
- commerce_coupon_delete_multiple($pids);
- }
- // Rebuild the menu as any (user-category) menu items should be gone now.
- menu_rebuild();
-}
-
-
-
-
-
-
-
-
-/**
- * Implements hook_commerce_line_item_type_info().
- */
-function commerce_coupon_commerce_line_item_type_info() {
- return array(
- 'coupon' => array(
- 'type' => 'coupon',
- 'name' => t('Coupon'),
- 'description' => t('Coupon line item for fixed coupon amounts.'),
- 'add_form_submit_value' => t('Add coupon'),
- 'base' => 'commerce_coupon_line_item',
- 'callbacks' => array(
- 'configuration' => 'commerce_coupon_configure_line_item',
- ),
- ),
- );
-}
-
-
-
-/**
- * Returns an appropriate title for this line item.
- */
-function commerce_coupon_line_item_title($line_item) {
- // TODO: Implement this method, get coupon code
-
- $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
-
-
-
- return t('Coupon');
-}
-
-
-/**
- * Returns the elements necessary to add a product line item through a line item
- * manager widget.
- */
-function commerce_coupon_line_item_add_form($form_state) {
- // TODO: Implement this method correct
-
- $order = $form_state['commerce_order'];
- $form = array();
-
- $form['amount'] = array(
- '#type' => 'textfield',
- '#title' => t('Amount'),
- '#default_value' => $default_amount,
- '#size' => 10,
- );
-
- // Build a currency options list from all enabled currencies.
- $options = array();
- foreach (commerce_currencies(TRUE) as $currency_code => $currency) {
- $options[$currency_code] = check_plain($currency['code']);
- }
-
- $form['currency_code'] = array(
- '#type' => 'select',
- '#title' => t('Currency'),
- '#options' => $options,
- '#default_value' => commerce_default_currency(),
- );
-
- return $form;
-}
-
-/**
- * Adds the selected shippng information to a line item added via a line item
- * manager widget.
- *
- * @param $line_item
- * The newly created line item object.
- * @param $element
- * The array representing the widget form element.
- * @param $form_state
- * The present state of the form upon the latest submission.
- * @param $form
- * The actual form array.
- *
- * @return
- * NULL if all is well or an error message if something goes wrong.
- */
-function commerce_coupon_line_item_add_form_submit(&$line_item, $element, &$form_state, $form) {
- // TODO: Implement this method correct
-
- $order = $form_state['commerce_order'];
-
- // Populate the line item with the product data.
- $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
- //$line_item_wrapper->shipping_method = $element['actions']['shipping_method']['#value'];
- $line_item_wrapper->commerce_unit_price->amount = $element['actions']['amount']['#value'];
- $line_item_wrapper->commerce_unit_price->currency_code = $element['actions']['currency_code']['#value'];
- $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
- $line_item_wrapper->commerce_unit_price->value(),
- 'base_price',
- $line_item_wrapper->commerce_unit_price->value(),
- TRUE
- );
-}
-
-
-/**
- * Creates a new product line item populated with the proper product values.
- *
- * @param $coupon
- * The fully loaded coupon to add.
- * @param $order_id
- * Order to add this coupon.
- *
- * @return
- * Line item object with default values.
- */
-function commerce_coupon_line_item_new($coupon, $order_id) {
- // Create the new line item.
- $line_item = entity_create('commerce_line_item', array(
- 'type' => 'coupon',
- 'order_id' => $order_id,
- 'quantity' => 1,
- ));
- // TODO: Implement this function
-
- $line_item->sku = $coupon->type . '_' . $coupon->coupon_id;
-
- // If it is a percentage coupon dont set any unit price
- if ($coupon->is_percentage) {
- return $line_item;
- }
-
-
- $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
-
- // Set the unit price on the line item object.
- $line_item_wrapper->commerce_unit_price->amount = $coupon->amount * -1 * 100;
-
- // print_r($coupon->amount);
-
- // Add the base price to the components array.
- if (!commerce_price_component_load($line_item_wrapper->commerce_unit_price->value(), 'coupon')) {
- $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
- $line_item_wrapper->commerce_unit_price->value(),
- 'commerce_coupon_' . $coupon->type,
- $line_item_wrapper->commerce_unit_price->value(),
- TRUE
- );
- }
-
-
- // Return the line item.
- return $line_item;
-}
-
-
-/**
- * Ensures the product line item type contains a product reference field.
- *
- * This function is called by the line item module when it is enabled or this
- * module is enabled. It invokes this function using the configuration_callback
- * as specified above.
- */
-function commerce_coupon_configure_line_item() {
-
-}
-
-
-
-
-
-
diff --git a/commerce_coupon.rules.inc b/commerce_coupon.rules.inc
deleted file mode 100644
index 478477a..0000000
--- a/commerce_coupon.rules.inc
+++ /dev/null
@@ -1,178 +0,0 @@
-<?php
-
-function commerce_coupon_rules_event_info() {
- $events = array();
-
- $events['commerce_coupon_validate'] = array(
- 'label' => t('Validate a coupon'),
- 'group' => t('Commerce Coupon'),
- 'variables' => array(
- 'coupon' => array('type' => 'commerce_coupon', 'label' => t('commerce coupon to validate')),
- ) + commerce_order_rules_event_variables(t('Order', array(), array('context' => 'a drupal commerce order'))),
- 'access callback' => 'commerce_order_rules_access',
- );
-
- $events['commerce_coupon_validated'] = array(
- 'label' => t('A coupon is validated'),
- 'group' => t('Commerce Coupon'),
- 'variables' => array(
- 'coupon' => array('type' => 'commerce_coupon', 'label' => t('commerce coupon to validate')),
- ) + commerce_order_rules_event_variables(t('Order', array(), array('context' => 'a drupal commerce order'))),
- 'access callback' => 'commerce_order_rules_access',
- );
-
- return $events;
-}
-
-
-
-
-/**
- * Implements hook_rules_action_info().
- */
-function commerce_coupon_rules_action_info() {
- $actions = array();
-
- $actions['commerce_coupon_is_valid'] = array(
- 'label' => t('Set coupon as valid'),
- 'parameter' => array(
- 'override' => array(
- 'type' => 'boolean',
- 'label' => t('Override'),
- 'description' => t('Normaly the validation result is concatenated by an AND operator. Here you can bypass this and set the value to true.'),
- ),
- ),
- 'group' => t('Commerce Coupon'),
- 'base' => 'commerce_coupon_valid_action',
- 'callbacks' => array(
- 'execute' => 'commerce_coupon_action_is_valid_coupon',
- ),
- );
-
- $actions['commerce_coupon_is_invalid'] = array(
- 'label' => t('Set coupon as invalid'),
- 'group' => t('Commerce Coupon'),
- 'base' => 'commerce_coupon_invalid_action',
- 'callbacks' => array(
- 'execute' => 'commerce_coupon_action_is_invalid_coupon',
- ),
- );
-
- $actions['commerce_coupon_apply_to_item_line'] = array(
- 'label' => t('Apply a coupon to a line item'),
- 'parameter' => array(
- 'line_item' => array(
- 'type' => 'commerce_line_item',
- 'label' => t('Line item'),
- ),
- 'coupon' => array(
- 'type' => 'commerce_coupon',
- 'label' => t('Coupon'),
- ),
- ),
- 'group' => t('Commerce Coupon'),
- );
-
- $actions['commerce_coupon_calculate_percentage_amount'] = array(
- 'label' => t('Calculates a percentage coupon amount'),
- 'parameter' => array(
- 'line_item' => array(
- 'type' => 'commerce_line_item',
- 'label' => t('Line item'),
- ),
- ),
- 'group' => t('Commerce Coupon'),
- );
-
- return $actions;
-}
-
-
-function commerce_coupon_action_is_valid_coupon($override = false) {
- $validation_results = &drupal_static('commerce_coupon_action_validation_results');
-
- if(isset($validation_results) && $override == false) {
- $validation_results = $validation_results && true;
- }
- else {
- $validation_results[$commerce_coupon->coupon_id] = true;
- }
-
-}
-
-function commerce_coupon_action_is_invalid_coupon($commerce_coupon) {
-
- $validation_results = &drupal_static('commerce_coupon_action_validation_results');
-
- $validation_results = false;
-
-}
-
-function commerce_coupon_calculate_percentage_amount($line_item) {
-
- $order_id = $line_item->order_id;
- $coupons = commerce_coupon_get_coupons_by_order($order_id);
- $components = rules_get_components(FALSE, 'action');
-
- foreach($coupons as $coupon) {
- $coupon = entity_metadata_wrapper('commerce_coupon', $coupon);
- $component_name = 'commerce_coupon_apply_' . $coupon->type->value() . '_to_item_line';
-
- if($coupon->is_percentage->value() && isset($components[$component_name])) {
- // Invoke it with the line item.
- rules_invoke_component($component_name, $line_item, $coupon);
- }
-
-
- }
-}
-
-
-function commerce_coupon_apply_to_item_line($line_item, $coupon) {
-
-
- if(!($coupon instanceof EntityMetadataWrapper)) {
- $coupon = entity_metadata_wrapper('commerce_coupon', $coupon);
- }
-
- if($coupon->is_percentage->value()) {
- $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
-
-
- $rate = $coupon->amount->value();
- if($rate > 1) {
- // Ensure that the rate is never bigger then 100%
- $rate = $rate / 100;
- }
-
- // TODO: Ensure that the coupon is only applied once!
-
- // Update the data array with the tax component.
- $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
- $line_item_wrapper->commerce_unit_price->value(),
- 'commerce_coupon_' . $coupon->type->value(),
-
- // TODO: Replace the calcuation by a callback method of the type
- array(
- 'amount' => $line_item_wrapper->commerce_unit_price->amount->value() * $rate * -1,
- 'currency_code' => $line_item_wrapper->commerce_unit_price->currency_code->value(),
- 'data' => array(
- 'coupon' => array(
- 'coupon_id' => $coupon->coupon_id->value(),
- 'type' => $coupon->type->value(),
- 'rate' => $rate,
- 'code' => $coupon->code->value(),
- ),
- ),
- ),
- false
- );
-
-
- }
-}
-
-
-
-
-
diff --git a/commerce_coupon.rules_defaults.inc b/commerce_coupon.rules_defaults.inc
deleted file mode 100644
index 5da1cb4..0000000
--- a/commerce_coupon.rules_defaults.inc
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-/**
- * @file
- * Defines default tax components and rules.
- */
-
-/**
- * Implements hook_default_rules_configuration().
- */
-function commerce_coupon_default_rules_configuration() {
- $rules = array();
-
- foreach(commerce_coupon_get_types() as $type => $coupon_type) {
-
- // Create a new rules component.
- $rule = rule(commerce_coupon_component_variables());
-
- $rule->label = t('Calculate @title amount', array('@title' => $coupon_type->label));
-
- // Add the action to apply the current tax.
- $rule->action('commerce_coupon_apply_to_item_line', array(
- 'line_item:select' => 'line-item',
- 'coupon:select' => 'coupon',
- ));
-
- $rules['commerce_coupon_apply_' . $type . '_to_item_line'] = $rule;
-
- }
-
- // Loop over every tax type and define a pricing rules to calculate taxes of
- // that type.
- foreach(commerce_coupon_get_types() as $type => $coupon_type) {
- // Create a new product pricing rule.
- $rule = rules_reaction_rule();
-
- $rule->label = t('Calculate coupon amount: @title', array('@title' => $coupon_type->label));
- $rule->active = TRUE;
-
- // Add the action to invoke every coupon component matching this type.
- $rule
- ->event('commerce_product_calculate_sell_price')
- ->action('commerce_coupon_calculate_percentage_amount', array(
- 'line_item:select' => 'line-item',
- )
- );
-
- $rules['commerce_coupon_calculate_' . $type . '_amount'] = $rule;
- }
-
-
- return $rules;
-}
-
-/**
- * Returns an array of variables for use in tax rate components.
- */
-function commerce_coupon_component_variables() {
- return array(
- 'line_item' => array(
- 'type' => 'commerce_line_item',
- 'label' => t('Line item'),
- ),
- 'coupon' => array(
- 'type' => 'commerce_coupon',
- 'label' => t('Coupon'),
- ),
- );
-}
diff --git a/includes/commerce_coupon.checkout_pane.inc b/includes/commerce_coupon.checkout_pane.inc
deleted file mode 100644
index bc77b50..0000000
--- a/includes/commerce_coupon.checkout_pane.inc
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-
-/**
- * Payment pane: form callback.
- */
-function commerce_coupon_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
- $pane_form = array();
-
- // Store the payment methods in the form for validation purposes.
- $pane_form['coupon_code'] = array(
- '#type' => 'textfield',
- '#title' => 'Coupon Code',
- '#description' => 'Enter here your coupon code.',
- );
-
- return $pane_form;
-}
-
-function commerce_coupon_pane_checkout_form_validate($form, &$form_state, $checkout_pane, $order) {
-
- // Check if it is empty
- if (empty($form_state['values']['commerce_coupon']['coupon_code'])) {
- return true;
- }
-
- // Valdiate the coupon code
- if (commerce_coupon_code_is_valid($form_state['values']['commerce_coupon']['coupon_code'], $order)) {
- return true;
- }
- else {
- form_set_error('commerce_coupon][coupon_code', t('Your coupon code is not valid.'));
- return false;
- }
-
-}
-
-
-function commerce_coupon_pane_checkout_form_submit($form, &$form_state, $checkout_pane, $order) {
- $code = $form_state['values']['commerce_coupon']['coupon_code'];
-
- $coupon = commerce_coupon_load_by_code($code);
- commerce_coupon_redeem_coupon($coupon, $order);
-}
diff --git a/modules/batch/commerce_coupon_batch.info b/modules/batch/commerce_coupon_batch.info
deleted file mode 100644
index bd652b1..0000000
--- a/modules/batch/commerce_coupon_batch.info
+++ /dev/null
@@ -1,9 +0,0 @@
-name = Coupon Batch
-description = Enables the mass generation of coupons.
-package = Commerce Coupon
-dependencies[] = commerce_coupon
-core = 7.x
-
-; Rules
-files[] = commerce_coupon_batch.module
-
diff --git a/modules/batch/commerce_coupon_batch.module b/modules/batch/commerce_coupon_batch.module
deleted file mode 100644
index 935c7c1..0000000
--- a/modules/batch/commerce_coupon_batch.module
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-
-function commerce_coupon_batch_menu() {
- $items = array();
-
-
- $items['admin/commerce/coupons/batch_task'] = array(
- 'title' => 'Batch Creation',
- //'title arguments' => array('@name' => $info->label),
- /*'page callback' => 'entity_ui_get_form',
- 'page arguments' => array('commerce_coupon', $entity, 'add'),
- 'file' => 'commerce_coupon.admin.inc',*/
- //'access callback' => 'commerce_coupon_access',
- 'page callback' => 'commerce_coupon_batch_task_page',
- 'access arguments' => array('commerce coupon batch creation'),
- 'module' => 'commerce_coupon_batch',
- 'type' => MENU_LOCAL_TASK,
- );
-
- $items['admin/commerce/coupons/batch'] = array(
- 'title' => 'Batch Creation',
- //'title arguments' => array('@name' => $info->label),
- /*'page callback' => 'entity_ui_get_form',
- 'page arguments' => array('commerce_coupon', $entity, 'add'),
- 'file' => 'commerce_coupon.admin.inc',*/
- //'access callback' => 'commerce_coupon_access',
- 'page callback' => 'commerce_coupon_batch_overview_page',
- 'access arguments' => array('commerce coupon batch creation'),
- 'module' => 'commerce_coupon_batch',
- );
-
-
- foreach (commerce_coupon_get_types() as $type => $info) {
- $entity = entity_create('commerce_coupon', array('type' => $type));
- $type_arg = strtr($type, '_', '-');
- $items['admin/commerce/coupons/batch/'.$type_arg] = array(
- 'title' => 'Batch create @name',
- 'title arguments' => array('@name' => $info->label),
- 'page callback' => 'entity_ui_get_form',
- 'page arguments' => array('commerce_coupon', $entity, 'add'),
- 'file' => 'includes/commerce_coupon_batch.form.inc',
- 'access callback' => 'commerce_coupon_access',
- 'access arguments' => array('create', $type),
- 'module' => 'commerce_coupon_batch',
- );
- }
-
- return $items;
-
-}
-
-function commerce_coupon_batch_task_page() {
- drupal_goto('admin/commerce/coupons/batch');
-}
-
-function commerce_coupon_batch_permission() {
- $permissions = array(
- 'commerce coupon batch creation' => array(
- 'title' => t('Commerce Coupon Batch Creation'),
- 'description' => t('Allows users to create coupons by a batch.'),
- ),
- );
- return $permissions;
-}
-
-
-function commerce_coupon_batch_overview_page() {
- $item = menu_get_item();
- $content = system_admin_menu_block($item);
-
-
- // Bypass the admin/commerce/coupon/add listing if only one coupon type is
- // available.
- if (count($content) == 1) {
- $item = array_shift($content);
- drupal_goto($item['href']);
- }
- return theme('commerce_coupon_add_list', array('content' => $content));
-}
diff --git a/modules/batch/includes/commerce_coupon_batch.form.inc b/modules/batch/includes/commerce_coupon_batch.form.inc
deleted file mode 100644
index 1e080a4..0000000
--- a/modules/batch/includes/commerce_coupon_batch.form.inc
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-
-
-
-/**
- * Generates the commerce coupon editing form.
- */
-function commerce_coupon_form($form, &$form_state, $coupon, $op = 'edit') {
-
- if ($op == 'clone') {
- $coupon_type->label .= ' (cloned)';
- $coupon_type->type = '';
- }
-
- $form['batch_size'] = array(
- '#title' => t('Batch Size'),
- '#type' => 'textfield',
- '#default_value' => $coupon->code,
- '#description' => t('Enter the number of coupons which should be generated.'),
- '#size' => 30,
- );
-
- $form['amount'] = array(
- '#title' => t('Amount'),
- '#type' => 'textfield',
- '#default_value' => $coupon->amount,
- '#description' => t('The amount of the coupon.'),
- '#required' => TRUE,
- '#size' => 30,
- );
-
- $form['is_percentage'] = array(
- '#title' => t('Percentage'),
- '#type' => 'checkbox',
- '#default_value' => $coupon->is_percentage,
- '#description' => t('Indicates if the amount is a percentage of the order or a fixed amount.'),
- );
-
-
- $form['is_active'] = array(
- '#title' => t('Active'),
- '#type' => 'checkbox',
- '#default_value' => $coupon->is_active,
- '#description' => t('Indicates if the coupon can be used or not.'),
- '#size' => 30,
- );
-
- // Add the field related form elements.
- $form_state['commerce_coupon'] = $coupon;
- field_attach_form('commerce_coupon', $coupon, $form, $form_state);
-
- $form['data']['#tree'] = TRUE;
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save coupon'),
- '#weight' => 40,
- );
-
- if ($op != 'add') {
- $form['actions']['delete'] = array(
- '#type' => 'submit',
- '#value' => t('Delete coupon'),
- '#weight' => 45,
- '#limit_validation_errors' => array(),
- '#submit' => array('commerce_coupon_form_submit_delete')
- );
- }
- return $form;
-}
-
-/**
- * Form API submit callback for the type form.
- */
-function commerce_coupon_form_submit(&$form, &$form_state) {
- $size = (int)$form_state['values']['batch_size'];
- $commerce_coupon = entity_ui_form_submit_build_entity($form, $form_state);
-
- if($size > 0) {
- for ($i = 0; $i < $size; $i++) {
- $coupon = clone $commerce_coupon;
- $coupon->code = commerce_coupon_generate_coupon_code();
-
- // Save
- commerce_coupon_save($coupon);
- }
- }
- // Go back.
- $form_state['redirect'] = 'admin/commerce/coupons';
-}
-