0

This is a copy of my question in StackOverflow: https://stackoverflow.com/questions/31006884/how-to-link-categories-between-storeviews-magento. I thought it would be more appropriate in the magento section.

I have created a multistore website with the following structure:

-website
--store1.nl
---store1-view
--store2.nl
---store2-view
--store3.nl
---store3-view

On the store1 homepage (CMS-page) I'd like to add a category-link to store2, store2-view. I have put the suggested widget link (see below), with a link to the desired category in store2.nl, but it doesn't link to the category store2.nl, it stays on store1.nl. The URL even says store1.nl<someurlcode>__store1-view instead of store2.nl<someurlcode>__store2-view

{{widget type="catalog/category_widget_link" anchor_text="Displayed Text" title="Title attribute text" template="catalog/category/widget/link/link_block.phtml" id_path="category/22"}}

I'd rather not hardcode the category-links.

1

It's not possible with a widget out of the box. To do this you have to add your own PHTML file (and possible block class for logic) and either

  • Emulate the store you wish to link to
  • Get the base URL for the other store with Mage::app()->getStore($storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); and then paste the category path after that
  • thanks Sander, I solved it, below I put the how-to in an separate answer – DrCashew Jun 28 '15 at 11:00
  • Great! Looking forward to how you managed to solve it – Sander Mangel Jun 28 '15 at 11:12
0

I solved the question with the help of Sander's answer, I used Store Emulation.

This is what I did:

I copied: app/design/frontend/base/template/catalog/category/widget/link/link_inline.phtml to app/design/frontend/theme/custom_theme/template/catalog/category/widget/link/link_inline.phtml

renamed the file to: link_inline_<store_view>.phtml

and used the following code:

$appEmulation = Mage::getSingleton('core/app_emulation');

//Start environment emulation of the specified store
$initialEnvironmentInfo = $appEmulation >startEnvironmentEmulation('<store_view_id2>');
// Gets the current store's id
$idPath = explode('/', $this->_getData('id_path'));
$categoryId = $idPath[1];

            if ($categoryId) {
                /** @var $helper Mage_Catalog_Helper_Category */
                $helper = $this->_getFactory()->getHelper('catalog/category');
                $category = Mage::getModel('catalog/category')->load($categoryId);
                $cat_name = $category->getName();
                $this->_href = $helper->getCategoryUrl($category);
            }          

?>
<span class="widget widget-category-link-inline"> <a class="level2" a href="<?php echo $this->_href; ?>"> <span><?php echo $cat_name ?></span></a></span>
<?php

//Stop environment emulation and restore original store
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);

To get the particular link in --store1.nl.---store1-view to link to --store2.nl.---store2-view I used the following block syntax in a static block used by --store1.nl.---store1-view:

{{widget type="catalog/category_widget_link" template="catalog/category/widget/link/link_inline_<store_view2>.phtml" id_path="category/61"}}

Improvements are welcome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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