A
A
Andrew2020-08-10 12:24:00
PHP
Andrew, 2020-08-10 12:24:00

How to get custom category image from OpenCart table in admin panel?

The category model file has a function to get a list of names and ids of all categories and subcategories. I am not very strong in MySQL. The code below takes the name from the table, and I also need to get the contents of the cat_icon column.

The most interesting thing is that the code uses 2 tables: category_path and category_description. And the column I'm looking for is in the third table - just "category".

I would be grateful for help.

public function getCategories($data = array()) {
    $sql = "SELECT cp.category_id AS category_id, GROUP_CONCAT(cd1.name ORDER BY cp.level SEPARATOR '  >  ') AS name, c1.parent_id, c1.sort_order FROM " . DB_PREFIX . "category_path cp LEFT JOIN " . DB_PREFIX . "category c1 ON (cp.category_id = c1.category_id) LEFT JOIN " . DB_PREFIX . "category c2 ON (cp.path_id = c2.category_id) LEFT JOIN " . DB_PREFIX . "category_description cd1 ON (cp.path_id = cd1.category_id) LEFT JOIN " . DB_PREFIX . "category_description cd2 ON (cp.category_id = cd2.category_id)  WHERE cd1.language_id = '" . (int)$this->config->get('config_language_id') . "' AND cd2.language_id = '" . (int)$this->config->get('config_language_id') . "'";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VVCh, 2020-08-10
@Don_Andreas

SELECT cp.category_id, c1.image

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question