Exemplo n.º 1
0
 protected function getContext()
 {
     $contextFilters = array();
     foreach ($this->filters as $filter) {
         $contextFilters[] = filterHandle($filter);
     }
     $context = array('filters' => implode(',', $contextFilters), 'originalAction' => $this->request->getActionName());
     foreach (array('category', 'quickShopSequence', 'includeSub') as $key) {
         if ($this->request->get($key)) {
             $context[$key] = $this->request->get($key);
         }
     }
     return $context;
 }
Exemplo n.º 2
0
function createCategoryUrl($params, LiveCart $application)
{
    static $simpleUrlTemplate = null;
    // create URL template
    $router = $application->getRouter();
    if (!$simpleUrlTemplate) {
        $simpleUrlTemplate = $router->createUrl(array('controller' => 'category', 'action' => 'index', 'cathandle' => '---', 'id' => 999));
        $simpleUrlTemplate = strtr($simpleUrlTemplate, array(999 => '#', '---' => '|'));
    }
    $category = $params['data'];
    if (!isset($category['ID'])) {
        $category['ID'] = 1;
    }
    $handle = isset($category['name_lang']) ? createHandleString($category['name_lang']) : '';
    // category names to use in other language links
    $router->setLangReplace($handle, 'name', $category);
    // no extra params, so we don't need to call the router to build the URL
    if (count($params) == 1) {
        return strtr($simpleUrlTemplate, array('#' => $category['ID'], '|' => $handle));
    }
    $filters = array();
    // remove filter (expand search)
    if (isset($params['removeFilter'])) {
        foreach ($params['filters'] as $key => $filter) {
            if ($filter['ID'] == $params['removeFilter']['ID']) {
                unset($params['filters'][$key]);
            }
        }
    }
    if (isset($params['removeFilters'])) {
        foreach ($params['removeFilters'] as $filter) {
            unset($params['filters'][$filter['ID']]);
        }
    }
    // get filters
    if (isset($params['filters'])) {
        foreach ($params['filters'] as $filter) {
            $filters[] = filterHandle($filter);
        }
    }
    // apply new filter (narrow search)
    if (!empty($params['addFilter'])) {
        $filters[] = filterHandle($params['addFilter']);
    }
    if (empty($handle)) {
        $handle = '-';
    }
    $urlParams = array('controller' => 'category', 'action' => empty($params['action']) ? 'index' : $params['action'], 'cathandle' => $handle, 'id' => $category['ID']);
    if (!empty($params['query'])) {
        $urlParams['query'] = $params['query'];
    }
    if (!empty($params['page'])) {
        $urlParams['page'] = $params['page'];
    }
    if ($filters) {
        $urlParams['filters'] = implode(',', $filters);
    }
    if ('index' != $urlParams['action']) {
        unset($urlParams['cathandle']);
        if (isset($urlParams['filters'])) {
            $urlParams['query'] = 'filters=' . $urlParams['filters'];
            unset($urlParams['filters']);
        }
    }
    $url = $application->getRouter()->createUrl($urlParams, true);
    if (!empty($params['full'])) {
        $url = $application->getRouter()->createFullUrl($url);
    }
    // remove empty search query parameter
    return preg_replace('/[\\?&]q=$/', '', $url);
}
Exemplo n.º 3
0
 /**
  *  Create breadcrumb
  */
 private function setUpBreadCrumbAndReturnFilterChainHandle($page)
 {
     // get category path for breadcrumb
     $path = $this->getCategory()->getPathNodeArray();
     include_once ClassLoader::getRealPath('application.helper.smarty') . '/function.categoryUrl.php';
     foreach ($path as $nodeArray) {
         $url = createCategoryUrl(array('data' => $nodeArray), $this->application);
         if (array_key_exists('name_lang', $nodeArray)) {
             $this->addBreadCrumb($nodeArray['name_lang'], $url);
         }
     }
     // add filters to breadcrumb
     if (!isset($nodeArray)) {
         $nodeArray = $this->getCategory()->toArray();
     }
     $params = array('data' => $nodeArray, 'filters' => array());
     foreach ($this->filters as $filter) {
         $filter = $filter->toArray();
         $params['filters'][] = $filter;
         // add current page number to the last item URL
         if (count($params['filters']) == count($this->filters)) {
             $params['page'] = $page;
         }
         $url = createCategoryUrl($params, $this->application);
         $this->addBreadCrumb($filter['name_lang'], $url);
     }
     // set return path
     if (isset($url)) {
         $this->router->setReturnPath($this->router->getRouteFromUrl($url));
     }
     // get filter chain handle
     $filterChainHandle = array();
     if (!empty($params['filters'])) {
         foreach ($params['filters'] as $filter) {
             $filterChainHandle[] = filterHandle($filter);
         }
     }
     return implode(',', $filterChainHandle);
 }