示例#1
0
 /**
  * Handle GET requests.
  */
 public function action_get()
 {
     try {
         if (($coupon_name = $this->request->param('id')) != NULL) {
             $coupon = new Model_Coupon();
             $coupon->where('name', '=', $coupon_name)->where('number_coupons', '>', 0)->where('valid_date', '>', Date::unix2mysql())->where('status', '=', 1);
             //filter by product
             if (is_numeric(core::request('id_product'))) {
                 $coupon->where('id_product', '=', core::request('id_product'));
             }
             $coupon = $coupon->limit(1)->find();
             $this->rest_output(array('coupon' => $coupon->loaded() ? $coupon->as_array() : FALSE));
         } else {
             $this->_error('You need to specify a coupon');
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }
示例#2
0
 /**
  * Initialize properties before running the controller methods (actions),
  * so they are available to our action.
  */
 public function before($template = NULL)
 {
     parent::before();
     Theme::checker();
     $this->maintenance();
     $this->private_site();
     /**
      * selected category
      */
     self::$category = Model_Category::current();
     /**
      * selected location
      */
     self::$location = Model_Location::current();
     //Gets a coupon if selected
     Model_Coupon::current();
     if ($this->auto_render === TRUE) {
         // Load the template
         if ($template !== NULL) {
             $this->template = $template;
         }
         $this->template = View::factory($this->template);
         // Initialize template values
         $this->template->title = core::config('general.site_name');
         $this->template->meta_keywords = '';
         $this->template->meta_description = '';
         $this->template->meta_copyright = 'Open Classifieds ' . Core::VERSION;
         $this->template->meta_copywrite = $this->template->meta_copyright;
         //legacy for old themes
         $this->template->content = '';
         $this->template->styles = array();
         $this->template->scripts = array();
         $this->template->amphtml = NULL;
         $this->template->header = View::factory('header');
         $this->template->footer = View::factory('footer');
         // header_front_login fragment since CSRF gets cached :(
         // possible workaround ? @see http://kohanaframework.org/3.0/guide/kohana/fragments
         // if (Auth::instance()->logged_in())
         //     $this->template->header  = View::fragment('header_front_login','header');
         // else
         //     $this->template->header  = View::fragment('header_front','header');
         //$this->template->footer = View::fragment('footer_front','footer');
     }
 }
示例#3
0
 /**
  * Initialize properties before running the controller methods (actions),
  * so they are available to our action.
  * @param  string $template view to use as template
  * @return void           
  */
 public function before($template = NULL)
 {
     Theme::checker();
     $this->maintenance();
     //Gets a coupon if selected
     Model_Coupon::current();
     if ($this->auto_render === TRUE) {
         // Load the template
         $this->template = $template === NULL ? 'oc-panel/main' : $template;
         //if its and ajx request I want only the content
         if (Core::get('rel') == 'ajax') {
             $this->template = 'oc-panel/content';
         }
         $this->template = View::factory($this->template);
         // Initialize empty values
         $this->template->title = __('Panel') . ' - ' . core::config('general.site_name');
         $this->template->meta_keywords = '';
         $this->template->meta_description = '';
         $this->template->meta_copyright = 'Open eShop ' . Core::VERSION;
         $this->template->header = '';
         $this->template->content = '';
         $this->template->footer = '';
         $this->template->styles = array();
         $this->template->scripts = array();
         $this->template->user = Auth::instance()->get_user();
         //non ajax request
         if (Core::get('rel') != 'ajax') {
             if (core::get('print') == 1) {
                 $this->template->header = '';
                 $this->template->footer = '';
             } else {
                 $this->template->header = View::factory('oc-panel/header');
                 $this->template->footer = View::factory('oc-panel/footer');
             }
             //other color
             if (Theme::get('admin_theme') == 'bootstrap') {
                 Theme::$styles = array('//cdn.jsdelivr.net/bootswatch/3.3.6/paper/bootstrap.min.css' => 'screen', '//cdn.jsdelivr.net/bootstrap/3.3.6/css/bootstrap.min.css?v=print' => 'print', '//cdn.jsdelivr.net/chosen/1.0.0/chosen.css' => 'screen', '//cdn.jsdelivr.net/bootstrap.tagsinput/0.3.9/bootstrap-tagsinput.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen', 'css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/loadingbar.css' => 'screen', 'css/icon-picker.min.css' => 'screen', 'css/font-awesome.min.css' => 'screen', 'css/summernote.css' => 'screen', 'css/admin-styles.css?v=' . Core::VERSION => 'screen');
             } else {
                 Theme::$styles = array('//cdn.jsdelivr.net/bootstrap/3.3.6/css/bootstrap.min.css' => 'screen', '//cdn.jsdelivr.net/bootstrap/3.3.6/css/bootstrap.min.css?v=print' => 'print', '//cdn.jsdelivr.net/bootswatch/3.3.6/' . Theme::get('admin_theme', 'cerulean') . '/bootstrap.min.css' => 'screen', '//cdn.jsdelivr.net/chosen/1.0.0/chosen.css' => 'screen', '//cdn.jsdelivr.net/bootstrap.tagsinput/0.3.9/bootstrap-tagsinput.css' => 'screen', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css' => 'screen', 'css/jquery.sceditor.default.theme.min.css' => 'screen', 'css/loadingbar.css' => 'screen', 'css/icon-picker.min.css' => 'screen', 'css/font-awesome.min.css' => 'screen', 'css/summernote.css' => 'screen', 'css/admin-styles.css?v=' . Core::VERSION => 'screen');
             }
             Theme::$scripts['footer'] = array('//code.jquery.com/jquery-1.10.2.min.js', '//cdn.jsdelivr.net/bootstrap/3.3.6/js/bootstrap.min.js', '//cdn.jsdelivr.net/chosen/1.0.0/chosen.jquery.min.js', Route::url('jslocalization', array('controller' => 'jslocalization', 'action' => 'chosen')), (Kohana::$environment !== Kohana::DEVELOPMENT ? 'market.' . Core::DOMAIN . '' : 'eshop.lo') . '/embed.js', 'js/oc-panel/theme.init.js?v=' . Core::VERSION, 'js/jquery.sceditor.bbcode.min.js', 'js/summernote.min.js', 'js/summernote-ext-video.js', 'js/jquery.validate.min.js', Route::url('jslocalization', array('controller' => 'jslocalization', 'action' => 'validate')), 'js/jquery.cookie.min.js', 'js/iconPicker.min.js', 'js/oc-panel/sidebar.js?v=' . Core::VERSION, '//cdn.jsdelivr.net/bootstrap.tagsinput/0.3.9/bootstrap-tagsinput.min.js', '//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js', 'js/jquery.bootgrid.min.js', 'js/query.bootgrid.fa.min.js', 'js/form.js?v=' . Core::VERSION);
         }
     }
 }
示例#4
0
 /**
  * calculates the price adding a coupon
  * @param  int $id_product 
  * @param  float $amount     
  * @return float             
  */
 public static function price($id_product, $amount)
 {
     //coupon added only calculate price if coupon is NULL or for that poroduct
     if (self::valid($id_product)) {
         //calculating price by applying either a discount amount or a discount percentage
         $discounted_price = abs(Model_Coupon::current()->discount_amount);
         if ($discounted_price > 0) {
             $discounted_price = round($amount - $discounted_price, 2);
         } else {
             $discounted_price = abs(Model_Coupon::current()->discount_percentage);
             if ($discounted_price > 0) {
                 $discounted_price = round($amount - $amount * $discounted_price / 100.0, 2);
             } else {
                 // both discount_amount and discount_percentage are 0
                 $discounted_price = 0;
             }
         }
         //in case calculated price is negative
         $amount = max($discounted_price, 0);
     }
     //return the price
     return $amount;
 }
示例#5
0
 /**
  * Initialize properties before running the controller methods (actions),
  * so they are available to our action.
  */
 public function before($template = NULL)
 {
     parent::before();
     Theme::checker();
     $this->maintenance();
     $this->private_site();
     //get category, deprecated, to keep backwards compatibility with themes
     self::$category = Model_Category::current();
     //Gets a coupon if selected
     self::$coupon = Model_Coupon::current();
     //get the affiliate if any
     Model_Affiliate::current();
     if ($this->auto_render === TRUE) {
         // Load the template
         if ($template !== NULL) {
             $this->template = $template;
         }
         $this->template = View::factory($this->template);
         // Initialize template values
         $this->template->title = core::config('general.site_name');
         $this->template->meta_keywords = '';
         $this->template->meta_description = '';
         $this->template->meta_copyright = 'Open eShop ' . Core::VERSION;
         $this->template->content = '';
         $this->template->styles = array();
         $this->template->scripts = array();
         //we can not cache this view since theres dynamic parts
         //$this->template->header  = View::factory('header');
         //setting inner views try to get from fragment
         // if (Auth::instance()->logged_in())
         //     $this->template->header  = View::fragment('header_front_login','header');
         // else
         $this->template->header = View::factory('header');
         //no fragment since CSRF gets cached :(
         $this->template->footer = View::fragment('footer_front', 'footer');
     }
 }
示例#6
0
 /**
  * verifies pricing in an existing order
  * @return void
  */
 public function check_pricing()
 {
     //update order based on the price and the amount of
     $days = core::get('featured_days');
     if (is_numeric($days) and ($price = Model_Order::get_featured_price($days)) !== FALSE) {
         $this->amount = $price;
         //get price from config
         $this->featured_days = $days;
         $this->save();
     }
     //original coupon so we dont lose it while we do operations
     $orig_coupon = $this->id_coupon;
     //remove the coupon forced by get/post
     if (core::request('coupon_delete') != NULL) {
         $this->id_coupon = NULL;
     } elseif (Model_Coupon::valid($this->id_product) and $this->id_coupon != Model_Coupon::current()->id_coupon) {
         $this->id_coupon = Model_Coupon::current()->id_coupon;
     } elseif ($this->coupon->loaded() and (Date::mysql2unix($this->coupon->valid_date) < time() or $this->coupon->status == 0 or $this->coupon->number_coupons == 0)) {
         Alert::set(Alert::INFO, __('Coupon not valid, expired or already used.'));
         $this->coupon->clear();
         $this->id_coupon = NULL;
     }
     //add new discount
     $new_amount = Model_Coupon::price($this->id_product, $this->original_price());
     //recalculate price since it change the coupon
     if ($orig_coupon != $this->id_coupon or $this->amount != $new_amount) {
         $this->amount = $new_amount;
         try {
             $this->save();
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
     }
 }
示例#7
0
 /**
  * validates if a coupon its added and valid for that product
  * @return bool 
  */
 public function valid_coupon()
 {
     //coupon added
     if (Model_Coupon::current()->loaded()) {
         // only calculate price if coupon is NULL or for that poroduct
         if (Model_Coupon::current()->id_product == $this->id_product or Model_Coupon::current()->id_product == NULL) {
             return TRUE;
         }
     }
     return FALSE;
 }
示例#8
0
    echo __('Offer');
    ?>
 <?php 
    echo $product->formated_price();
    ?>
 
	    	<del><?php 
    echo $product->price . ' ' . $product->currency;
    ?>
</del> </h4>
	    </span>
		<span class="offer-valid"><?php 
    echo __('Offer valid until');
    ?>
 <?php 
    echo Date::format(Model_Coupon::current()->loaded() ? Model_Coupon::current()->valid_date : $product->offer_valid);
    ?>
</span>
	<?php 
} else {
    ?>
	    <?php 
    if ($product->final_price() != 0) {
        ?>
	        <h4><?php 
        echo __('Price');
        ?>
 : <span data-locale="<?php 
        echo $product->currency;
        ?>
" class="price-curry curry"><?php 
        ?>
, <?php 
        echo __('valid until');
        ?>
 <?php 
        echo Date::format(Model_Coupon::current()->valid_date);
        ?>
.
            <?php 
        if (Model_Coupon::current()->id_product != NULL) {
            ?>
                <?php 
            echo __('only valid for');
            ?>
  <?php 
            echo Model_Order::product_desc(Model_Coupon::current()->id_product);
            ?>
            <?php 
        }
        ?>
        </p>
    <?php 
    } else {
        ?>
    <div class="input-group">
        <input class="form-control" type="text" name="coupon" value="<?php 
        echo Core::get('coupon');
        echo Core::get('coupon');
        ?>
" placeholder="<?php 
        echo __('Coupon Name');
示例#10
0
 /**
  * get the coupon from the query or from the sesion or the post in paypal
  * @return Model_Coupon or null if not found
  */
 public static function get_coupon()
 {
     $coupon = new Model_Coupon();
     /**
      * Deletes a coupon in use
      */
     if (core::request('coupon_delete') != NULL) {
         Session::instance()->set('coupon', '');
         Alert::set(Alert::INFO, __('Coupon deleted.'));
     } elseif (core::post('custom') != NULL or core::request('coupon') != NULL or Session::instance()->get('coupon') != '') {
         $slug_coupon = new Model_Coupon();
         $coupon = $slug_coupon->where('name', '=', core::post('custom', core::request('coupon', Session::instance()->get('coupon'))))->where('number_coupons', '>', 0)->where('valid_date', '>', Date::unix2mysql())->where('status', '=', 1)->limit(1)->find();
         if ($coupon->loaded()) {
             //only add it to session if its different than before
             if (Session::instance()->get('coupon') != $coupon->name) {
                 Alert::set(Alert::SUCCESS, __('Coupon added!'));
                 Session::instance()->set('coupon', $coupon->name);
             }
         } else {
             Alert::set(Alert::INFO, __('Coupon not valid, expired or already used.'));
             Session::instance()->set('coupon', '');
         }
     }
     return $coupon;
 }
示例#11
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>";
     }
 }
示例#12
0
            <?php 
        echo sprintf(__('Discount off %s'), Model_Coupon::current()->discount_amount == 0 ? round(Model_Coupon::current()->discount_percentage, 0) . '%' : i18n::money_format(Model_Coupon::current()->discount_amount));
        ?>
<br>
            <?php 
        echo sprintf(__('%s coupons left'), Model_Coupon::current()->number_coupons);
        ?>
, <?php 
        echo sprintf(__('valid until %s'), Date::format(Model_Coupon::current()->valid_date, core::config('general.date_format')));
        ?>
.
            <?php 
        if (Model_Coupon::current()->id_product != NULL) {
            ?>
                <?php 
            echo sprintf(__('only valid for %s'), Model_Order::product_desc(Model_Coupon::current()->id_product));
            ?>
            <?php 
        }
        ?>
        </p>
    <?php 
    } else {
        ?>
    <div class="form-group">
        <div class="input-group">
            <input class="form-control" type="text" name="coupon" value="<?php 
        echo Core::get('coupon');
        echo Core::get('coupon');
        ?>
" placeholder="<?php 
示例#13
0
 <?php 
        echo Date::format(Model_Coupon::current()->valid_date);
        ?>
.
            <?php 
        if (Model_Coupon::current()->id_product != NULL) {
            ?>
                <?php 
            echo __('only valid for');
            ?>
  <a target="_blank" href="<?php 
            echo Route::url('product', array('seotitle' => Model_Coupon::current()->product->seotitle, 'category' => Model_Coupon::current()->product->category->seoname));
            ?>
">
                        <?php 
            echo Model_Coupon::current()->product->title;
            ?>
</a>.
            <?php 
        }
        ?>
        </p>
    <?php 
    } else {
        ?>
    <div class="form-group">
        <input class="form-control" type="text" name="coupon" value="<?php 
        echo Core::get('coupon');
        echo Core::get('coupon');
        ?>
" placeholder="<?php 
示例#14
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()));
 }
