<modification>
	<id><![CDATA[Price Filter]]></id>
	<version><![CDATA[1.0.2]]></version>
	<vqmver><![CDATA[2.x]]></vqmver>
	<author><![CDATA[BTech Unit]]></author>
        <file name="catalog/controller/product/product.php">
		<operation>
			<search position="before" index="1,2"><![CDATA[if (isset($this->request->get['filter'])) {]]></search>
			<add><![CDATA[
                            // Price Filter
                             if (isset($this->request->get['minprice']) && isset($this->request->get['maxprice']) ) {
                             $url .= '&minprice=' . $this->request->get['minprice'].'&maxprice='.$this->request->get['maxprice'];
                            }
                           // Price Filter
]]></add>
		</operation>
 
 <operation>
			<search position="replace" index="2"><![CDATA['href'      => $this->url->link('product/category', 'path=' . $path),]]></search>
			<add><![CDATA[
                            // Price Filter
                            'href'      => $this->url->link('product/category', 'path=' . $this->request->get['path'].( (isset($this->request->get['minprice']) && isset($this->request->get['maxprice'])) ? '&minprice=' . $this->request->get['minprice'].'&maxprice='.$this->request->get['maxprice'] : '')),
                           // Price Filter
]]></add>
		</operation>
                
	</file>
       
       <file name="catalog/controller/product/category.php">
		<operation>
			<search position="before" index="4"><![CDATA[if (isset($this->request->get['sort'])) {]]></search>
			<add><![CDATA[
                            // Price Filter
                            if (isset($this->request->get['minprice']) && isset($this->request->get['maxprice']) ) {
                  $url .= '&minprice=' . $this->request->get['minprice'].'&maxprice='.$this->request->get['maxprice'];
               
                            $max_price = $this->request->get['minprice'];
                            $min_price = $this->request->get['maxprice'];
            } else {
                $max_price = '';
                $min_price = '';
            }
                           // Price Filter
]]></add>
		</operation>
                <operation>
			<search position="after"><![CDATA[ 'filter_category_id' => $category_id,]]></search>
			<add><![CDATA[
                            // Price Filter
                             'maxprice' => $max_price,
                             'minprice' => $min_price,
                           // Price Filter
]]></add>
		</operation>
                  <operation>
			<search position="before" index="5"><![CDATA[if (isset($this->request->get['limit'])) {]]></search>
			<add><![CDATA[
                          // Price Filter
                             if (isset($this->request->get['minprice']) && isset($this->request->get['maxprice']) ) {
                             $url .= '&minprice=' . $this->request->get['minprice'].'&maxprice='.$this->request->get['maxprice'];
                            }
                           // Price Filter
]]></add>
		</operation>
                 <operation>
			<search position="before" index="5,6,7"><![CDATA[if (isset($this->request->get['sort'])) {]]></search>
			<add><![CDATA[
                              // Price Filter
                             if (isset($this->request->get['minprice']) && isset($this->request->get['maxprice']) ) {
                             $url .= '&minprice=' . $this->request->get['minprice'].'&maxprice='.$this->request->get['maxprice'];
                            }
                           // Price Filter
]]></add>
		</operation>    
	</file>
        
        <file name="catalog/model/catalog/product.php">
		<operation>
			<search position="after" error="skip" index="1,2"><![CDATA[$sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'";]]></search>
			<add><![CDATA[
                                 if (!empty($data['maxprice']) && !empty($data['minprice'])) {
            // $amount = $this->tax->getTax($value, $tax_class_id);

            if ($this->config->get('config_tax')) {
                if (isset($this->session->data['country_id']) && isset($this->session->data['zone_id'])) {
                    $country_id = $this->session->data['country_id'];
                    $zone_id = $this->session->data['zone_id'];
                } else {
                    $country_id = $this->config->get('config_country_id');
                    $zone_id = $this->config->get('config_zone_id');
                }

                $sqlT = "((";
                $sqlT .= "SELECT IFNULL(SUM(tr.rate), 0) FROM " . DB_PREFIX . "tax_rate tr";
                $sqlT .= " LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr.geo_zone_id = z2gz.geo_zone_id)";
                $sqlT .= " WHERE (z2gz.country_id = '0' OR z2gz.country_id = '" . (int) $country_id . "')";
                $sqlT .= " AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int) $zone_id . "') and tr.type = 'P'";
                $sqlT .= ") / 100 + 1)";

                $sqlT2 = "((";
                $sqlT2 .= "SELECT IFNULL(SUM(tr.rate), 0) FROM " . DB_PREFIX . "tax_rate tr";
                $sqlT2 .= " LEFT JOIN " . DB_PREFIX . "zone_to_geo_zone z2gz ON (tr.geo_zone_id = z2gz.geo_zone_id)";
                $sqlT2 .= " WHERE (z2gz.country_id = '0' OR z2gz.country_id = '" . (int) $country_id . "')";
                $sqlT2 .= " AND (z2gz.zone_id = '0' OR z2gz.zone_id = '" . (int) $zone_id . "') and tr.type = 'F'";
                $sqlT2 .= "))";

                $tax_multiplier = "IFNULL(" . $sqlT . ", 1) * ";
                $tax_multiplier2 = "IFNULL(" . $sqlT2 . ", 0) + ";
            } else {
                $tax_multiplier = "";
                $tax_multiplier2 = "";
            }

            $sql .= " AND " . $tax_multiplier2 . " " . $tax_multiplier . " (CASE WHEN (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int) $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) IS NOT NULL THEN (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int) $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) WHEN (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int) $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) IS NOT NULL THEN (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int) $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) ELSE p.price END) >= " . $data['maxprice'] . "
                    AND " . $tax_multiplier2 . " " . $tax_multiplier . " (CASE WHEN (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int) $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) IS NOT NULL THEN (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int) $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) WHEN (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int) $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) IS NOT NULL THEN (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int) $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) ELSE p.price END) <= " . $data['minprice'] . " ";
        }
]]></add>
		</operation>
	</file>
</modification>