0

Here is my setup: 1 website, 4 stores and 1 storeview by store

I would like to collect the list of my stores.

I created my block named "storenav." In "layout/page.xml" to the desired location, I added:

<block type="page/html" name="storenav" as="storenav" template="page/html/storenav.phtml"/>

For the contents of the block, I created a phtml in which I put the following code:

<li>
    <?php foreach ($this->getGroups() as $_group): ?>
        <a href="<?php echo $_group->getHomeUrl() ?>"> <?php echo $this->escapeHtml($_group->getName()) ?>  </a><br/>
    <?php endforeach; ?>
</li>

I thought it would retrieve the list of my "store", but nothing appears to share a point for the list.

There's something missing in my code? Is it necessary and does it put something else? My approach is not it good?

I'm completely stuck, help me, please

Thank you in advance

2 Answers 2

1

With the way you've set up your template you need a getGroups() function in Mage_Page_Block_Html class.

The getGroups function could look something like:

public function getGroups()
{
   return   Mage::app()->getStores(false); //Pass false if you don't want the default store.

}

The functions to use to retrieve store name and url in the template with be:

$url = $_group->getBaseUrl();
$name = $_group->getName();
2
  • Thank you for your help "ParasSood" Rather than recreate a getgroups () function in the Mage_Page_Block_Html class, I used the one that already existed in the footer to switch blind. So, so I modified my "layout / page.xml" by putting: <block type="page/switch" name="storenav" as="storenav" template="page/html/storenav.phtml"/> My approach is correct?
    – Chip13
    Aug 24, 2014 at 12:34
  • I don't think you need groups, $_groups->getName() would return you the name of the group. Call getStores() in the page/switch block class to get the stores and do everything else as you've done.
    – Paras Sood
    Aug 24, 2014 at 12:52
0

Thank you for your help "ParasSood"

Rather than recreate a getgroups () function in the Mage_Page_Block_Html class, I used the one that already existed in the footer to switch blind.

So, so I modified my "layout / page.xml" by putting:

<block type="page/switch" name="storenav" as="storenav" template="page/html/storenav.phtml"/>

My approach is correct?

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.