/** * Display a list of all collections * * @return void */ public function displayTask() { // Get filters $this->view->filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'title'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int')); //print_r($this->view->filters); $obj = new Archive(); // Get record count $this->view->total = $obj->collections('count', $this->view->filters); // Get records $this->view->rows = $obj->collections('list', $this->view->filters); //print_r($this->view->rows); die; // Set any errors if ($this->getError()) { foreach ($this->getErrors() as $error) { $this->view->setError($error); } } // Output the HTML //print_r($this->view); die; $this->view->display(); }
/** * Set the state of an entry * * @param integer $state State to set * @return void */ public function stateTask($state = 0) { $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; //print_r($ids); die; // Check for an ID if (count($ids) < 1) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $state == 1 ? Lang::txt('COM_STOREFRONT_SELECT_PUBLISH') : Lang::txt('COM_STOREFRONT_SELECT_UNPUBLISH'), 'error'); return; } // Update record(s) $obj = new Archive(); foreach ($ids as $ogId) { // Save category try { $obj->updateOptionGroup($ogId, array('state' => $state)); } catch (\Exception $e) { \Notify::error($e->getMessage()); return; } } // Set message switch ($state) { case '-1': $message = Lang::txt('COM_STOREFRONT_ARCHIVED', count($ids)); break; case '1': $message = Lang::txt('COM_STOREFRONT_PUBLISHED', count($ids)); break; case '0': $message = Lang::txt('COM_STOREFRONT_UNPUBLISHED', count($ids)); break; } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $message); }
/** * Save a product * * @param boolean $redirect Redirect the page after saving * @return void */ public function saveTask($redirect = true) { // Check for request forgeries Request::checkToken() or jexit('Invalid Token'); // Incoming $fields = Request::getVar('fields', array(), 'post'); $obj = new Archive(); // Save product try { $obj->setProductMeta($fields['pId'], $fields); } catch (\Exception $e) { \Notify::error($e->getMessage()); // Get the product $product = $obj->product($fields['pId']); $this->editTask($product); return; } if ($redirect) { // Redirect $this->setRedirect('index.php?option=' . $this->_option . '&controller=products&task=edit&id=' . Request::getInt('id', 0), Lang::txt('COM_STOREFRONT_PRODUCT_SAVED')); return; } // Get the product $product = $obj->product($fields['pId']); $this->editTask($product); }
/** * Remove an entry * * @return void */ public function removeTask() { // Incoming $step = Request::getInt('step', 1); $step = !$step ? 1 : $step; // What step are we on? switch ($step) { case 1: Request::setVar('hidemainmenu', 1); // Incoming $id = Request::getVar('id', array(0)); if (!is_array($id) && !empty($id)) { $id = array($id); } $this->view->pIds = $id; // Set any errors if ($this->getError()) { $this->view->setError($this->getError()); } // Output the HTML $this->view->display(); break; case 2: // Check for request forgeries Request::checkToken() or jexit('Invalid Token'); // Incoming $pIds = Request::getVar('pIds', 0); //print_r($sId); die; // Make sure we have IDs to work with if (empty($pIds)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller), Lang::txt('COM_STOREFRONT_NO_ID'), 'error'); return; } $delete = Request::getVar('delete', 0); $msg = "Delete canceled"; $type = 'error'; if ($delete) { // Do the delete $obj = new Archive(); foreach ($pIds as $pId) { // Delete SKU try { $product = $obj->product($pId); $product->delete(); } catch (\Exception $e) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=dispaly&id=' . $pId), $e->getMessage(), $type); return; } } $msg = "Product(s) deleted"; $type = 'message'; } // Set the redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=dispaly&id=' . $pId), $msg, $type); break; } }
/** * Set the state of an entry * * @param integer $state State to set * @return void */ public function stateTask($state = 0) { $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; $pId = Request::getVar('pId', 0); // Check for an ID if (count($ids) < 1) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $state == 1 ? Lang::txt('COM_STOREFRONT_SELECT_PUBLISH') : Lang::txt('COM_STOREFRONT_SELECT_UNPUBLISH'), 'error'); return; } // Update record(s) $obj = new Archive(); foreach ($ids as $sId) { // Save SKU try { $sku = Sku::getInstance($sId); $obj->updateSku($sku, array('state' => $state)); } catch (\Exception $e) { $error = true; } } // Set message switch ($state) { case '-1': $message = Lang::txt('COM_STOREFRONT_ARCHIVED', count($ids)); break; case '1': $message = Lang::txt('COM_STOREFRONT_PUBLISHED', count($ids)); break; case '0': $message = Lang::txt('COM_STOREFRONT_UNPUBLISHED', count($ids)); break; } $type = 'message'; if (isset($error) && $error) { switch ($state) { case '1': $action = 'published'; break; case '0': $action = 'unpublished'; break; } $message = 'SKU could not be ' . $action; if (sizeof($ids) > 1) { $message = 'Some SKUs could not be ' . $action; } $type = 'error'; } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=display&id=' . $pId, false), $message, $type); }
/** * Save a product * * @param boolean $redirect Redirect the page after saving * @return void */ public function saveTask($redirect = true) { // Check for request forgeries Request::checkToken() or jexit('Invalid Token'); // Incoming $fields = Request::getVar('fields', array(), 'post'); $obj = new Archive(); // Get the product $product = $obj->product($fields['pId']); $meta = $fields; unset($meta['pId']); // Save product meta $product->setMeta($meta); if ($redirect) { // Redirect $this->setRedirect('index.php?option=' . $this->_option . '&controller=products&task=edit&id=' . Request::getInt('id', 0), Lang::txt('COM_STOREFRONT_PRODUCT_SAVED')); return; } $this->editTask($product); }