Created
July 18, 2016 12:37
-
-
Save rakshazi/593978d3e90dbafa599f881688b5dd0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function viewAction() | |
{ | |
// Get initial data from request | |
$categoryId = (int) $this->getRequest()->getParam('category', false); | |
$productId = (int) $this->getRequest()->getParam('id'); | |
$specifyOptions = $this->getRequest()->getParam('options'); | |
/////////////////////////////////////// START WITH 301 REDIRECT | |
$product = Mage::getModel('catalog/product')->load($productId); | |
$currentURL = Mage::helper('core/url')->getCurrentUrl(); | |
$getParams = ''; | |
$params = $this->getRequest()->getParams(); | |
if (isset($params['id'])) { | |
unset($params['id']); | |
} | |
if ($params) { | |
$getParams = '?' . http_build_query($params); | |
} | |
if ($currentURL != $product->getProductUrl() . $getParams) { | |
$this->getResponse()->setRedirect($product->getProductUrl() . $getParams, 301)->sendResponse(); | |
} | |
/////////////////////////////////////// END WITH 301 REDIRECT | |
// Prepare helper and params | |
$viewHelper = Mage::helper('catalog/product_view'); | |
$params = new Varien_Object(); | |
$params->setCategoryId($categoryId); | |
$params->setSpecifyOptions($specifyOptions); | |
// Render page | |
try { | |
$viewHelper->prepareAndRender($productId, $this, $params); | |
} catch (Exception $e) { | |
if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) { | |
if (isset($_GET['store']) && !$this->getResponse()->isRedirect()) { | |
$this->_redirect(''); | |
} elseif (!$this->getResponse()->isRedirect()) { | |
$this->_forward('noRoute'); | |
} | |
} else { | |
Mage::logException($e); | |
$this->_forward('noRoute'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment