Jump to content
Sign in to follow this  
gagarin79

Возможность выбора нескольких родительских категорий в каталоге

Recommended Posts

Добрый день.

 

Коллеги, подскажите, есть ли модуль, позволяющий присваивать несколько родительских категорий для одной подкатегории в структуре каталога?

Share this post


Link to post
Share on other sites

На сколько я знаю есть модуль - multi parent category: http://www.opencart.com/index.php?route=extension/extension/info&extension_id=18829&filter_search=parent%20category

но здесь я его не встречал. Тоже бы приобрел такой модуль.

автор возможно буржуй, а значит этот модуль ожидать здесь бесполезно.

модуль по ссылке не факт что нормально станет на ocstore, т.к. сделан под opencart.

Share this post


Link to post
Share on other sites

автор возможно буржуй, а значит этот модуль ожидать здесь бесполезно.

модуль по ссылке не факт что нормально станет на ocstore, т.к. сделан под opencart.

Почему бесполезно? Тут половина форума написать его может

Share this post


Link to post
Share on other sites

Почему бесполезно? Тут половина форума написать его может

потому что стоит перечитать мое сообщение. я не про написать, а про конкретный модуль, который собрались ждать тут.

Share this post


Link to post
Share on other sites

нашел решение - но оно под 2.0 не знаю, реально ли реализовать для 1.5..

STEP 1;- Create Table. "oc_category_multiparen"

