/** * Sets the state of one or more entries * * @return void */ public function stateTask() { // Check for request forgeries Request::checkToken('get'); $id = Request::getInt('id', 0, 'get'); switch ($this->_task) { case 'publish': case 'unpublish': $publish = $this->_task == 'publish' ? 1 : 0; // Check for an ID if (!$id) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_STORE_ALERT_SELECT_ITEM') . ' ' . ($publish == 1 ? 'published' : 'unpublished'), 'error'); return; } // Update record(s) $obj = new Store($this->database); $obj->load($id); $obj->published = $publish; if (!$obj->store()) { throw new Exception($obj->getError(), 500); } // Set message if ($publish == '1') { Notify::success(Lang::txt('COM_STORE_MSG_ITEM_ADDED')); } else { if ($publish == '0') { Notify::success(Lang::txt('COM_STORE_MSG_ITEM_DELETED')); } } break; case 'available': case 'unavailable': $avail = $this->_task == 'available' ? 1 : 0; // Check for an ID if (!$id) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_STORE_ALERT_SELECT_ITEM') . ' ' . ($avail == 1 ? 'available' : 'unavailable'), 'error'); return; } // Update record(s) $obj = new Store($this->database); $obj->load($id); $obj->available = $avail; if (!$obj->store()) { throw new Exception($obj->getError(), 500); } // Set message if ($avail == '1') { Notify::success(Lang::txt('COM_STORE_MSG_ITEM_AVAIL')); } else { if ($avail == '0') { Notify::success(Lang::txt('COM_STORE_MSG_ITEM_UNAVAIL')); } } break; } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false)); }
/** * Display the items in a user's shopping cart * * @return void */ public function cartTask() { // Need to login to view cart if (User::isGuest()) { $this->loginTask(); return; } $this->view->setLayout('cart'); // Set page title $this->_buildTitle(); // Set the pathway $this->_buildPathway(); $this->view->infolink = $this->infolink; $this->view->msg = ''; // Check if economy functions are unavailable $upconfig = Component::params('com_members'); if (!$upconfig->get('bankAccounts')) { $this->view->rows = 0; $this->view->funds = 0; $this->view->cost = 0; $this->view->setError(Lang::txt('COM_STORE_MSG_STORE_CLOSED')); $this->view->display(); return; } // Incoming $this->view->action = Request::getVar('action', ''); $this->view->id = Request::getInt('item', 0); // Check if item exists $purchasetype = ''; if ($this->view->id) { $objStore = new Store($this->database); $iteminfo = $objStore->getInfo($this->view->id); if (!$iteminfo) { $this->view->id = 0; } else { $purchasetype = $this->_getPurchaseType($iteminfo[0]->type); } } // Get cart object $item = new Cart($this->database); switch ($this->view->action) { case 'add': // Check if item is already there, then update quantity or save new $found = $item->checkCartItem($this->view->id, User::get('id')); if (!$found && $this->view->id) { $item->itemid = $this->view->id; $item->uid = User::get('id'); $item->type = $purchasetype; $item->added = \Date::toSql(); $item->quantity = 1; $item->selections = ''; // store new content if (!$item->store()) { throw new Exception($item->getError(), 500); } $this->view->msg = Lang::txt('COM_STORE_MSG_ADDED_TO_CART'); } break; case 'update': // Update quantaties and selections $item->saveCart(array_map('trim', $_POST), User::get('id')); break; case 'remove': // Update quantaties and selections if ($this->view->id) { $item->deleteCartItem($this->view->id, User::get('id')); } break; case 'empty': // Empty all $item->deleteCartItem('', User::get('id'), 'all'); break; default: // Do nothing break; } // Check available user funds $BTL = new Teller(User::get('id')); $balance = $BTL->summary(); $credit = $BTL->credit_summary(); $funds = $balance - $credit; $this->view->funds = $funds > 0 ? $funds : 0; // Calculate total $this->view->cost = $item->getCartItems(User::get('id'), 'cost'); // Get cart items $this->view->rows = $item->getCartItems(User::get('id')); // Output HTML foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->display(); }