/** * decreases de number available of coupon and deletes de cookie ;) * @param model_coupon $coupon * @return void */ public static function sale(Model_Coupon $coupon = NULL) { if ($coupon === NULL) { $coupon = Model_Coupon::current(); } if ($coupon->loaded()) { $coupon->number_coupons--; try { $coupon->save(); } catch (ORM_Validation_Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } Session::instance()->set('coupon', ''); } }
/** * 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'); } }
/** * 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); } } }
/** * 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; }
/** * 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'); } }
/** * 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()); } } }
/** * 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; }
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');
<?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
<?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
/** * 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()); } } }