/** * returns the current affiliate user * @return Model_User */ public static function current() { //we don't have so let's retrieve if (self::$_current === NULL) { self::$_current = self::get_affiliate(); } return self::$_current; }
/** * 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'); } }
/** * ads a new hit in visits DB and counts how many visits has * @return integer count */ public function count_hit() { if (!Model_Visit::is_bot() and $this->loaded() and core::config('product.count_visits') == 1) { //adding a visit only if not the owner if (!Auth::instance()->logged_in()) { $visitor_id = NULL; } else { $visitor_id = Auth::instance()->get_user()->id_user; } //adding affiliate if any $id_affiliate = NULL; if (Model_Affiliate::current()->loaded()) { $id_affiliate = Model_Affiliate::current()->id_user; } //new visit if not owner nad not bot if ($this->id_user != $visitor_id) { $new_hit = DB::insert('visits', array('id_product', 'id_user', 'id_affiliate', 'ip_address'))->values(array($this->id_product, $visitor_id, $id_affiliate, ip2long(Request::$client_ip)))->execute(); } //count how many visits has $hits = new Model_Visit(); return $hits->where('id_product', '=', $this->id_product)->count_all(); } return 0; }
', 'price': '<?php echo round($order->product->price, 2); ?> ', 'quantity': 1 }); // Transaction level information is provided via an actionFieldObject. ga('ec:setAction', 'purchase', { 'id': '<?php echo $order->id_order; ?> ', 'affiliation': '<?php echo Model_Affiliate::current()->loaded() ? Model_Affiliate::current()->id_user : ''; ?> ', 'revenue': '<?php echo round($product_price = 100 * $order->amount / (100 + $order->VAT), 2); ?> ', 'tax': '<?php echo round($order->amount - $product_price, 2); ?> ', 'coupon': '<?php echo is_numeric($order->id_coupon) ? $order->coupon->name : ''; ?> ' // User added a coupon at checkout. });
/** * confirm payment for order * * @param string $id_order [unique indentifier of order] * @param string $txn_id id of the transaction depending on provider */ public function confirm_payment($paymethod = 'paypal', $txn_id = NULL, $pay_date = NULL, $amount = NULL, $currency = NULL) { // update orders if ($this->loaded()) { $product = $this->product; $user = $this->user; $this->status = self::STATUS_PAID; $this->pay_date = $pay_date === NULL ? Date::unix2mysql() : $pay_date; $this->paymethod = $paymethod; $this->txn_id = $txn_id; if ($product->support_days > 0) { $this->support_date = Date::unix2mysql(Date::mysql2unix($this->pay_date) + $product->support_days * 24 * 60 * 60); } if ($amount !== NULL) { $this->amount = $amount; } if ($currency !== NULL) { $this->currency = $currency; } try { $this->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } //if saved delete coupon from session and -- number of coupons. Model_Coupon::sale($this->coupon); //add affiliate commision Model_Affiliate::sale($this, $product); //generate licenses $licenses = Model_License::generate($user, $this, $product); $license = ''; //loop all the licenses to an string if (count($licenses) > 0) { $license = '\\n\\n==== ' . __('Your Licenses') . ' ===='; foreach ($licenses as $l) { $license .= '\\n' . $l->license; } } //download link $download = ''; if ($product->has_file() == TRUE) { $dwnl_link = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'download', 'id' => $this->id_order)); $download = '\\n\\n==== ' . __('Download') . ' ====\\n<a href="' . $dwnl_link . '">' . $dwnl_link . '</a>'; } //theres an expire? 0 = unlimited $expire = ''; $expire_hours = Core::config('product.download_hours'); $expire_times = Core::config('product.download_times'); if (($expire_hours > 0 or $expire_times > 0) and $product->has_file() == TRUE) { if ($expire_hours > 0 and $expire_times > 0) { $expire = sprintf(__('Your download expires in %u hours and can be downloaded %u times.'), $expire_hours, $expire_times); } elseif ($expire_hours > 0) { $expire = sprintf(__('Your download expires in %u hours.'), $expire_hours); } elseif ($expire_times > 0) { $expire = sprintf(__('Can be downloaded %u times.'), $expire_times); } $expire = '\\n' . $expire; } //param for sale email $params = array('[DATE]' => $this->pay_date, '[ORDER.ID]' => $this->id_order, '[USER.NAME]' => $user->name, '[USER.EMAIL]' => $user->email, '[PRODUCT.TITLE]' => $product->title, '[PRODUCT.PRICE]' => i18n::format_currency($this->amount, $this->currency), '[PRODUCT.NOTES]' => Text::bb2html($product->email_purchase_notes, TRUE, FALSE, FALSE), '[DOWNLOAD]' => $download, '[EXPIRE]' => $expire, '[LICENSE]' => $license); //send email with order details download link and product notes $user->email('new-sale', $params); //notify to seller if (core::config('email.new_sale_notify')) { Email::send(core::config('email.notify_email'), '', 'New Sale! ' . $product->title, 'New Sale! ' . $product->title, core::config('email.notify_email'), ''); } return TRUE; } return FALSE; }