示例#1
0
 public function couponAction()
 {
     if ($this->_request->isPost()) {
         $model = new Model_Coupon();
         $data = $this->_request->getParams();
         unset($data["action"]);
         unset($data["controller"]);
         unset($data["module"]);
         $data["create_user"] = $this->admin->{"username"};
         $number = $data["number"];
         unset($data["number"]);
         for ($i = 0; $i < $number; $i++) {
             do {
                 $coupon = $this->__generateRandomString(13);
             } while (!$model->validateCoupon($coupon));
             $data["value"] = $coupon;
             $model->save($data);
         }
         echo "<h2>Created !!!</h2>";
     }
 }
示例#2
0
 /**
  * CRUD controller: UPDATE
  */
 public function action_update()
 {
     $this->template->title = __('Update') . ' ' . __($this->_orm_model) . ' ' . $this->request->param('id');
     $this->template->styles = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/css/datepicker.css' => 'screen');
     $this->template->scripts['footer'] = array('//cdn.jsdelivr.net/bootstrap.datepicker/0.1/js/bootstrap-datepicker.js', 'js/oc-panel/coupon.js');
     $coupon = new Model_Coupon($this->request->param('id'));
     if ($this->request->post()) {
         $coupon->id_product = Core::post('id_product');
         $coupon->discount_amount = Core::post('discount_amount');
         $coupon->discount_percentage = Core::post('discount_percentage');
         $coupon->valid_date = Core::post('valid_date');
         $coupon->number_coupons = Core::post('number_coupons');
         $coupon->status = Core::post('status') == 'on' ? 1 : 0;
         try {
             $coupon->save();
             Alert::set(Alert::SUCCESS, sprintf(__('Coupon %s updated'), $coupon->name));
         } catch (ORM_Validation_Exception $e) {
             $errors = '';
             $e = $e->errors('coupon');
             foreach ($e as $f => $err) {
                 $errors .= $err . ' - ';
             }
             Alert::set(Alert::ERROR, sprintf(__('Coupon %s not updated, errors: %s'), $coupon->name, $errors));
         } catch (Exception $e) {
             Alert::set(Alert::ERROR, sprintf(__('Coupon %s not updated'), $coupon->name));
         }
         $this->redirect(Route::url('oc-panel', array('controller' => 'coupon', 'action' => 'update', 'id' => $coupon->id_coupon)));
     }
     return $this->render('oc-panel/pages/coupon/update', array('coupon' => $coupon, 'products' => $this->get_products()));
 }