Post by hiddenking » Sat Jan 29, 2022 5:07 pm

i did a new page for all category and product to show but i want to sort this category which Which category is the first secend 3.th floor I decide how can i do that this is my code

newcategory php

Code: Select all

<?php
class ControllerExtensionModuleFskcatproducts extends Controller {
	public function index() {
		$this->load->model('tool/image');
		$this->load->model('catalog/product');
		
		$this->document->setTitle("Tüm Kategoriler"); // ***** define this in your language file
		
		$category_list = array(117,240,166,241,242); // Buraya hangi kategoriler gelecekse onların adlarını yazın. 
		
		$category_products = $this->db->query(
		"SELECT cd.name as category_name, ptc.product_id 
		FROM 
		".DB_PREFIX."product_to_category ptc LEFT JOIN 
		".DB_PREFIX."product p ON (ptc.product_id = p.product_id) 
		LEFT JOIN ".DB_PREFIX."category_description cd ON (ptc.category_id = cd.category_id) 
		WHERE 
		ptc.category_id IN(".implode(',',$category_list).")  AND
		p.status = 1 AND
		cd.language_id = '".(int)$this->config->get('config_language_id')."'
		GROUP BY ptc.product_id")->rows;
		
		$data['products'] = array();

		foreach($category_products as $category_product){
			$result = $this->model_catalog_product->getProduct($category_product['product_id']);
			$image = ($result['image'] ? $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height')) : $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height')));
			$price = ($this->customer->isLogged() || !$this->config->get('config_customer_price') ? $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']) : false);
			$special = ((float)$result['special'] ? $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']) : false);
			$tax = ($this->config->get('config_tax') ? $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']) : false);
			$rating = ($this->config->get('config_review_status') ? (int)$result['rating'] : false);

			$data['products'][$category_product['category_name']][] = array(
				'product_id'		=> $result['product_id'],
				'stock_control'		=> $stock_control,
				'thumb'			=> $image,
				'name'			=> $result['name'],
				'description'		=> utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
				'price'			=> $price,
				'special'		=> $special,
				'tax'			=> $tax,
				'minimum'		=> $result['minimum'] > 0 ? $result['minimum'] : 1,
				'rating'			=> $result['rating'],
				'href'			=> $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
				); 
		} 
		$data['footer'] = $this->load->controller('common/footer');
		$data['header'] = $this->load->controller('common/header'); 
		$this->response->setOutput($this->load->view('extension/module/fskcatproduct', $data));
	}
}
result

Attachments

Screenshot (86).png

Screenshot (86).png (136.02 KiB) Viewed 441 times


market.miuiturkiye.net


User avatar
Newbie

Posts

Joined
Tue Apr 24, 2018 2:15 am

Post by thekrotek » Sat Jan 29, 2022 5:20 pm

I don't see any sorting in your query at all.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by hpwebdesign » Mon Jan 31, 2022 8:08 am

change your query like this

Code: Select all

SELECT cd.name as category_name, ptc.product_id 
		FROM 
		".DB_PREFIX."product_to_category ptc LEFT JOIN
		".DB_PREFIX."category c ON (ptc.category_id=c.category_id) LEFT JOIN 
		".DB_PREFIX."product p ON (ptc.product_id = p.product_id) 
		LEFT JOIN ".DB_PREFIX."category_description cd ON (ptc.category_id = cd.category_id) 
		WHERE 
		ptc.category_id IN(".implode(',',$category_list).")  AND
		p.status = 1 AND
		cd.language_id = '".(int)$this->config->get('config_language_id')."'
		GROUP BY ptc.product_id ORDER BY c.sort_order ASC"
and in your admin you can sort the categories as you wish

HP Web Design
http://hpwebdesign.io
Opencart Extension Development | OpenCart Professional Services | OpenCart Tutorials


User avatar
New member

Posts

Joined
Wed Aug 15, 2018 6:58 am
Location - Yogyakarta
Who is online

Users browsing this forum: Adminas99999, Semrush [Bot] and 129 guests