Post by solojuve1897 » Mon Jun 27, 2011 11:06 pm

Hello,

I am very much new on this forum and have a small problem I hope somebody knowledgeable in MySQL and PHP can help me with. I made a duplicate of the "special.php"-page to make a new "latest.php"-page. Everything seams to be working fine. Result is here: http://dartbutiken.se/butik/index.php?r ... uct/latest

But I dont have pagination. I know why, but I dont know how to solve it.

In the controller/product/special.php file you find the following lines controlling the pagination-process:

First this:

Code: Select all

$product_total = $this->model_catalog_product->getTotalProductSpecials();
And second this part:

Code: Select all

$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $this->config->get('config_catalog_limit');
$pagination->text = $this->language->get('text_pagination');
$pagination->url = HTTP_SERVER . 'index.php?route=product/special' . $url . '&page={page}';
            
$this->data['pagination'] = $pagination->render();
The problem is how to make a new SQL-statement which is like the "getTotalProductSpecials" with the difference that it instead gets the latest products.

In the model/catalog/product.php file you find the SQL-statement:

Code: Select all

public function getTotalProductSpecials() {
		if ($this->customer->isLogged()) {
			$customer_group_id = $this->customer->getCustomerGroupId();
		} else {
			$customer_group_id = $this->config->get('config_customer_group_id');
		}		
		
		$query = $this->db->query("SELECT COUNT(DISTINCT ps.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "product_special ps ON (p.product_id = ps.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_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())) AND ps.product_id NOT IN (SELECT pd2.product_id FROM " . DB_PREFIX . "product_discount pd2 WHERE p.product_id = pd2.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())))");
		
		if (isset($query->row['total'])) {
			return $query->row['total'];
		} else {
			return 0;	
		}
	}
Help is very much appreciated!

Regards,

Newbie

Posts

Joined
Fri Jun 03, 2011 1:00 am

Post by solojuve1897 » Tue Jun 28, 2011 8:58 pm

*Bump*

Anybody?

Newbie

Posts

Joined
Fri Jun 03, 2011 1:00 am

Post by ckonig » Tue Jun 28, 2011 9:02 pm

how does the model function look, that gives you the 'latest' products?

User avatar
Active Member

Posts

Joined
Wed Feb 16, 2011 4:26 pm
Location - Netherlands

Post by solojuve1897 » Tue Jun 28, 2011 11:32 pm

ckonig wrote:how does the model function look, that gives you the 'latest' products?
Like this:

Code: Select all

public function getLatestProducts($limit) {
		$product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit);

		if (!$product_data) { 
			$query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p 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) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit);
		 	 
			$product_data = $query->rows;

			$this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data);
		}
		
		return $product_data;
	}

Newbie

Posts

Joined
Fri Jun 03, 2011 1:00 am

Post by solojuve1897 » Wed Jun 29, 2011 6:57 pm

*Bump*

Anybody?

This seams harder than what I though in the beginning...

Regards,

Newbie

Posts

Joined
Fri Jun 03, 2011 1:00 am

Post by solojuve1897 » Fri Jul 01, 2011 12:15 am

*Last Bump*

I guess nobody can help me. Please?

Regards,

Newbie

Posts

Joined
Fri Jun 03, 2011 1:00 am
Who is online

Users browsing this forum: No registered users and 60 guests