Пример #1
0
 private function build_coupon_form($coupon = array(), $id = 0)
 {
     $this->load->model('store/shipping_model');
     $this->load->model('store/products_model');
     $this->load->model('billing/subscription_plan_model');
     // Get the required options
     $coupon_products = isset($coupon['products']) ? $coupon['products'] : array();
     $coupon_plans = isset($coupon['plans']) ? $coupon['plans'] : array();
     $coupon_shipping = isset($coupon['shipping']) ? $coupon['shipping'] : array();
     $coupon_types = $this->coupon_model->get_coupon_types();
     foreach ($coupon_types as $type) {
         $type_options[$type->coupon_type_id] = $type->coupon_type_name;
     }
     $reduction_options = array(0 => '%', 1 => setting('currency_symbol'));
     $products = $this->products_model->get_products();
     $product_options = array();
     $product_options['-1'] = 'not available for any products';
     if (is_array($products)) {
         foreach ($products as $product) {
             $product_options[$product['id']] = $product['name'];
         }
     }
     $plans = $this->subscription_plan_model->get_plans();
     $plan_options = array();
     $plan_options['-1'] = 'not available for any subscriptions';
     if (is_array($plans)) {
         foreach ($plans as $plan) {
             $plan_options[$plan['id']] = $plan['name'];
         }
     }
     $shipping = $this->shipping_model->get_rates();
     $shipping_options = array();
     if (is_array($shipping)) {
         foreach ($shipping as $rate) {
             $shipping_options[$rate['id']] = $rate['name'];
         }
     }
     // Build the form
     $this->load->library('admin_form');
     $form = new Admin_form();
     $form->fieldset('Coupon Information');
     $form->hidden('coupon_id', $id);
     $form->text('Coupon Name', 'coupon_name', isset($coupon['coupon_name']) ? $coupon['coupon_name'] : null, 'Something for you to recognize the coupon by.', TRUE);
     $form->text('Coupon Code', 'coupon_code', isset($coupon['coupon_code']) ? $coupon['coupon_code'] : null, 'The code the customer must enter.', TRUE);
     $form->date('Start Date', 'coupon_start_date', isset($coupon['coupon_start_date']) ? $coupon['coupon_start_date'] : null, null, TRUE, FALSE, FALSE, '8em');
     $form->date('Expiry Date', 'coupon_end_date', isset($coupon['coupon_end_date']) ? $coupon['coupon_end_date'] : null, null, TRUE, FALSE, FALSE, '8em');
     $form->text('Maximum Uses', 'coupon_max_uses', (isset($coupon['coupon_max_uses']) and !empty($coupon['coupon_max_uses'])) ? $coupon['coupon_max_uses'] : null, 'The maximum number of customers that can use the coupon.', FALSE, FALSE, FALSE, '6em');
     $form->checkbox('One Per Customer?', 'coupon_customer_limit', '1', isset($coupon['coupon_customer_limit']) && $coupon['coupon_customer_limit'] == 1 ? TRUE : FALSE, 'Check to limit each customer to a single use.');
     $form->dropdown('Coupon Type', 'coupon_type_id', $type_options, isset($coupon['coupon_type_id']) ? $coupon['coupon_type_id'] : FALSE, FALSE, FALSE, FALSE, FALSE, 'coupon_type');
     $form->fieldset('Price Reduction', array('coupon_reduction'));
     $form->dropdown('Reduction Type', 'coupon_reduction_type', $reduction_options, isset($coupon['coupon_reduction_type']) ? $coupon['coupon_reduction_type'] : FALSE);
     $form->text('Reduction Amount', 'coupon_reduction_amt', isset($coupon['coupon_reduction_amt']) ? $coupon['coupon_reduction_amt'] : null, 'The amount of the discount.', FALSE, FALSE, FALSE, '6em');
     $form->dropdown('Products', 'products[]', $product_options, $coupon_products, TRUE, FALSE, 'Leave all unselected to make available for all products.');
     $form->dropdown('Subscription Plans', 'plans[]', $plan_options, $coupon_plans, TRUE, FALSE, 'Leave all unselected to make available for all subscriptions.');
     $form->fieldset('Free Trial', array('coupon_trial'));
     $form->text('Free Trial Length', 'coupon_trial_length', isset($coupon['coupon_trial_length']) ? $coupon['coupon_trial_length'] : null, null, FALSE, 'in days', FALSE, '6em');
     $form->dropdown('Subscription Plans', 'trial_subs[]', $plan_options, $coupon_plans, TRUE, 'If left blank, will select ALL SUBSCRIPTION PLANS');
     $form->fieldset('Free Shipping', array('coupon_shipping'));
     $form->text('Min. Cart Amount', 'coupon_min_cart_amt', isset($coupon['coupon_min_cart_amt']) ? $coupon['coupon_min_cart_amt'] : null, 'The minimum order amount before the coupon may be used.', FALSE, FALSE, FALSE, '6em');
     $form->dropdown('Shipping Methods', 'ship_rates[]', $shipping_options, $coupon_shipping, TRUE, 'If left blank, will select ALL SHIPPING PLANS');
     return $form;
 }