public function getCurrentUrl($fromStore = true) { $sidQueryParam = $this->_getSession()->getSessionIdQueryParam(); $storeUrl = Mage::app()->getStore()->isCurrentlySecure() ? $this->getUrl('', array('_secure' => true)) : $this->getUrl(''); $storeParsedUrl = parse_url($storeUrl); $params = array('_current' => true, '_m_escape' => '', '_use_rewrite' => true, '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()); $currentUrl = Mage::getUrl('*/*/*', $params); if (($pos = strpos($currentUrl, '?')) !== false) { $currentUrl = substr($currentUrl, 0, $pos); } $requestString = ltrim(Mage::app()->getRequest()->getRequestString(), '/'); $storeParsedQuery = array(); if (isset($storeParsedUrl['query'])) { parse_str($storeParsedUrl['query'], $storeParsedQuery); } $currQuery = Mage::app()->getRequest()->getQuery(); if (isset($currQuery[$sidQueryParam]) && !empty($currQuery[$sidQueryParam]) && $this->_getSession()->getSessionIdForHost($storeUrl) != $currQuery[$sidQueryParam]) { unset($currQuery[$sidQueryParam]); } foreach ($currQuery as $k => $v) { $storeParsedQuery[$k] = $v; } if (!Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL, $this->getCode())) { $storeParsedQuery['___store'] = $this->getCode(); } //if ($fromStore !== false) { $storeParsedQuery['___from_store'] = $fromStore === true ? Mage::app()->getStore()->getCode() : $fromStore; //} return $storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'] . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') . $storeParsedUrl['path'] . $requestString . ($storeParsedQuery ? '?' . http_build_query($storeParsedQuery, '', '&') : ''); return Mage::helper('mana_filters')->markLayeredNavigationUrl(Mage::getUrl('*/*/*', $params), '*/*/*', $params); /* @var $url Mana_Seo_Rewrite_Url */ $url = Mage::getSingleton('core/url'); return $url->getUrl('*/*/*', parent::getCurrentUrl($fromStore)); }
public function getCurrentUrl($fromStore = true) { /** @var $core Mana_Core_Helper_Data */ /** @var ManaPro_FilterSeoLinks_Model_Url $coreUrl */ $core = Mage::helper('mana_core'); $coreUrl = Mage::getSingleton('core/url'); $conditionalWord = $core->getStoreConfig('mana_filters/seo/conditional_word'); $request = Mage::app()->getRequest(); $currentPath = $request->getRouteName() . '/' . $request->getControllerName() . '/' . $request->getActionName(); $currentUrl = parent::getCurrentUrl($fromStore); // delete SEO friendly filters from url path in catalog if ($currentPath == 'catalog/category/view' && ($position = strpos($currentUrl, $conditionalWord)) !== false) { $parts = parse_url($currentUrl); $currentUrl = substr($currentUrl, 0, $position - 1) . '?' . $parts['query']; } return $coreUrl->setEscape(true)->encodeUrl('*/*/*', $currentUrl); }
/** * This method is used to generate URL for store switcher (or language switcher) blocks, typically located in page header * or page footer. `$this` is store to which the URL should switch our user, whereas `Mage::app()->getRequest()` represents * current user location in current store. * @param bool $fromStore * @return string */ public function getCurrentUrl($fromStore = true) { // we only change generation of store URLs on layered navigation enabled pages if ($parsedUrl = Mage::registry('m_parsed_url')) { // get instance of a model which can generate URL for target store $urlModel = Mage::getModel('core/url'); $urlModel->setStore($this); // set basic URL generation parameters $params = array_merge(array('_use_rewrite' => true, '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure()), $parsedUrl->getImplodedParameters()); // add URL query parameters (all applied filters, toolbar parameters and other arbitrary parameters) $query = count($parsedUrl->getQueryParameters()) ? $parsedUrl->getImplodedQueryParameters() : array(); // get array of URL query parameters applied to the current page. The resulting array may contain applied filters in non- // SEO-friendly form (added by Mana_Seo_Router) like [ "price" => "0,100" ] and other arbitrary parameters like // [ "qq" => "pp" ]. $currQuery = Mage::app()->getRequest()->getQuery(); // get base URL of this store $storeUrl = Mage::app()->getStore()->isCurrentlySecure() ? $this->getUrl('', array('_secure' => true)) : $this->getUrl(''); // retrieve name of session id URL query parameter, typically "SID" $sidQueryParam = $this->_getSession()->getSessionIdQueryParam(); // in case session id is in URL and not in cookie we may remove it from current URL query parameters so, that would // basically start new session after store is switched if (!empty($currQuery[$sidQueryParam])) { if ($this->_getSession()->getSessionIdForHost($storeUrl) != $currQuery[$sidQueryParam]) { $params['_nosid'] = true; } } // add source and target store to target URL query $fromStoreCode = $fromStore === true ? Mage::app()->getStore()->getCode() : $fromStore; if ($this->getCode() != $fromStoreCode) { if (!Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL, $this->getCode())) { $query['___store'] = $this->getCode(); } $query['___from_store'] = $fromStore === true ? Mage::app()->getStore()->getCode() : $fromStore; } // add URL query parameters (if any) to URL generation parameters if (count($query)) { $params['_query'] = $query; } // generate and return URL for target store $url = $urlModel->getUrl($parsedUrl->getRoute(), $params); return $url; } else { return parent::getCurrentUrl($fromStore); } }
public function testGetCurrentUrl() { $this->_model->expects($this->any())->method('getUrl')->will($this->returnValue('http://localhost/index.php')); $this->assertStringEndsWith('default', $this->_model->getCurrentUrl()); $this->assertStringEndsNotWith('default', $this->_model->getCurrentUrl(false)); }
public function getCurrentUrl($fromStore = true) { return Mage::getSingleton('core/url')->setEscape(true)->encodeUrl('*/*/*', parent::getCurrentUrl($fromStore)); }