/** * Process redirect (R) and permanent redirect (RP) * * @return Mage_Core_Model_Url_Rewrite_Request */ protected function _processRedirectOptions() { $isPermanentRedirectOption = $this->_rewrite->hasOption('RP'); $external = substr($this->_rewrite->getTargetPath(), 0, 6); if ($external === 'http:/' || $external === 'https:') { $destinationStoreCode = $this->_app->getStore($this->_rewrite->getStoreId())->getCode(); $this->_setStoreCodeCookie($destinationStoreCode); $this->_sendRedirectHeaders($this->_rewrite->getTargetPath(), $isPermanentRedirectOption); } $targetUrl = $this->_request->getBaseUrl() . '/' . $this->_rewrite->getTargetPath(); $storeCode = $this->_app->getStore()->getCode(); if (Mage::getStoreConfig('web/url/use_store') && !empty($storeCode)) { $targetUrl = $this->_request->getBaseUrl() . '/' . $storeCode . '/' . $this->_rewrite->getTargetPath(); } if ($this->_rewrite->hasOption('R') || $isPermanentRedirectOption) { $this->_sendRedirectHeaders($targetUrl, $isPermanentRedirectOption); } $queryString = $this->_getQueryString(); if ($queryString) { $targetUrl .= '?' . $queryString; } $this->_request->setRequestUri($targetUrl); $this->_request->setPathInfo($this->_rewrite->getTargetPath()); return $this; }
/** * Get URL rewrite from request * * @return Mage_Core_Model_Url_Rewrite */ private function _getUrlRewrite() { if (!$this->_urlRewrite) { $this->_urlRewrite = Mage::getModel('Mage_Core_Model_Url_Rewrite'); $urlRewriteId = (int) $this->getRequest()->getParam('id', 0); if ($urlRewriteId) { $this->_urlRewrite->load((int) $this->getRequest()->getParam('id', 0)); } } return $this->_urlRewrite; }
public function loadByRequestPath(Mage_Core_Model_Url_Rewrite $object, $path) { if (!is_array($path)) { $path = array($path); } $pathBind = array(); foreach ($path as $key => $url) { $pathBind['path' . $key] = urldecode($url); } // Form select $adapter = $this->_getReadAdapter(); $select = $adapter->select('*')->from($this->getMainTable())->where('request_path IN (:' . implode(', :', array_flip($pathBind)) . ')')->where('store_id IN(?)', array(Mage_Core_Model_App::ADMIN_STORE_ID, (int) $object->getStoreId())); $items = $adapter->fetchAll($select, $pathBind); // Go through all found records and choose one with lowest penalty - earlier path in array, concrete store $mapPenalty = array_flip(array_values($path)); // we got mapping array(path => index), lower index - better $currentPenalty = null; $foundItem = null; foreach ($items as $item) { $penalty = isset($mapPenalty[$item['request_path']]) ? $mapPenalty[$item['request_path']] << 1 + ($item['store_id'] ? 0 : 1) : 0; if (!$foundItem || $currentPenalty > $penalty) { $foundItem = $item; $currentPenalty = $penalty; if (!$currentPenalty) { break; // Found best matching item with zero penalty, no reason to continue } } } // Set data and finish loading if ($foundItem) { $object->setData($foundItem); } // Finish $this->unserializeFields($object); $this->_afterLoad($object); return $this; }
/** * @param Zend_Controller_Request_Http $request * @param Zend_Controller_Response_Http $response * @return Mage_Core_Model_Url */ public function rewrite(Zend_Controller_Request_Http $request = null, Zend_Controller_Response_Http $response = null) { if (is_null($request)) { $request = Mage::app()->getFrontController()->getRequest(); } if (!Mage::helper('ecommerceteam_sln')->forceLayered()) { if (true == parent::rewrite($request, $response)) { return true; } } /** @var $helper EcommerceTeam_Sln_Helper_Request */ $helper = Mage::helper('ecommerceteam_sln/request'); $helper->rewrite($request); return true; }
public function rewrite(Zend_Controller_Request_Http $request = null, Zend_Controller_Response_Http $response = null) { $h = Mage::helper('gomage_checkout'); if ($h->getConfigData('general/enabled')) { if (is_null($request)) { $request = Mage::app()->getFrontController()->getRequest(); } $requestPath = trim($request->getPathInfo(), '/'); if ($requestPath == 'checkout/onepage' || $requestPath == 'checkout/onepage/index') { if (in_array(Mage::app()->getStore()->getWebsiteId(), $h->getAvailavelWebsites())) { if (!($h->isMobileDevice() && (bool) $h->getConfigData('general/disable_mobile'))) { $request->setAlias(self::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath()); $request->setPathInfo('gomage_checkout/onepage'); return true; } } } } parent::rewrite($request, $response); }
public function rewrite(Zend_Controller_Request_Http $request = null, Zend_Controller_Response_Http $response = null) { $result = parent::rewrite($request, $response); if (false !== $result) { return $result; } if (!Mage::isInstalled()) { return false; } if (is_null($request)) { $request = Mage::app()->getFrontController()->getRequest(); } $initialRequestPath = trim($request->getPathInfo(), '/'); $suffix = Mage::getStoreConfig('catalog/seo/category_url_suffix'); $pqSuffix = self::SEO_SUFFIX . $suffix; if ($pqSuffix == substr($initialRequestPath, strlen($initialRequestPath) - strlen($pqSuffix))) { $requestPath = substr($initialRequestPath, 0, strlen($initialRequestPath) - strlen($pqSuffix)); if (is_null($this->getStoreId()) || false === $this->getStoreId()) { $this->setStoreId(Mage::app()->getStore()->getId()); } $this->loadByRequestPath($requestPath . $suffix); if ($this->getId()) { $request->setPathInfo('productquestions/index/index/'); $request->setParam('id', $this->getProductId()); if ($this->getCategoryId()) { $request->setParam('category', $this->getCategoryId()); } if (Mage::getConfig('productquestions/seo/cache_requests')) { try { $this->setUrlRewriteId(null)->setRequestPath($initialRequestPath)->setTargetPath('productquestions/index/index/id/' . $this->getProductId() . '/category/' . $this->getCategoryId())->setIdPath($this->getIdPath() . '/questions')->setIsSystem(0)->save(); } catch (Exception $e) { Mage::logException($e); } } return parent::rewrite($request, $response); } } return false; }
public function testCRUD() { $this->_model->setStoreId(Mage::app()->getDefaultStoreView()->getId())->setRequestPath('fancy/url.html')->setTargetPath('catalog/product/view')->setIsSystem(1)->setOptions('RP'); $crud = new Magento_Test_Entity($this->_model, array('request_path' => 'fancy/url2.html')); $crud->testCrud(); }
function getRequestPathForDefinition($vehicle) { $path = parent::getData('url_path'); if (!$vehicle || !$this->getData('product_id')) { return $this->getRequestPath(); } $schema = new Elite_Vaf_Model_Schema(); $path = 'fit/' . $this->vehicleSlug($vehicle) . '/' . $path; return $path; }
/** * Load rewrite information for request * If $path is array - we must load all possible records and choose one matching earlier record in array * * @param Mage_Core_Model_Url_Rewrite $object * @param array|string $path * @return Mage_Core_Model_Mysql4_Url_Rewrite */ public function loadByRequestPath(Mage_Core_Model_Url_Rewrite $object, $path) { if (!is_array($path)) { $path = array($path); } // Form select $read = $this->_getReadAdapter(); $select = $read->select()->from($this->getMainTable())->where($this->getMainTable() . '.request_path IN (?)', $path)->where('store_id IN(?)', array(0, $object->getStoreId())); $items = $read->fetchAll($select); // Go through all found records and choose one with lowest penalty - earlier path in array, concrete store $mapPenalty = array_flip(array_values($path)); // we got mapping array(path => index), lower index - better $currentPenalty = null; $foundItem = null; foreach ($items as $item) { $penalty = $mapPenalty[$item['request_path']] << 1 + ($item['store_id'] ? 0 : 1); if (!$foundItem || $currentPenalty > $penalty) { $foundItem = $item; $currentPenalty = $penalty; if (!$currentPenalty) { break; // Found best matching item with zero penalty, no reason to continue } } } // Set data and finish loading if ($foundItem) { $object->setData($foundItem); } // Finish $this->unserializeFields($object); $this->_afterLoad($object); return $this; }
/** * Prevent loading disallowed urlrewrites * * @param Mage_Core_Model_Url_Rewrite $model */ public function coreUrlRewriteLoadAfter($model) { if (!$model->getId()) { return; } if (!$this->_role->hasStoreAccess($model->getStoreId())) { $this->_throwLoad(); } }
/** * Retrieve loaded url rewrite * * @param string $idPath * @return Mage_Core_Model_Url_Rewrite */ protected function _loadRewrite($idPath) { $rewrite = new Mage_Core_Model_Url_Rewrite(); $rewrite->loadByIdPath($idPath); return $rewrite; }
/** * Has redirect options set * * @param Mage_Core_Model_Url_Rewrite $urlRewrite * @return bool */ public function hasRedirectOptions($urlRewrite) { /** @var $options Mage_Core_Model_Source_Urlrewrite_Options */ $options = Mage::getSingleton('Mage_Core_Model_Source_Urlrewrite_Options'); return in_array($urlRewrite->getOptions(), $options->getRedirectOptions()); }
* http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade Magento to newer * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * * @category Magento * @package Mage_Catalog * @subpackage integration_tests * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ /** * Extends valid Url rewrites */ require __DIR__ . '/url_rewrites.php'; /** * Invalid rewrite for product assigned to different category */ $rewrite = new Mage_Core_Model_Url_Rewrite(); $rewrite->setStoreId(1)->setIdPath('product/1/4')->setRequestPath('category-2/simple-product.html')->setTargetPath('catalog/product/view/id/1')->setIsSystem(1)->setCategoryId(4)->setProductId(1)->save(); /** * Invalid rewrite for product assigned to category that doesn't belong to store */ $rewrite = new Mage_Core_Model_Url_Rewrite(); $rewrite->setStoreId(1)->setIdPath('product/1/5')->setRequestPath('category-5/simple-product.html')->setTargetPath('catalog/product/view/id/1')->setIsSystem(1)->setCategoryId(5)->setProductId(1)->save();
function getRequestPathForDefinition(VF_Vehicle $vehicle) { $path = parent::getData('url_path'); if (!$vehicle || !$this->getData('product_id')) { return $this->getRequestPath(); } $path = 'fit/' . $this->vehicleSlug($vehicle) . '/' . $path; return $path; }
public function saveRewrite(Mage_Core_Model_Url_Rewrite $rewrite) { if (!$rewrite->getId()) { $old = Mage::getModel('core/url_rewrite')->setStoreId($rewrite->getStoreId())->loadByIdPath($rewrite->getIdPath()); if (!$old) { $old->loadByRequestPath($rewrite->getRequestPath()); } if ($old) { $rewrite->setId($old->getId()); } } $rewrite->save(); $this->_rewrites[$rewrite->getStoreId()][$rewrite->getIdPath()] = $rewrite; $this->_paths[$rewrite->getStoreId()][$rewrite->getRequestPath()] = $rewrite->getIdPath(); return $this; }
public function _construct() { parent::_construct(); $this->_resourceName = 'manapro_filterseolinks/rewrite'; }