예제 #1
0
 public static function collectionIntegrityCheck($collection)
 {
     $return = new \stdClass();
     $return->status = 'ok';
     $return->errors = array();
     // Check if there are other collections that have the same alias
     try {
         $conflictingCollectionId = \Components\Storefront\Models\Collection::findActiveCollectionByAlias($collection->getAlias());
         if ($conflictingCollectionId && $conflictingCollectionId != $collection->getId()) {
             $return->status = 'error';
             $return->errors[] = 'There is already another collection published with the same alias. Alias must be unique.';
         }
     } catch (\Exception $e) {
         // No conflicting product found (hence, the Exception), good to go.
         return $return;
     }
     return $return;
 }
예제 #2
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));
 }
예제 #3
0
 /**
  * Get a collection
  *
  * @param	int							collection ID
  * @return	StorefrontModelCollection 	Instance of a collection
  */
 public function getCollection($cId)
 {
     $collection = new Collection();
     // Get all product info
     $collectionInfo = $this->getCollectionInfo($cId, true);
     //print_r($collectionInfo); die;
     $collection->setType($collectionInfo->cType);
     $collection->setId($collectionInfo->cId);
     $collection->setName($collectionInfo->cName);
     $collection->setActiveStatus($collectionInfo->cActive);
     $collection->verify();
     return $collection;
 }
예제 #4
0
 /**
  * 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;
     // 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;
     }
     foreach ($ids as $cId) {
         // Save category
         try {
             $collection = new Collection($cId);
             $collection->setActiveStatus($state);
             // Make sure there are no integrity issues
             $this->checkIntegrity($collection);
             $collection->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 = 'Collection could not be ' . $action;
         if (sizeof($ids) > 1) {
             $message = 'Some collection(s) could not be ' . $action;
         }
         $type = 'error';
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $message, $type);
 }