示例#15
0
 /**
  * verifies pricing in an existing order
  * @return void
  */
 public function check_pricing()
 {
     //original coupon so we dont lose it while we do operations
     $orig_coupon = $this->id_coupon;
     //remove the coupon forced by get/post
     if (core::request('coupon_delete') != NULL) {
         $this->id_coupon = NULL;
     } elseif ($this->product->valid_coupon() and $this->id_coupon != Model_Coupon::current()->id_coupon) {
         $this->id_coupon = Model_Coupon::current()->id_coupon;
     } elseif ($this->coupon->loaded() and (Date::mysql2unix($this->coupon->valid_date) < time() or $this->coupon->status == 0 or $this->coupon->number_coupons == 0)) {
         Alert::set(Alert::INFO, __('Coupon not valid, expired or already used.'));
         $this->coupon->clear();
         $this->id_coupon = NULL;
     }
     $user = $this->user;
     //recalculate price since it change the coupon or user info
     if ($orig_coupon != $this->id_coupon or $this->country != $user->country or $this->city != $user->city or $this->VAT_number != $user->VAT_number or $this->postal_code != $user->postal_code or $this->address != $user->address) {
         //set variables just in case...
         $this->amount = $this->product->final_price();
         $this->VAT = euvat::vat_percentage();
         $this->VAT_number = $user->VAT_number;
         $this->country = $user->country;
         $this->city = $user->city;
         $this->postal_code = $user->postal_code;
         $this->address = $user->address;
         try {
             $this->save();
         } catch (Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
     }
 }