CREATE TABLE IF NOT EXISTS `oc_category_multiparent` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL,
  `parent_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


STEP 2:-  update oc_category set parent_id=0;


STEP 3:- Change follwoing files as below
   I admin/model/catalog/category.php
      Add new method. as follwing.

 -------------------------------------------
         public function getParentCategories($category_id) {
              //echo " inside getParentCategories".$category_id;
  $parent_category_data = array();

  $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_multiparent WHERE category_id = '" . (int)$category_id . "'");

  foreach ($query->rows as $result) {
   $parent_category_data[] = $result['parent_id'];
  }

  return $parent_category_data;
 }
     
  -------------------------------------
public function getMultipleParentCategories($category_id) {

$query = $this->db->query("SELECT CONCAT( CONCAT( '(', GROUP_CONCAT( cd1.name ORDER BY cp.level SEPARATOR ')(' ) ) , ') >' ) AS parentcategories FROM " . DB_PREFIX . "category_multiparent cmprt LEFT JOIN " . DB_PREFIX . "category_description cd1 ON ( cmprt.parent_id = cd1.category_id ) LEFT JOIN " . DB_PREFIX . "category_path cp ON ( cp.category_id = cmprt.parent_id ) WHERE cmprt.category_id='" . (int)$category_id . "'");            
  
             
  return $query->rows;
 }

--------------------------------
 Inside existing function public function editCategory($category_id, $data) { add follwing code

$this->db->query("DELETE FROM " . DB_PREFIX . "category_multiparent WHERE category_id = '" . (int)$category_id . "'");
                if (isset($data['product_category'])) {
   foreach ($data['product_category'] as $parent_id) {
                            echo "Category parentid". $parent_id;
    $this->db->query("INSERT INTO " . DB_PREFIX . "category_multiparent SET category_id = '" . (int)$category_id . "', parent_id = '" . (int)$parent_id . "'");
   }
  }

================================================
  2. admin/language/english/catalog/category.php
      Add  follwing Lines

    $_['entry_category']         = 'Parent Categories';
    $_['help_category']          = '(Autocomplete)';
==============================================
  3. admin/view/template/catalog/category_form.tpl
      Add  follwing Lines
   ---------------------------------------------------AT html section------------------------
<div class="form-group">
               <label class="col-sm-2 control-label" for="input-category"><span data-toggle="tooltip" title="<?php echo $help_category; ?>"><?php echo $entry_category; ?></span></label>
               <div class="col-sm-10">
                  <input type="text" name="category" value="" placeholder="<?php echo $entry_category; ?>" id="input-category" class="form-control" />
                 <div id="product-category" class="well well-sm" style="height: 150px; overflow: auto;">
                    <?php foreach ($product_categories as $product_category) { ?>
                    <div id="product-category<?php echo $product_category['category_id']; ?>"><i class="fa fa-minus-circle"></i> <?php echo $product_category['name']; ?>
                      <input type="hidden" name="product_category[]" value="<?php echo $product_category['category_id']; ?>" />
                    </div>
                    <?php } ?>
                  </div>
               </div>

              </div>
--------------------------------------------------------following in script section-------------


// Category
$('input[name=\'category\']').autocomplete({
 'source': function(request, response) {
  $.ajax({
   url: 'index.php?route=catalog/category/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request),
   dataType: 'json',   
   success: function(json) {
    response($.map(json, function(item) {
     return {
      label: item['name'],
      value: item['category_id']
     }
    }));
   }
  });
 },
 'select': function(item) {
  $('input[name=\'category\']').val('');


// Category
$('input[name=\'category\']').autocomplete({
 'source': function(request, response) {
  $.ajax({
   url: 'index.php?route=catalog/category/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request),
   dataType: 'json',   
   success: function(json) {
    response($.map(json, function(item) {
     return {
      label: item['name'],
      value: item['category_id']
     }
    }));
   }
  });
 },
 'select': function(item) {
  $('input[name=\'category\']').val('');
  
  $('#product-category' + item['value']).remove();
  
  $('#product-category').append('<div id="product-category' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="product_category[]" value="' + item['value'] + '" /></div>'); 
 }
});
$('#product-category').delegate('.fa-minus-circle', 'click', function() {
 $(this).parent().remove();
});  
  $('#product-category' + item['value']).remove();
  
  $('#product-category').append('<div id="product-category' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="product_category[]" value="' + item['value'] + '" /></div>'); 
 }
});
$('#product-category').delegate('.fa-minus-circle', 'click', function() {
 $(this).parent().remove();
});
=======================================================
 4. admin/controller/catalog/category.php
      Add  follwing Lines in existing method getForm() {
  -----------------------------------------------
$data['entry_category'] = $this->language->get('entry_category');
$data['help_category'] = $this->language->get('help_category');
-----------------------------------------------

 if (isset($this->request->post['product_category'])) {
   $categories = $this->request->post['product_category'];
  } elseif (isset($this->request->get['category_id'])) {
   $categories = $this->model_catalog_category->getParentCategories($this->request->get['category_id']);
  } else {
   $categories = array();
                }
             
                $data['product_categories'] = array();
               foreach ($categories as $category_id) {
                        $category_info = $this->model_catalog_category->getCategory($category_id);

   if ($category_info) {
    $data['product_categories'][] = array(
     'category_id' => $category_info['category_id'],
     'name' => ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name']
    );
   }
  }

------------------------ in Existing method protected function getList() { update following code -------------------------------------foreach ($results as $result) {
                         $multipleCategories = $this->model_catalog_category->getMultipleParentCategories($result['category_id']);
                        // echo $multipleCategories;
   $data['categories'][] = array(
    'category_id' => $result['category_id'],
    'name'        => $multipleCategories[0]['parentcategories'].$result['name'],
    'sort_order'  => $result['sort_order'],
    'edit'        => $this->url->link('catalog/category/edit', 'token=' . $this->session->data['token'] . '&category_id=' . $result['category_id'] . $url, 'SSL'),
    'delete'      => $this->url->link('catalog/category/delete', 'token=' . $this->session->data['token'] . '&category_id=' . $result['category_id'] . $url, 'SSL')
   );
  }
==================================
5. catalog/controller/common/header.php
        replace the following line with the following

 //$children = $this->model_catalog_category->getCategories($category['category_id']);
                      Replace above with the below line In ControllerCommonHeader's  loop section foreach ($categories as $category) {
   if ($category['top']) {
  $children = $this->model_catalog_category->getMultiParentCategories($category['category_id']);
}
------------------------------------
6. catalog/model/catalog/category.php
      Add following new method

   public function getMultiParentCategories($parent_id = 0) {
  $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) LEFT JOIN " . DB_PREFIX . "category_multiparent cmprt ON (c.category_id = cmprt.category_id) WHERE cmprt.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "'  AND c.status = '1' ORDER BY c.sort_order, LCASE(cd.name)");

  return $query->rows;

 }
====================================
 :) MULTI PARENT CATEGORY OPENCART Interation is Done Enjoy :)
Edited by afwollis

Share this post


Link to post
Share on other sites

а как потом определять, которая из родительских категорий родительнейстей?

ну - чисто для исключения дублей для ПС?

Share this post


Link to post
Share on other sites

а как потом определять, которая из родительских категорий родительнейстей?

ну - чисто для исключения дублей для ПС?

дублей не будет, т.к. родительская категория в урл не будет присутствовать

Share this post


Link to post
Share on other sites

Сделала модуль по вышеприведенному решению,  но он подхватывается только родным опенкартовским меню, супер мега меню не видит подкатегорий добавленных этим способом. И в общем списке категорий они тоже не выводятся, 

 

наверно дело в этих пунктах 

 

 

 

5. catalog/controller/common/header.php
        replace the following line with the following

 //$children = $this->model_catalog_category->getCategories($category['category_id']);
                      Replace above with the below line In ControllerCommonHeader's  loop section foreach ($categories as $category) {
if ($category['top']) {
  $children = $this->model_catalog_category->getMultiParentCategories($category['category_id']);

}
------------------------------------
6. catalog/model/catalog/category.php
      Add following new method

   public function getMultiParentCategories($parent_id = 0) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) LEFT JOIN " . DB_PREFIX . "category_multiparent cmprt ON (c.category_id = cmprt.category_id) WHERE cmprt.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "'  AND c.status = '1' ORDER BY c.sort_order, LCASE(cd.name)");

return $query->rows;

}
 
 
но что с ними сделать чтоб в суперменю они тоже были видны?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.