示例#1
0
 /**
  * Insert or update a ShopCategory with data provided in the request.
  * @return  boolean                 True on success, null on noop,
  *                                  false otherwise.
  * @author  Reto Kohli <*****@*****.**> (parts)
  */
 function store_category()
 {
     global $_ARRAYLANG;
     if (empty($_POST['bcategory'])) {
         //DBG::log("store_category(): Nothing to do");
         return null;
     }
     $category_id = intval($_POST['category_id']);
     $name = contrexx_input2raw($_POST['name']);
     $active = isset($_POST['active']);
     $virtual = isset($_POST['virtual']);
     $parentid = intval($_POST['parent_id']);
     $picture = contrexx_input2raw($_POST['image_href']);
     $long = contrexx_input2raw($_POST['desc']);
     $objCategory = null;
     if ($category_id > 0) {
         // Update existing ShopCategory
         $objCategory = ShopCategory::getById($category_id);
         if (!$objCategory) {
             return \Message::error(sprintf($_ARRAYLANG['TXT_SHOP_CATEGORY_MISSING'], $category_id));
         }
         // Check validity of the IDs of the category and its parent.
         // If the values are identical, leave the parent ID alone!
         if ($category_id != $parentid) {
             $objCategory->parent_id($parentid);
         }
         $objCategory->name($name);
         $objCategory->description($long);
         $objCategory->active($active);
     } else {
         // Add new ShopCategory
         $objCategory = new ShopCategory($name, $long, $parentid, $active, 0);
     }
     // Ignore the picture if it's the default image!
     // Storing it would be pointless, and we should
     // use the picture of a contained Product instead.
     if ($picture && ($picture == self::$defaultImage || !self::moveImage($picture))) {
         $picture = '';
     }
     $objCategory->picture($picture);
     $objCategory->virtual($virtual);
     if (!$objCategory->store()) {
         return \Message::error($_ARRAYLANG['TXT_SHOP_DATABASE_QUERY_ERROR']);
     }
     if ($picture) {
         //DBG::log("store_category(): Making thumb");
         $objImage = new \ImageManager();
         if (!$objImage->_createThumbWhq(\Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopPath() . '/', \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteImagesShopWebPath() . '/', $picture, \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_width', 'Shop'), \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_max_height', 'Shop'), \Cx\Core\Setting\Controller\Setting::getValue('thumbnail_quality', 'Shop'))) {
             \Message::warning($_ARRAYLANG['TXT_SHOP_ERROR_CREATING_CATEGORY_THUMBNAIL']);
         }
     }
     // Avoid showing/editing the modified ShopCategory again.
     // view_categories() tests the $_REQUEST array!
     unset($_REQUEST['category_id']);
     return \Message::ok($_ARRAYLANG['TXT_SHOP_CATEGORY_STORED_SUCCESSFULLY']);
 }