php - 在 Magento 中获取包含详细信息的所有类别的数组

标签 php magento e-commerce

我希望能够通过 API 调用以获取所有类别的数组以及 URL 键等详细信息。最终的目标将是这样的数组

$massage_cats=array(
    array("entity_id"=>78,
          "name"=>"Massage Oils and Tools",
          "url_key"=>"massage-oils-and-tools",
          "url_path"=>"essential-accessories/massage-oils-and-tools.html"),
    array("entity_id"=>79,
          "name"=>"Massage Oils",
          "url_key"=>"massage-oils",
          "url_path"=>"essential-accessories/massage-oils-and-tools/massage-oils.html")
);

所以我想喊出类似的东西

$massage_cats= array();
$allcats = Mage::getModel('catalog/cats?')->loadAll();
    foreach($allcats $k=>$item){
        array_push($massage_cats,$item->loadDetails());
    }

我知道这完全是虚构的,对 API 来说不是真实的,但这基本上是目标。我确实需要我展示的输出。实现需求的代码思路?

最佳答案

这将获得您的值(value)观。您可以从这里随意构建阵列。

$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url')
->addAttributeToSelect('is_active');

foreach ($categories as $category)
{
    if ($category->getIsActive()) { // Only pull Active categories
        $entity_id = $category->getId();
        $name = $category->getName();
        $url_key = $category->getUrlKey();
        $url_path = $category->getUrl();
    }
}

编辑

我改编自 MagentoCommerce.com 上的一篇文章.您可以改用它:

$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
if ($ids){
    foreach ($ids as $id){
        $cat = Mage::getModel('catalog/category');
        $cat->load($id);

        $entity_id = $cat->getId();
        $name = $cat->getName();
        $url_key = $cat->getUrlKey();
        $url_path = $cat->getUrlPath();
    }
}

关于php - 在 Magento 中获取包含详细信息的所有类别的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9448169/

相关文章:

php - 实时合并 MP3 时的 ID3 标签,使用 PHP 和 HTTP 部分内容

php - Symfony3 项目中的 POMM2,注册转换器时遇到问题

magento - getAllVisibleItems(), getAllItems 两次返回项目

mysql - 如何破译这个mysql数据的结构?

c# - 如何按格式转换价格

ruby-on-rails - Rails 应用程序中的参数可能缺少值

php - SQL注入(inject)攻击——使用mysqli_multi_query()

php - 在 content-product.php 上更改 woocommerce 中的产品链接

magento - 如何在 Mgt 开发环境中使用带有自签名证书的 HTTPS/SSL

订购页面 : "This customer email already exists" 上的 Magento