1

I like to do a cms page with all brands (subcategories) on it. We have a multistore wise set up. But at the moment, it shows me only subcategories and categories from one storeview.

I have this just copied and change the

->load(195); ->setStoreId(2)

But it seems that I need to do something else, as it shows me only from one store the list. See here:

https://www.outdoorequipped.com/allbrands/

Here is the code I use:

    <div class="main row">
<div class="col-main col-xs-12">
<div class="row">
<?php
$parentCategory = Mage::getModel('catalog/category')->load(195);
$subcategoryCollection = Mage::getModel('catalog/category')
        ->getCollection()
        ->setStoreId(2)
        ->addFieldToFilter('level', ['lteq' => $parentCategory->getLevel() + 2])
        /*->addFieldToFilter('level', $parentCategory->getLevel() + 1)*/
        ->addFieldToFilter('path', ['like' => $parentCategory->getData('path') . '%'])
        ->addAttributeToFilter('entity_id', array('neq' => '195'))
        ->addAttributeToFilter('entity_id', array('neq' => '136'))
        ->addAttributeToSelect(['name'])
        ->setOrder('name', Varien_Data_Collection_Db::SORT_ORDER_ASC);
?>
<?php $previous = null;?>
<?php foreach ($subcategoryCollection as $category): ?>

    <?php $name = $category->getName();
          $firstLetter = substr($name, 0, 1);
          if($previous == null){
             echo '<div class="col-sm-12">'."\n";
             echo '<h4 style="margin-top:5px; margin-bottom:2px;">'.$firstLetter.'</h4>'."\n";
             $previous = $firstLetter;
          }
          elseif ($previous !== $firstLetter){
                echo '</div>'."\n";
                echo '<div class="col-sm-12">'."\n";
                echo '<h4 style="margin-top:5px; margin-bottom:2px;">'.$firstLetter.'</h4>'."\n";
                $previous = $firstLetter;
          }
          echo '<a href="'.$category->getUrl().'" style="margin:10px">'.$category->getName().'</a>'."\n";

    ?>

<?php endforeach; ?>
</div>
</div>
</div>
</div>

It not gives what I like to have. Here is the link from this page:

[link]https://www.outdoorequipped.com/allbrands/

I like to show on this CMS page from all storeviews (4 of them) all categories under a specific given category id.

so should be something similar to this:

ACTIVE / OUTDOOR / WORK

Cat 1 / Cat 11 / Cat 21
Cat 2 / Cat 12 / Cat 22
Cat 3 / Cat 13 / Cat 23

As Active, Outdoor and Work are the storeviews.

3
  • have you filter current store view categories right?
    – Abdul
    Commented Nov 20, 2015 at 4:56
  • As I am new in Magento. I not really understand Your question. When I put this part of code in one store view, I see all categories from it. If I use this code in another store (store view) I see it all those categories. I only like to see all categories on a cms page, for all of the store views. How I can filter current store view categories? Commented Nov 20, 2015 at 5:39
  • // Current store id $storeId = Mage::app()->getStore()->getId();
    – Abdul
    Commented Nov 20, 2015 at 5:52

1 Answer 1

0

Try this

$BrandsCategoryName = 'Brands';
$storeId = Mage::app()->getStore()->getStoreId();
$rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCollection()
    ->setStoreId($storeId)
    ->addFieldToFilter('is_active', 1)
    ->addAttributeToFilter('path', array('like' => "1/{$rootCategoryId}/%"))
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('name', $BrandsCategoryName);

if(count($categories) && $category = $categories->getFirstItem()) {
    $children = Mage::getModel('catalog/category')->getCategories($category->getId());
    foreach ($children as $category) {
          echo $category->getName(); // will return category name 
          echo $category->getRequestPath(); // will return category URL
    }
}
11
  • It not gives what I like to have. Here is the link from this page: [link]outdoorequipped.com/allbrands I like to show on this CMS page from all storeviews (4 of them) all categories under a specific given category id. so should be something similar to this: ACTIVE OUTDOOR WORK Cat 1 Cat 11 Cat 21 Cat 2 Cat 12 Cat 22 Cat 3 Cat 13 Cat 23 As Active, Outdoor and Work are the storeviews. Commented Nov 20, 2015 at 6:22
  • need to display all subcategories and categories to current store right?
    – Abdul
    Commented Nov 20, 2015 at 6:27
  • yes, plus from all other stores too Commented Nov 20, 2015 at 6:28
  • but category id "195" assigned all store?
    – Abdul
    Commented Nov 20, 2015 at 6:29
  • can share your admin Manage Categories screen shot?
    – Abdul
    Commented Nov 20, 2015 at 6:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.