Để lấy dữ liệu danh mục Magento trực tiếp từ cơ sở dữ liệu, tôi sử dụng:
select
   p.entity_id  as entity_id,
   if(pp.level = 1,
      n.value,
      concat_ws (' / ', pn.value, n.value)) as name,
   date(p.created_at) as created_at
from
   catalog_category_entity p
   -- name
   left join catalog_category_entity_varchar n on
      p.entity_id = n.entity_id and n.attribute_id = 41
   -- status
   left join catalog_category_entity_int s on
      p.entity_id = s.entity_id and s.attribute_id = 42 and
      s.store_id = 0
   -- parent
   left join catalog_category_entity pp on p.parent_id = pp.entity_id
   -- parent name
   left join catalog_category_entity_varchar pn on
      pp.entity_id = pn.entity_id and pn.attribute_id = 41 and
      pn.store_id = 0
where
   s.value = 1 and -- status is active
   p.level >= 2 
order by
   2
;
Attribution_ids khác nhau từ hệ thống đến hệ thống. Ở đây tôi đang sử dụng 41 và 42.
Để xác định thuộc tính_ids chính xác cho tên danh mục và trạng thái danh mục từ trang Magento, tôi sử dụng:
select
   p.entity_id,
   a.attribute_id,
   a.frontend_label as attribute,
   av.value
from
   catalog_category_entity p
   left join catalog_category_entity_{datatype} av on
      p.entity_id = av.entity_id
   left join eav_attribute a on
      av.attribute_id = a.attribute_id
where
   p.entity_id = {eid}
;
Bằng cách thay thế {datatype} bằng 'varchar', bạn có thể lấy thuộc tính_id cho tên danh mục và với 'int' để lấy thuộc tính_id cho trạng thái danh mục. Bạn có thể thay thế {eid} cho bất kỳ danh mục entity_id.
Điều này có thể được thực hiện trong một trình soạn thảo hoặc trên dòng lệnh với sed như vậy:
Giả sử wdb là một bí danh được đặt cho kết nối cơ sở dữ liệu mysql trang web của bạn như thế này:
alias wdb='mysql -h<hostname> -u<username> -p<password> <databasename>'
Sau đó bạn có thể chạy
$ cat show_category_attr.sql | sed -e "s/{datatype}/varchar/" -e "s/{eid}/2/" | wdb -t
Và lấy
+-----------+--------------+--------------+------------------+
| entity_id | attribute_id | attribute    | value            |
+-----------+--------------+--------------+------------------+
|         2 |           41 | Name         | Default Category |
|         2 |           49 | Display Mode | PRODUCTS         |
+-----------+--------------+--------------+------------------+
Và chạy
$ cat show_category_attr.sql | sed -e "s/{datatype}/int/" -e "s/{eid}/2/"| wdb -t
Và lấy
+-----------+--------------+----------------------------+-------+
| entity_id | attribute_id | attribute                  | value |
+-----------+--------------+----------------------------+-------+
|         2 |           42 | Is Active                  |     1 |
|         2 |           67 | Include in Navigation Menu |     1 |
+-----------+--------------+----------------------------+-------+
Ở đây bạn có thể thấy các số cần thiết 41 và 42.
Kỹ thuật tương tự có thể được sử dụng cho các sản phẩm Magento.