Page 1 of 1

Related Products

Posted: Wed Jun 24, 2009 9:48 pm
by crt-inc
I can have only one related product? am trying to add more than 1 related product to another one in a different category or same and i just can get one showing up on related products.

I read around looks like a bug? but daniel said it was fixed on the latest release? i just installed the shopping cart yesterday so is the latest version.

Thanks for any help

Re: Related Products

Posted: Thu Jun 25, 2009 12:43 pm
by readyman
yep same here... version 1.2.9 - I'll have a look at this one later today.

Re: Related Products

Posted: Thu Jun 25, 2009 10:51 pm
by readyman
In catalog/model/catalog/product.php in the function getProductsRelated and the very long sql query...

Look for language_id = '" . (int)$this->language->getId() . "' GROUP BY pr.product_id ORDER BY pd.name ASC");

Delete bolded.

Here's the entire 'new' sql for you. Works for me... Daniel or other admin, please confirm this 'fix'.

Code: Select all

$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_related pr LEFT JOIN " . DB_PREFIX . "product p ON (pr.related_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.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) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->language->getId() . "' AND ss.language_id = '" . (int)$this->language->getId() . "' ORDER BY pd.name ASC");

Re: Related Products

Posted: Thu Jun 25, 2009 11:29 pm
by crt-inc
Well it is working now for me as far i add 2 new products, now shows me 2 products on the related items let me add more products and i'll edit the post

Edit: Yes it's working now, thanks so much

Re: Related Products

Posted: Thu Jun 25, 2009 11:47 pm
by Bugbites
Hi,

I have a different related products issue. It displays 2 of the same product on the front end. I tried using the code pasted above but i get an error that a table does not exist. Here is an example of what it is doing...

http://www.discountdesignerhardware.com ... uct_id=216

here is the sql query

Code: Select all

public function getProductRelated($product_id) {
		$query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM product_related pr LEFT JOIN product p ON (pr.related_id = p.product_id) LEFT JOIN product_description pd ON (p.product_id = pd.product_id) LEFT JOIN manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN stock_status ss ON (p.stock_status_id = ss.stock_status_id) LEFT JOIN product_to_category p2c ON (p.product_id = p2c.product_id) WHERE pr.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->language->getId() . "' AND ss.language_id = '" . (int)$this->language->getId() . "' ORDER BY pd.name ASC");
		
		return $query->rows;
And this is in the template to display the related products

Code: Select all

<?php if ($products) { ?>
    <table class="list">
      <?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?>
      <tr>
        <?php for ($j = $i; $j < ($i + 4); $j++) { ?>
        <td width="25%"><?php if (isset($products[$j])) { ?>
          <a href="<?php echo $products[$j]['href']; ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" /></a><br />
          <a href="<?php echo $products[$j]['href']; ?>"><?php echo $products[$j]['name']; ?></a><br />
          <span style="color: #999; font-size: 11px;"><?php echo $products[$j]['model']; ?></span><br />
          <?php if (!$products[$j]['special']) { ?>
          <span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span><br />
          <?php } else { ?>
          <span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
          <?php } ?>
          <?php if ($products[$j]['rating']) { ?>
          <img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" />
          <?php } ?>
          <?php } ?>

Re: Related Products

Posted: Thu Jun 25, 2009 11:57 pm
by crt-inc
what is your cart version? i have the latest one and this works for me and i don't have the problem that you say

check here: http://68.196.1.236/store/index.php?rou ... duct_id=52

Re: Related Products

Posted: Fri Jun 26, 2009 12:01 am
by Bugbites
Yes I also have the latest version. I.2.8

Re: Related Products

Posted: Fri Jun 26, 2009 12:15 am
by crt-inc
Nop, latest is 1.2.9 check it

Re: Related Products

Posted: Fri Jun 26, 2009 12:22 am
by Bugbites
Oh I see. Do you know of a solution that I can fix my issue with? I have 2 mods that I do not want to loss by upgrading. Does the upgrade effect mods?

Re: Related Products

Posted: Fri Jun 26, 2009 12:26 am
by crt-inc
well maybe the others guys can, i just started to work on this cart since 3 days ago and i liked so much but still i have a long way to go to learn more.

Re: Related Products

Posted: Fri Jun 26, 2009 11:57 am
by readyman
You would have to be specific about the problems that you are having in those mods for me to help. Maybe you could start a different topic.

Re: Related Products

Posted: Tue Jul 21, 2009 1:56 am
by kdmp
readyman wrote:In catalog/model/catalog/product.php in the function getProductsRelated and the very long sql query...

Look for language_id = '" . (int)$this->language->getId() . "' GROUP BY pr.product_id ORDER BY pd.name ASC");

Delete bolded.
Okay when I used the provided correction by readyman the related products were doubling up and in some cases tripling. I think I have resolved this by simply changing it to this:
...language_id = '" . (int)$this->language->getId() . "' GROUP BY pd.product_id ORDER BY pd.name ASC");
Change the PR to PD and that will stop the 'doubling' / 'tripling' :)