Example #1
0
 /**
  * Upload a file to the wiki via AJAX
  *
  * @return     string
  */
 public function ajaxRemoveTask()
 {
     // Check for request forgeries
     Request::checkToken(array('get', 'post')) or jexit('Invalid Token');
     // Ensure we have an ID to work with
     $id = Request::getInt('id', 0);
     if (!$id) {
         echo json_encode(array('error' => Lang::txt('COM_STOREFRONT_ERROR_NO_ID')));
         return;
     }
     $type = strtolower(Request::getWord('type', ''));
     $imgId = Request::getVar('currentfile', '');
     // Instantiate a model, change some info and save
     switch ($type) {
         case 'product':
             $object = new Product($id);
             $object->removeImage($imgId);
             break;
         case 'collection':
             $object = new Collection($id);
             $object->removeImage($imgId);
             break;
         default:
             echo json_encode(array('error' => Lang::txt('COM_STOREFRONT_ERROR_INVALID_TYPE')));
             return;
             break;
     }
     if (!$object->save()) {
         echo json_encode(array('error' => 'Error saving object'));
         return;
     }
     //echo result
     echo json_encode(array('success' => true, 'file' => '', 'id' => $id, 'size' => 0, 'width' => 0, 'height' => 0));
 }
Example #2
0
 /**
  * Save a collection
  *
  * @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');
     // Get the collection
     $collection = new Collection($fields['cId']);
     try {
         if (isset($fields['cName'])) {
             $collection->setName($fields['cName']);
         }
         if (isset($fields['state'])) {
             $collection->setActiveStatus($fields['state']);
         }
         if (isset($fields['alias'])) {
             $collection->setAlias($fields['alias']);
         }
         $collection->setType('category');
         // Make sure there are no integrity issues TODO: move the integrity check to the collection verify method (same as SKU)
         $collection->save();
     } catch (\Exception $e) {
         \Notify::error($e->getMessage());
         $this->editTask($collection);
         return;
     }
     if ($redirect) {
         // Redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_STOREFRONT_COLLECTION_SAVED'));
         return;
     }
     $this->editTask($collection);
 }