<modification>
    <name>OC Layered Navigation Ajax</name>
	<version>3.x</version>
	<link>http://www.plazathemes.com/</link>
	<author>Plaza Theme</author>
	<code>layered_navigation</code>

	<file path="catalog/controller/product/category.php">
        <operation>
            <search><![CDATA[$category_info = $this->model_catalog_category->getCategory($category_id);]]></search>
            <add position="before"><![CDATA[
        /* Edit for Layered Navigation */
        if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
            // SSL connection
            $base_url = str_replace('http', 'https', $this->config->get('config_url'));
        } else {
            $base_url = $this->config->get('config_url');
        }
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA['href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)]]></search>
            <add position="replace"><![CDATA['href'  => $base_url . 'index.php?route=product/category&path=' . $result['category_id'] . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=p.sort_order&order=ASC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=pd.name&order=ASC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=pd.name&order=DESC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=ASC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=p.price&order=ASC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=DESC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=p.price&order=DESC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=DESC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=rating&order=DESC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=ASC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=rating&order=ASC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=ASC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=p.model&order=ASC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=DESC' . $url)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . '&sort=p.model&order=DESC' . $url]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=' . $value)]]></search>
            <add position="replace"><![CDATA[$base_url . 'index.php?route=product/category&path=' . $category_id . $url . '&limit=' . $value]]></add>
        </operation>

        <operation>
            <search><![CDATA[$pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');]]></search>
            <add position="replace"><![CDATA[$pagination->url = $base_url . 'index.php?route=extension/module/oclayerednavigation/category&path=' . $category_id . $url . '&page={page}';]]></add>
        </operation>

        <operation>
            <search><![CDATA[$data['limit'] = $limit;]]></search>
            <add position="replace"><![CDATA[
            /* Edit for Layered Navigation Ajax Module */
            $module_status = $this->config->get('module_oclayerednavigation_status');
            if($module_status) {
                // $this->document->addScript('catalog/view/javascript/jquery/jquery-ui.min.js');
                $this->document->addStyle('catalog/view/javascript/jquery/css/jquery-ui.min.css');
 
                if (file_exists(DIR_TEMPLATE . $this->config->get('theme_' . $this->config->get('config_theme') . '_directory') . '/stylesheet/opentheme/oclayerednavigation/css/oclayerednavigation.css')) {
                    $this->document->addStyle('catalog/view/theme/' . $this->config->get('theme_' . $this->config->get('config_theme') . '_directory') . '/stylesheet/opentheme/oclayerednavigation/css/oclayerednavigation.css');
                } else {
                    $this->document->addStyle('catalog/view/theme/default/stylesheet/opentheme/oclayerednavigation/css/oclayerednavigation.css');
                }
 
                $this->document->addScript('catalog/view/javascript/opentheme/oclayerednavigation/oclayerednavigation.js');
            }


            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[$this->response->setOutput($this->load->view('product/category', $data));]]></search>
            <add position="replace"><![CDATA[
            /* Edit for Layered Navigation Ajax Module */
            if($module_status) {
                $data['module_oclayerednavigation_loader_img'] = $base_url . 'image/' . $this->config->get('module_oclayerednavigation_loader_img');
 
                $this->response->setOutput($this->load->view('extension/module/oclayerednavigation/occategory', $data));
            } else {
 
                $this->response->setOutput($this->load->view('product/category', $data));
            }
            ]]></add>
        </operation>
	</file>

    <file path="catalog/model/catalog/product.php">
        <operation>
            <search><![CDATA[if (!empty($data['filter_manufacturer_id'])) {]]></search>
            <add position="before">
                <![CDATA[
        /* Price range */
        if  (!empty($data['filter_price'])) {
            $min_price = $data['filter_price']['min_price'];
            $max_price = $data['filter_price']['max_price'];
            $sql_sl_special = "(SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1)";
            $sql_sl_discount = "(SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1)";
            $sql .= " AND (CASE WHEN " . $sql_sl_special . " IS NOT NULL THEN " . $sql_sl_special . " WHEN " . $sql_sl_discount . " IS NOT NULL THEN ". $sql_sl_discount . " ELSE p.price END) >='". $min_price ."'" ;
            $sql .= " AND (CASE WHEN " . $sql_sl_special . " IS NOT NULL THEN " . $sql_sl_special . " WHEN " . $sql_sl_discount . " IS NOT NULL THEN ". $sql_sl_discount . " ELSE p.price END) <='". $max_price ."'";
        }
        /* End */
                ]]>
            </add>
        </operation>
    </file>
</modification>