Question

Is it possible to define the category by id on the admin product page?

The idea is to capture the category by id (previously registered) and not by name. I found these codes to change that are responsible for that function:

admin/model/catalog/product.php

public function getProductCategories($product_id) {
  $product_category_data = array();

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

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

  return $product_category_data;

}

admin/controller/catalog/product.php

// Categories
  $this->load->model('catalog/category');

  if (isset($this->request->post['product_category'])) {
     $categories = $this->request->post['category_id'];
  } elseif (isset($this->request->get['product_id'])) {      
     $categories = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
  } else {
     $categories = array();
  }

  $this->data['product_categories'] = array();

  foreach ($categories as $category_id) {
     $category_info = $this->model_catalog_category->getCategory($category_id);

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

admin/view/template/catalog/product_form.tpl

<tr>
          <td><?php echo $entry_category; ?></td>
          <td><input type="text" name="category" value="" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><div id="product-category" class="scrollbox">
              <?php $class = 'odd'; ?>
              <?php foreach ($product_categories as $product_category) { ?>
              <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
              <div id="product-category<?php echo $product_category['category_id']; ?>" class="<?php echo $class; ?>"><?php echo $product_category['name']; ?><img src="view/image/delete.png" alt="" />
                <input type="hidden" name="product_category[]" value="<?php echo $product_category['category_id']; ?>" />
              </div>
              <?php } ?>
            </div></td>
        </tr>

The problem is that I am not good in php and I don't know where I change to get that results. Thank you for some help or idea!

Was it helpful?

Solution

if (!empty($data['filter_name'])) { $sql .= " AND cp.category_id LIKE '" . $this->db->escape($data['filter_name']) . "%'";

line 211 in admin/model/catalog/category.php

I found the solution for my question, however it doesn't solved my problem. Thank everyone for help me!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top