Post by spdavis » Thu Aug 17, 2017 3:42 am

Hi..
I have an online shop that sells products by different Manufacturers/Brand. Using OC 1.5.4.
I want customers with any product page to be able to view products by filter, but present to pages by GROUP of Manufacturers/Brand.

So is by example: -
Manufacturers/Brand BC
Manufacturers/Brand B

and (say)
Manufacturers/Brand C

My search drop down need then offers 3 options:-
ALL Manufacturers/Brands which will be default
All Manufacturers/Brands but excluding Manufacturers/Brand C
Manufacturers/Brand C only


Or put another way:-
Default is ALL STUFF we sell
OUR selected just shows OUR STUFF not THEIR STUFF
THEIR selected, just shows only THEIR STUFF not OUR STUFF


I am literally wanting to filter out from a SQL request one Manufacturers Brand
So far the module default reads okay and lists all items we sell. Which means almost there. However, without a working filter:-
This bit is where I maybe totally wrong (?) :-

Code: Select all

			if(is_array($manufacturers) && count($manufacturers) > 0){

					$this->data['manufacturers'][] = array(
						'text'  => "OUR STUFF",
						'value' => "OUR",
						'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&manufacturer_name=OUR')
						);	
					$this->data['manufacturers'][] = array(
						'text'  => 'THEIR STUFF',
						'value' =>  'THEIR',
						'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&manufacturer_name=THEIR')
						);	
Full script:-

Code: Select all

<modification>
        <id>Filter by Manufacturer Category</id>
        <version>1.00</version>
        <vqmver>2.5.1</vqmver>
        <author>xxxx</author>
		
        <file name="catalog/language/*/product/category.php">
			<operation error="log">
				<search position="before"><![CDATA[$_['text_limit']]]></search>
				<add><![CDATA[$_['text_filter']       = 'All Brands';]]></add>
			</operation>
		</file>
        <file name="catalog/controller/product/category.php">
			<operation error="log">
				<search position="after"><![CDATA[$this->load->model('catalog/product');]]></search>
				<add><![CDATA[$this->load->model('catalog/manufacturer');
				$this->load->model('setting/setting');]]></add>
			</operation>
			<operation error="log">
				<search position="before" index="1"><![CDATA[if (isset($this->request->get['order'])) {]]></search>
				<add><![CDATA[if (isset($this->request->get['manufacturer_name'])) {
				$manufacturer_name = $this->request->get['manufacturer_name'];
				} else {
				$manufacturer_name = 'all';
				}]]></add>
			</operation>
			<operation error="log">
				<search position="before" index="2,4,5,6"><![CDATA[if (isset($this->request->get['order'])) {]]></search>
				<add><![CDATA[if (isset($this->request->get['manufacturer_name'])) { $url .= '&manufacturer_name=' . $this->request->get['manufacturer_name']; }]]></add>
			</operation>
			<operation error="log">
				<search position="after"><![CDATA[$results = $this->model_catalog_category->getCategories($category_id);]]></search>
				<add><![CDATA[
			$categoryids_with_childs = array();
			$categoryids_with_childs = $this->model_catalog_category->getCategories($category_id);
			array_push($categoryids_with_childs, $category_id);
			$manufacturers = $this->model_catalog_manufacturer->getManufacturersByCategories($categoryids_with_childs);
			$this->data['manufacturers'] = array();
			$this->data['manufacturers'][] = array(
				'text'  => $this->language->get('text_filter'),
				'value' => 'all',
				'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&manufacturer_name=all')
			);
			if(is_array($manufacturers) && count($manufacturers) > 0){

					$this->data['manufacturers'][] = array(
						'text'  => "OUR STUFF",
						'value' => "OUR",
						'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&manufacturer_name=OUR')
						);	
					$this->data['manufacturers'][] = array(
						'text'  => 'THEIR STUFF',
						'value' =>  'THEIR',
						'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&manufacturer_name=THEIR')
						);	
		}
			]]></add>
			</operation>
			<operation error="log">
				<search position="before"><![CDATA['order'              => $order,]]></search>
				<add><![CDATA['manufacturer_name' => $manufacturer_name, 'filter_manufacturer_name' => $manufacturer_name,]]></add>
			</operation>
			<operation error="log">
				<search position="before"><![CDATA[$this->data['sorts'] = array();]]></search>
				<add><![CDATA[			if (isset($this->request->get['manufacturer_name'])) {
				$url .= '&manufacturer_name=' . $this->request->get['manufacturer_name'];
				}]]></add>
			</operation>
			<operation error="log">
				<search position="before"><![CDATA[$this->data['sort'] = $sort;]]></search>
				<add><![CDATA[$this->data['manufacturer_name'] = $manufacturer_name;]]></add>
			</operation>
		</file>
		<file name="catalog/model/catalog/manufacturer.php">
			<operation error="log">
				<search position="after" offset="2"><![CDATA[return $manufacturer_data;]]></search>
				<add><![CDATA[
				public function getManufacturersByCategories($category_ids) {
					if (is_array($category_ids) && count($category_ids) > 0) {
					$path = '';
					$parts = explode('_', (string)$this->request->get['path']);
					$category_ids = (int)array_pop($parts);
				
					$query = $this->db->query("SELECT m.manufacturer_id, m.name, COUNT(p.product_id) AS products_total FROM " . DB_PREFIX . "product_to_category pc 
					LEFT JOIN " . DB_PREFIX . "product p ON (p.product_id = pc.product_id) 
					LEFT JOIN " . DB_PREFIX . "manufacturer m ON (m.manufacturer_id = p.manufacturer_id) 
					WHERE pc.category_id IN (".$category_ids.") AND p.status = 1 AND p.quantity > -1 
					GROUP BY m.manufacturer_id ORDER BY m.name ASC");
					return $query->rows;
					}
					return false;
				}
				]]></add>
			</operation>
		</file>
        <file name="catalog/view/theme/*/template/product/category.tpl">
			<operation error="log">
				<search position="before"><![CDATA[<?php echo $text_sort; ?>]]></search>
				<add><![CDATA[<div class="manufacturer" style="margin-left:29%;display: inline-block;">
                     <b>View:</b>
      <select onchange="location = this.value;">
        <?php foreach ($manufacturers as $filter) { ?>
        <?php if ($filter['value'] == $manufacturer_name) { ?>
        <option value="<?php echo $filter['href']; ?>" selected="selected"><?php echo $filter['text']; ?></option>
        <?php } else { ?>
        <option value="<?php echo $filter['href']; ?>"><?php echo $filter['text']; ?></option>
        <?php } ?>
        <?php } ?>
      </select>
    </div>]]></add>
			</operation>
		</file>
</modification>
I am trying to mod a module that filters Manufacturers, as described above, but cant quite get it.. CAN anybody PLEASE help?
If there is a better way of doing, this, great... How?

New member

Posts

Joined
Wed Jan 30, 2013 9:52 am
Who is online

Users browsing this forum: DoctorDredd and 23 guests