如何从Magento获取类别列表? [英] How to get a category listing from Magento?

查看:96
本文介绍了如何从Magento获取类别列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Magento中创建一个页面,以可视化方式显示类别..示例

I want to create a page in Magento that shows a visual representation of the categories.. example

CATEGORY
 product 1
 product 2

ANOTHER CATEGORY
 product 3

我的问题是,他们的数据库的组织结构与我过去所看到的完全不同.他们有专用于数据类型(如varchar,int等)的表.我认为这是出于性能或类似目的.

My problem is, their database is organised very differently to what I've seen in the past. They have tables dedicated to data types like varchar, int, etc. I assume this is for performance or similar.

我还没有找到一种使用MySQL查询数据库并获取类别列表的方法.然后,我想将这些类别与产品进行匹配,以获取每个类别的产品清单.不幸的是,Magento似乎很难做到这一点.

I haven't found a way to use MySQL to query the database and get a list of categories. I'd then like to match these categories to products, to get a listing of products for each category. Unfortunately Magento seems to make this very difficult.

我还没有找到一种可在页面块内使用的方法..我创建了Showcase.phtml并将其放在XML布局中,并显示并运行其PHP代码.我希望可以轻松地进行一些操作,例如循环遍历$this->getAllCategories(),然后在内部进行嵌套循环,例如进行$category->getChildProducts().

Also I have not found a method that will work from within a page block.. I have created showcase.phtml and put it in the XML layout and it displays and runs its PHP code. I was hoping for something easy like looping through $this->getAllCategories() and then a nested loop inside with something like $category->getChildProducts().

有人可以帮助我吗?

推荐答案

从与SEO相关的类(Mage_Catalog_Block_Seo_Sitemap_Category)中找到的代码

From code found in an SEO related class (Mage_Catalog_Block_Seo_Sitemap_Category)

$helper     = Mage::helper('catalog/category');
$collection = $helper->getStoreCategories('name', true, false);
$array      = $helper->getStoreCategories('name', false, false);

试着忘记这是一个为商店提供动力的数据库,而是专注于使用Magento系统提供的对象.

Try to forget that it's a database that's powering your store, and instead concentrate on using the objects that the Magento system provides.

例如,我不知道如何获取类别列表.但是,我使用

遍历了Mage代码库

For example, I had no no idea how to get a list of categories. However, I grepped through the Mage codebase with

grep -i -r -E 'class.+?category'

哪个返回了大约30个班级的清单.滚动浏览这些对象,相对容易地猜测哪些对象可能具有方法或需要进行将捕获类别的方法调用.

Which returned a list of around 30 classes. Scrolling through those, it was relatively easy to guess which objects might have methods or need to make method calls that would grab the categories.

这篇关于如何从Magento获取类别列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