如何获得网站切换器而不是商店切换器?

时间:2010-11-24 19:01:18

标签: templates layout web magento switching

如何创建用于切换网站的下拉菜单,而不仅仅是商店?

更具体地说,我想在Magento网站之间切换。模板中有一个用于切换商店的下拉菜单和一个用于切换语言的下拉菜单,但没有一个用于切换网站。

1 个答案:

答案 0 :(得分:9)

在Magento论坛上找到了解决方案:http://www.magentocommerce.com/boards/viewthread/8296/

您必须在自定义主题包中创建app/design/frontend/base/default/template/page/switch/stores.phtml模板的副本。

然后你必须修改它才能使用以下代码:

<?php
$websites = Mage::app()->getWebsites();

if (count($websites) > 1): ?>
<div class="website-switcher">
    <label for="select-website"><?php echo $this->__('Select Store:') ?></label>
    <select id="select-website" title="<?php echo $this->__('Select Store') ?>" onchange="location.href=this.value">
    <?php foreach ($websites as $website): // print out each website name and code as a dropdown box item ?>
        <?php $_selected = $website->getCode() == Mage::app()->getWebsite()->getCode() ? ' selected="selected"' : '' ?>
        <option value="<?php echo $website->getDefaultStore()->getBaseUrl()?>"<?php echo $_selected ?>><?php echo $this->htmlEscape($website->getName()) ?></option>
    <?php endforeach; ?>
    </select>
</div>
<?php endif; ?>

使用的方法链接到Magento API文档:

相关问题