1

What is the best way to add a link to a product's front-end page from the its back-end edit screen? I am using Magento 1.9.2.1 CE. I tried
http://www.magentocommerce.com/magento-connect/vs-preview-product-from-backend.html

But it does not work with 1.9 (as one would expect).

0

Here’s an extremely lightweight Magento extension which will provide you with a simple view product link next to a product name, in Magento admin. It will point to a product view page in the frontend of your Magento project. Simple and easy.

github or Tadic_AVP

All you have to do is copy the content of Tadic_AVP extension (app folder) to a root folder of your Magento project – and that’s it. I hope this simple extension will prove to be useful to you.

Reference: http://inchoo.net/magento/view-product-in-frontend-from-magento-admin/

0

I implemented it for a custom admin theme:

Layout

<layout>
    <adminhtml_catalog_product_edit>
        <reference name="left">
            <block type="product_link/adminhtml_catalog_product_previewLink" name="preview_link" before="store_switcher"></block>
        </reference>
    </adminhtml_catalog_product_edit>
</layout>

Template

<?php
/* @var $this SGH_ProductLink_Block_Adminhtml_Catalog_Product_PreviewLink */
$productUrl = $this->getUrl('catalog/product/view', array(
    'id' => $this->getProduct()->getId(),
     '_store' => $this->getStoreId(),
     '_query' => array('no_flat_index' => 1, 'no_cache' => 1)
));
?>
<p class="switcher">
    <a target="magento_product_preview" href="<?php echo $productUrl; ?>"><?php echo $this->__('Preview in Store (%s)', $this->getStoreName())?></a>
</p>

Block

class SGH_ProductLink_Block_Adminhtml_Catalog_Product_PreviewLink extends Mage_Core_Block_Template
{
    protected $_template='product_link/catalog/product/preview_link.phtml';

    /**
     * Retrieve currently edited product object
     *
     * @return Mage_Catalog_Model_Product
     */
    public function getProduct()
    {
        return Mage::registry('current_product');
    }
    /**
     * Returns store name of current store
     * 
     * @return string[]
     */
    public function getStoreName()
    {
        return Mage::app()->getStore($this->getStoreId())->getName();
    }
    /**
     * Returns store id if currently in store view scope, default store id otherwise
     * 
     * @return int
     */
    public function getStoreId()
    {
        return (int) Mage::app()->getRequest()->getParam('store', Mage::app()->getDefaultStoreView()->getId());
    }
    /**
     * Returns url model class name. Overridden to use frontend URL model.
     *
     * @return string
     */
    protected function _getUrlModelClass()
    {
        return 'core/url';
    }
}

Since the URL depends on the store view, it takes the currently selected scope into account and uses the default store if in default scope.

The code adds a link above the scope switcher. The link is also prepared with ?no_cache=1&no_flat_index=1 parameters to show the page without using full page cache and flat index. Those do not have any effect in Magento CE without custom cache and index extensions, so you can remove them.

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.