【问题标题】:Getting All categories in external page获取外部页面中的所有类别
【发布时间】:2010-04-02 05:02:39
【问题描述】:

我猜这是非常基本的 magento 问题。 我想首先获取所有商店类别,然后遍历它们以获取其子类别和产品,并类似地继续直到最后一个子类别。

我将在页面顶部声明 Mage::app() 的外部页面中使用它。我不知道使用 Magento API(如果它们被调用的话)来获取此功能。

请记住,我没有在任何模板中使用它,所以我猜像 getCurrentCategory() 这样的东西在这里不起作用。

另外请指导是否有任何好的资源来搜索magento和API中的特定功能来实现它,或者我注定要通过他们的phpdoc来了解方法列表。

这里的任何帮助将不胜感激, 谢谢。

【问题讨论】:

    标签: php magento


    【解决方案1】:

    以下内容应该可以帮助您做您想做的事。从我对事物的简要了解来看,Magento 似乎并没有严格按照类别/子类别的方式来考虑事物。相反,有很多类别,有些类别有父母,有些有孩子,有些有。

    //get a collection of all the categories
    Mage::app($mageRunCode, $mageRunType);
    //...
    
    //get a collection of all the categories
    $categories = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToSelect('*');    
    
    foreach($categories as $category)
    {
        //get an array of parent ids for this category
        $array = $category->getParentIds();
    
        //get an array of children ids
        $children = explode(',',$category->getChildren());
    
        //get a list of all the products in a category
        $products = $category->getProductCollection();
    
    }
    
    //pull collection of categories with a parent whose id is 13
    $categories = Mage::getModel('catalog/category')
    ->getCollection()
    ->addFieldToFilter('parent_id','13')    
    ->addAttributeToSelect('*');        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-16
      • 1970-01-01
      • 2016-04-19
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多