/** * Display a user's cart */ public function read() { $id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum'); $user_id = $this->input->get('user_id', '', 'alnum'); // check, if we're not forcing user to view a certain cart (i. e. after they click on link in email) if (!empty($id)) { $cart = (new \Shop\Models\Carts())->setState('filter.id', $id)->getItem(); if (empty($cart)) { // this cart does not exist so let's not disclose that to people. rather, we say the cart is empty (which is true) $this->app->reroute('/shop/cart'); return; } $identity = $this->getIdentity(); if (empty($identity->id)) { $token = $this->input->get('auto_login_token', '', 'alnum'); if (empty($user_id) || empty($token)) { \Dsc\System::instance()->get('session')->set('site.login.redirect', '/shop/cart'); $this->app->reroute('/sign-in'); } else { // try to auto log in user $notification_idx = $this->input->get("idx", 0, 'int'); $this->auth->loginWithToken($user_id, $token, '/shop/cart?email=1&user_id=' . $user_id . '&idx=' . $notification_idx); } } else { if ((string) $cart->user_id != (string) $identity->id) { $this->app->reroute('/shop/cart'); return; } } } $referal_email = $this->input->get("email", 0, 'int'); if ($referal_email) { $identity = $this->getIdentity(); if ($identity->id == $user_id) { // only if the right user is logged in $notification_idx = $this->input->get("idx", 0, 'int'); \Dsc\Activities::track('User clicked on link in abandoned cart email', array('Notification' => $notification_idx)); \Dsc\System::instance()->get('session')->set('shop.notification_email', 1); } $this->app->reroute('/shop/cart'); return; } $cart = \Shop\Models\Carts::fetch(); // Update product fields stored in cart foreach ($cart->validateProducts() as $change) { \Dsc\System::addMessage($change); } $cart->applyCredit(); \Base::instance()->set('cart', $cart); $this->app->set('meta.title', 'Shopping Cart'); \Shop\Models\Activities::track('Viewed Cart', array('cart_id' => (string) $cart->id)); $view = \Dsc\System::instance()->get('theme'); echo $view->renderTheme('Shop/Site/Views::cart/read.php'); }
/** * Gets paginated results from a source */ protected function filteredSearch() { $current_source = array('id' => 'invalid', 'title' => ''); $paginated = null; $q = trim($this->input->get('q', null, 'default')); try { if (!empty($q)) { $current_source = \Search\Models\Source::current(); $paginated = \Search\Models\Source::paginate($current_source, $q); \Dsc\Activities::track('Performed Search', array('Search Term' => $q, 'Search Source' => $current_source['title'], 'page_number' => $paginated->current_page, 'app' => 'search')); } } catch (\Exception $e) { \Dsc\System::addMessage($e->getMessage(), 'error'); } $this->app->set('current_source', $current_source); $this->app->set('paginated', $paginated); $this->app->set('q', $q); $this->app->set('meta.title', trim('Search ' . $current_source['title'])); echo $this->theme->render('Search/Site/Views::search/index.php'); }
public static function track($action, $properties = array()) { $action_properties = $properties + array('app' => 'pages'); return parent::track($action, $action_properties); }