/** * 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), $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 $pId) { // Save product try { $product = new Product($pId); $product->setActiveStatus($state); $product->save(); } 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 = 'Product could not be ' . $action; if (sizeof($ids) > 1) { $message = 'Some products could not be ' . $action; } $type = 'error'; } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller), $message, $type); }