Esempio n. 1
0
 /**
  * Test that Mage_Core_Controller_Varien_Action_Forward::dispatch() does not change dispatched flag
  */
 public function testDispatch()
 {
     $this->_request->setDispatched(true);
     $this->assertTrue($this->_request->isDispatched());
     $this->_object->dispatch('any action');
     $this->assertFalse($this->_request->isDispatched());
 }
Esempio n. 2
0
 /**
  * Validate and Match Cms Page and modify request
  *
  * @param Mage_Core_Controller_Request_Http $request
  * @return bool
  *
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function match(Mage_Core_Controller_Request_Http $request)
 {
     if (!Mage::isInstalled()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('install'))->sendResponse();
         exit;
     }
     $identifier = trim($request->getPathInfo(), '/');
     $condition = new Varien_Object(array('identifier' => $identifier, 'continue' => true));
     $this->_eventManager->dispatch('cms_controller_router_match_before', array('router' => $this, 'condition' => $condition));
     $identifier = $condition->getIdentifier();
     if ($condition->getRedirectUrl()) {
         Mage::app()->getFrontController()->getResponse()->setRedirect($condition->getRedirectUrl())->sendResponse();
         $request->setDispatched(true);
         return $this->_controllerFactory->createController('Mage_Core_Controller_Varien_Action_Redirect', array('request' => $request));
     }
     if (!$condition->getContinue()) {
         return null;
     }
     $page = Mage::getModel('Mage_Cms_Model_Page');
     $pageId = $page->checkIdentifier($identifier, Mage::app()->getStore()->getId());
     if (!$pageId) {
         return null;
     }
     $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId);
     $request->setAlias(Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS, $identifier);
     return $this->_controllerFactory->createController('Mage_Core_Controller_Varien_Action_Forward', array('request' => $request));
 }
 /**
  * Redirect to entity (category or product) in new store
  *
  * @param int $rewriteId
  *
  * @return null|void
  */
 public function _checkStoreRedirect($rewriteId)
 {
     if ($this->_prevStoreId == $this->_storeId) {
         return;
     }
     $redirect = $this->_redirectResource->getRedirectByRewriteId($rewriteId);
     if (!empty($redirect['product_id'])) {
         $requestPath = $this->_getProductRequestPath($redirect, $redirect['category_id']);
     } elseif (!empty($redirect['category_id'])) {
         $requestPath = $this->_getCategoryRequestPath($redirect);
     }
     if (!empty($requestPath)) {
         $this->_response->setRedirect($requestPath, 301);
         $this->_request->setDispatched(true);
     }
 }
Esempio n. 4
0
 /**
  * Redirect to category from another store if custom url key defined
  *
  * @param int $rewriteId
  */
 protected function _checkStoreRedirect($rewriteId)
 {
     if ($this->_prevStoreId != $this->_storeId) {
         $categoryId = $this->_categoryResource->getCategoryIdByRewriteId($rewriteId);
         if (!empty($categoryId)) {
             $rewrite = $this->_categoryResource->getRewriteByCategoryId($categoryId, $this->_storeId);
             if (!empty($rewrite)) {
                 $requestPath = $rewrite['request_path'];
                 if (!empty($this->_newStoreSeoSuffix)) {
                     $requestPath .= '.' . $this->_newStoreSeoSuffix;
                 }
                 $requestPath = $this->_getBaseUrl() . $requestPath;
                 $this->_response->setRedirect($requestPath, 301);
                 $this->_request->setDispatched(true);
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Calls the diehard/load controller without spawning a new request
  *
  * @param array $params
  * @return string
  */
 public function getDynamicBlockReplacement($params)
 {
     // Append dynamic block content to end of page to be replaced by javascript, but not Ajax
     if ($params['blocks'] || !empty($params['all_blocks'])) {
         // Init store if it has not been yet (page served from cache)
         if (!$this->helper()->isAppInited()) {
             $this->helper()->initApp();
         } else {
             // Reset layout
             Mage::unregister('_singleton/core/layout');
             Mage::getSingleton('core/layout');
             // TODO Mage::app()->getLayout() is not reset using the method above!
             // TODO Consider resetting Magento entirely using Mage::reset();
         }
         // Create a sub-request to get JSON response
         $uri = $this->getBaseUrl() . '/_diehard/load/ajax';
         $request = new Mage_Core_Controller_Request_Http($uri);
         $request->setRouteName('diehard');
         $request->setModuleName('_diehard');
         $request->setControllerName('load');
         $request->setActionName('ajax');
         $request->setControllerModule('Cm_Diehard');
         $request->setParam('full_action_name', $params['full_action_name']);
         if (!empty($params['all_blocks'])) {
             $request->setParam('all_blocks', 1);
         } else {
             $request->setParam('blocks', $params['blocks']);
         }
         $request->setParam('params', $params['params']);
         $request->setDispatched(true);
         // Override parameters in request singleton (for Mage_Core_Block_Abstract#getRequest())
         Mage::app()->getRequest()->clearParams();
         Mage::app()->getRequest()->setParams($request->getParams());
         Mage::app()->getRequest()->setParams($request->getParam('params'));
         // Render sub-request into sub-response object
         $response = new Mage_Core_Controller_Response_Http();
         require_once Mage::getModuleDir('controllers', 'Cm_Diehard') . '/LoadController.php';
         $controller = new Cm_Diehard_LoadController($request, $response);
         $controller->dispatch('json');
         $replacement = '';
         if ($this->helper()->isDebug()) {
             $replacement .= '<!-- Dynamic blocks rendered: ' . (empty($params['all_blocks']) ? implode(',', $params['blocks']) : 'ALL') . ' -->' . "\n";
         }
         $replacement .= "<script type=\"text/javascript\">/* <![CDATA[ */Diehard.replaceBlocks({$response->getBody()});/* ]]> */</script>";
         return $replacement;
     } else {
         if ($this->helper()->isDebug()) {
             return '<!-- No dynamic blocks -->';
         } else {
             return '';
         }
     }
 }