This acts as a fallback if you can't be bothered to relate products together. I've just posted about this mod on my blog, but thought I'd share it in the forums too.
This is only tested on Version 1.4.9.5.
Open ROOT/catalog/controller/product/product.php
Find:
Code: Select all
$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
Code: Select all
if(count($results)<1 && (int)$this->data['product_info']['manufacturer_id'] > 0){
$results = $this->model_catalog_product->getProductRelatedByManufacturer($this->data['product_info']['manufacturer_id'],$this->request->get['product_id']);
}
find:
Code: Select all
public function getProductRelated($product_id) {
$product_data = array();
$product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
foreach ($product_related_query->rows as $result) {
$product_query = $this->db->query("SELECT DISTINCT *, 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.product_id = '" . (int)$result['related_id'] . "' 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') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows) {
$product_data[$result['related_id']] = $product_query->row;
}
}
return $product_data;
}
Code: Select all
public function getProductRelatedByManufacturer($manufacturer_id,$product_id) {
$product_data = array();
$product_related_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product WHERE manufacturer_id = '" . (int)$manufacturer_id . "' LIMIT 0,9");
foreach ($product_related_query->rows as $result) {
$product_query = $this->db->query("SELECT DISTINCT *, 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.product_id = '" . (int)$result['product_id'] . "' 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') . "' AND p.date_available <= NOW() AND p.status = '1'"); if ($product_query->num_rows && $result['product_id'] != $product_id) {
$product_data[$result['product_id']] = $product_query->row;
}
}
return $product_data;
}
You now have a built in system that automatically adds products of the same brand or manufacturer but ONLY IF you haven't related products already. If there are no other similar branded products, it should fail silently in much the same way as if there were no related products.
Hopefully someone will find this useful
I'm thinking of adding the functionality to try related by category if there are no brands, but I'm not so sure it's worth it really. Let me know what you think.
Feedback welcome