Ejemplo n.º 1
0
<!--head-->
<script type="text/javascript" src="../js/tinymce/tinymce.min.js"></script>
<!--//head-->
<?php 
if (isset($_POST['sveCMSCategory']) && Tools::getRequest('sveCMSCategory') == 'add') {
    $cmscategory = new CMSCategory();
    $cmscategory->copyFromPost();
    $cmscategory->add();
    if (is_array($cmscategory->_errors) and count($cmscategory->_errors) > 0) {
        $errors = $cmscategory->_errors;
    } else {
        $_GET['id'] = $cmscategory->id;
        echo '<div class="conf">创建分类成功</div>';
    }
}
if (isset($_GET['id'])) {
    $id = (int) $_GET['id'];
    $obj = new CMSCategory($id);
}
if (isset($_POST['sveCMSCategory']) && Tools::getRequest('sveCMSCategory') == 'edit') {
    if (Tools::getRequest('id_parent') == $obj->id) {
        $obj->_errors[] = '父分类不能为当前分类!';
    } elseif (Validate::isLoadedObject($obj)) {
        $obj->copyFromPost();
        $obj->update();
    }
    if (is_array($obj->_errors) and count($obj->_errors) > 0) {
        $errors = $obj->_errors;
    } else {
        echo '<div class="conf">更新分类成功</div>';
    }
Ejemplo n.º 2
0
 public static function create_category($parent, $name, $linkRewrite, $description = '', $meta_title = '', $meta_description = '', $meta_keywords = '')
 {
     $configuration = PS_CLI_CONFIGURE::getConfigurationInstance();
     $category = new CMSCategory();
     if (!Validate::isUnsignedId($parent)) {
         echo "Error, {$parent} is not a valid category ID\n";
         return false;
     }
     $parentCat = new CMSCategory($parent);
     if (!Validate::isloadedObject($parentCat)) {
         echo "Error: category {$parentCat} does not exists\n";
         return false;
     }
     $category->id_parent = $parent;
     if (!Validate::isName($name)) {
         echo "Error, {$name} is not a valid category name\n";
         return false;
     }
     $category->name = array($configuration->lang => $name);
     if (!Validate::isLinkRewrite($linkRewrite)) {
         echo "Error, {$linkRewrite} is not a valid link rewrite\n";
         return false;
     }
     $category->link_rewrite = array($configuration->lang => $linkRewrite);
     if (!Validate::isCleanHtml($description)) {
         echo "Warning, {$description} is not a valid category description\n";
         $description = '';
     }
     $category->description = array($configuration->lang => $description);
     if (!Validate::isGenericName($meta_title)) {
         echo "Warning, {$meta_title} is not a valid value for meta_title\n";
         $meta_title = '';
     }
     $category->meta_title = array($configuration->lang => $meta_title);
     if (!Validate::isGenericName($meta_description)) {
         echo "Warning, {$meta_description} is not a valid value for meta_description\n";
         $meta_description = '';
     }
     $category->meta_description = array($configuration->lang => $meta_description);
     if (!Validate::isGenericName($meta_keywords)) {
         echo "Warning, {$meta_keywords} is not a valid value for meta_keywords\n";
         $meta_keywords = '';
     }
     $category->meta_keywords = array($configuration->lang => $meta_keywords);
     if ($category->add()) {
         if ($configuration->porcelain) {
             echo $category->id_cms_category;
         } else {
             echo "Successfully created category {$category->id_cms_category}\n";
         }
         return true;
     } else {
         echo "Error, could not create category {$name}\n";
         return false;
     }
 }
 protected function importCMSCategories()
 {
     $this->truncateTables(array('cms_category', 'cms_category_lang', 'cms_category_shop'));
     $handle = $this->openCsvFile('cms_categories.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('CMSCategory', $this->cms_category_fields, $line);
         if (!isset($fields['id'])) {
             $cms_cat = new CMSCategory((int) $line[0]);
             $cms_cat->id = $line[0];
         } else {
             $cms_cat = new CMSCategory((int) $fields['id']);
         }
         foreach ($fields as $key => $field) {
             if ($key == 'name' || $key == 'description' || $key == 'meta_keywords' || $key == 'meta_description' || $key == 'link_rewrite') {
                 $cms_cat->{$key} = $this->multilFild($field);
             } else {
                 $cms_cat->{$key} = $field;
             }
         }
         $cms_cat->force_id = 1;
         if (!$res) {
             $cms_cat->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }