/**
  * @param Mana_Seo_Model_ParsedUrl $token
  * @param int $from
  * @param int $to
  * @return bool
  */
 protected function _setPriceFilter($token, $from, $to)
 {
     $cSwapRangeBounds = Mana_Seo_Model_ParsedUrl::CORRECT_SWAP_RANGE_BOUNDS;
     /* @var $core Mana_Core_Helper_Data */
     $core = Mage::helper('mana_core');
     $isSlider = $core->isManadevLayeredNavigationInstalled() && in_array($token->getParameterUrl()->getFilterDisplay(), array('slider', 'range', 'min_max_slider'));
     if ($this->_schema->getUseRangeBounds() || $isSlider) {
         $from = 0 + $from;
         $to = 0 + $to;
         if ($from > $to) {
             $this->_notice($token, $cSwapRangeBounds, __LINE__, "{$from},{$to}");
             $t = $from;
             $from = $to;
             $to = $t;
         }
         if ($isSlider) {
             $token->addQueryParameter($token->getAttributeCode(), "{$from},{$to}");
         } else {
             if ($from == $to) {
                 return false;
             }
             $range = $to - $from;
             $rawIndex = $to / $range;
             $index = round($rawIndex);
             if (abs($index - $rawIndex) >= 0.001) {
                 return false;
             }
             $token->addQueryParameter($token->getAttributeCode(), "{$index},{$range}");
         }
     } else {
         $token->addQueryParameter($token->getAttributeCode(), "{$from},{$to}");
     }
     return true;
 }
Beispiel #2
0
 public function getItemData($key, $value)
 {
     /* @var $seo Mana_Seo_Helper_Data */
     $seo = Mage::helper('mana_seo');
     $this->_schema = $seo->getActiveSchema($this->getStore()->getId());
     if ($url = $this->_getParameterUrl($key)) {
         switch ($url->getType()) {
             case Mana_Seo_Model_ParsedUrl::PARAMETER_ATTRIBUTE:
                 if ($urlKey = $this->_getValueUrlKey($value)) {
                     return array('url' => $this->_encode($urlKey['final_url_key']), 'prefix' => $urlKey['final_include_filter_name'] || in_array($url->getFilterDisplay(), array('slider', 'range', 'min_max_slider')) ? $this->_encode($url->getFinalUrlKey()) . $this->getSchema()->getFirstValueSeparator() : '', 'position' => $urlKey['position'], 'id' => $value);
                 }
                 break;
             case Mana_Seo_Model_ParsedUrl::PARAMETER_CATEGORY:
                 if ($this->getSchema()->getRedirectToSubcategory()) {
                     $url = urldecode(str_replace('+', '%2B', $seo->urlDecode(Mage::app()->getFrontController()->getRequest()->getParam('m-url'))));
                     $query = array('cat' => $value, 'm-seo-enabled' => null, 'm-show-more-cat' => null, 'm-show-more-popup' => null, 'm-url' => null);
                     /* @var $parser Mana_Seo_Helper_UrlParser */
                     $parser = Mage::helper('mana_seo/urlParser');
                     $storeUrl = Mage::app()->getStore()->isCurrentlySecure() ? $this->getUrl('', array('_secure' => true)) : $this->getUrl('');
                     $storeParsedUrl = parse_url($storeUrl);
                     $path = substr($url, strlen($storeParsedUrl['scheme'] . '://' . $storeParsedUrl['host'] . (isset($storeParsedUrl['port']) ? ':' . $storeParsedUrl['port'] : '') . $storeParsedUrl['path']));
                     //                        if (!$this->coreHelper()->startsWith($path, '/')) {
                     //                            $path = '/'.$path;
                     //                        }
                     $urlQuery = array();
                     if (($pos = strpos($path, '?')) !== false) {
                         parse_str(substr($path, $pos + 1), $urlQuery);
                         $path = substr($path, 0, $pos);
                     }
                     $storeParsedQuery = array();
                     if (isset($storeParsedUrl['query'])) {
                         parse_str($storeParsedUrl['query'], $storeParsedQuery);
                     }
                     if ($this->coreHelper()->startsWith($path, 'catalogsearch/result/')) {
                         $path = Mage::getStoreConfig('mana/seo/search_url_key') . substr($path, strlen('catalogsearch/result/'));
                     }
                     if ($parsedUrl = $parser->parse($path)) {
                         $params = array_merge($parsedUrl->getImplodedParameters(), array('_secure' => Mage::app()->getFrontController()->getRequest()->isSecure(), '_use_rewrite' => true, '_m_escape' => '', '_query' => array_merge($storeParsedQuery, $query, $urlQuery, count($parsedUrl->getQueryParameters()) ? $parsedUrl->getImplodedQueryParameters() : array())));
                         $url = Mage::helper('mana_filters')->markLayeredNavigationUrl(Mage::getUrl($parsedUrl->getRoute(), $params), $parsedUrl->getRoute(), $params);
                         return array('full_url' => $url);
                     } else {
                         throw new Exception('Not implemented');
                     }
                 } elseif ($urlKey = $this->_getCategoryUrlKeys($value)) {
                     return array('url' => $this->_encode($urlKey), 'prefix' => $this->_encode($url->getFinalUrlKey()) . $this->getSchema()->getFirstValueSeparator(), 'position' => 0, 'id' => 0);
                 }
                 break;
             case Mana_Seo_Model_ParsedUrl::PARAMETER_PRICE:
                 list($from, $to) = explode(',', $value);
                 $index = $from;
                 $range = $to;
                 if ($this->_schema->getUseRangeBounds()) {
                     $from = ($index - 1) * $range;
                     $to = $from + $range;
                     $path = $from . $this->_schema->getPriceSeparator() . $to;
                 } else {
                     $path = $index . $this->_schema->getPriceSeparator() . $range;
                 }
                 return array('url' => $path, 'prefix' => '', 'position' => 0, 'id' => 0);
             default:
                 throw new Exception('Not implemented');
         }
     }
     return $value;
 }