public function confirm($order_info, $order_total)
 {
     $code = '';
     $start = strpos($order_total['title'], '(') + 1;
     $end = strrpos($order_total['title'], ')');
     if ($start && $end) {
         $code = substr($order_total['title'], $start, $end - $start);
     }
     $coupon_info = \model\sale\CouponDAO::getInstance()->applyCoupon($code);
     if ($coupon_info) {
         \model\sale\CouponDAO::getInstance()->redeem($coupon_info['coupon_id'], $order_info['order_id'], $order_info['customer_id'], $order_total['value']);
     }
 }
Beispiel #2
0
 public function calculate()
 {
     $this->language->load('total/coupon');
     $json = array();
     if (!$this->cart->hasProducts()) {
         $json['redirect'] = $this->url->link('checkout/cart');
     }
     if (isset($this->request->post['coupon'])) {
         $this->load->model('checkout/coupon');
         $coupon_info = \model\sale\CouponDAO::getInstance()->applyCoupon($this->request->post['coupon']);
         if ($coupon_info) {
             $this->session->data['coupon'] = $this->request->post['coupon'];
             $this->session->data['success'] = $this->language->get('text_success');
             $json['redirect'] = $this->url->link('checkout/cart', '', 'SSL');
         } else {
             $json['error'] = $this->language->get('error_coupon');
         }
     }
     $this->getResponse()->setOutput(json_encode($json));
 }
Beispiel #3
0
 public function history()
 {
     $this->language->load('sale/coupon');
     $this->load->model('sale/coupon');
     $this->data['text_no_results'] = $this->language->get('text_no_results');
     $this->data['column_order_id'] = $this->language->get('column_order_id');
     $this->data['column_customer'] = $this->language->get('column_customer');
     $this->data['column_amount'] = $this->language->get('column_amount');
     $this->data['column_date_added'] = $this->language->get('column_date_added');
     if (isset($this->request->get['page'])) {
         $page = $this->request->get['page'];
     } else {
         $page = 1;
     }
     $this->data['histories'] = array();
     $results = CouponDAO::getInstance()->getCouponHistories($this->request->get['coupon_id'], ($page - 1) * 10, 10);
     foreach ($results as $result) {
         $this->data['histories'][] = array('order_id' => $result['order_id'], 'customer' => $result['customer'], 'amount' => $result['amount'], 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])));
     }
     $history_total = CouponDAO::getInstance()->getTotalCouponHistories($this->request->get['coupon_id']);
     $pagination = new Pagination();
     $pagination->total = $history_total;
     $pagination->page = $page;
     $pagination->limit = 10;
     $pagination->url = $this->url->link('sale/coupon/history', 'token=' . $this->session->data['token'] . '&coupon_id=' . $this->request->get['coupon_id'] . '&page={page}', 'SSL');
     $this->data['pagination'] = $pagination->render();
     $this->getResponse()->setOutput($this->render('sale/coupon_history.tpl'));
 }