Post by hillfish » Tue Sep 21, 2010 1:20 pm

Hi

I add 30 products - each product as it is added gets assigned 4 related products. so I finish adding the 30 and go back to check on some of the products I added and they now have extra random 'related' products, presumably added by mr nobody lol.
There seems to be no pattern to it - the extra (unrequested) related products are picked from random catagories.
I can delete the extra items, but I assume as I add more products it will just happen again.

Just for info - all the numbers (except the 4 related products, which is the number of RP's I was adding)) are just for example - could be any number.
This is on a virgin install of 1491 on it's own domain name.

That's about it ???
Cheers

New member

Posts

Joined
Wed Mar 03, 2010 2:31 am

Post by Johnathan » Tue Sep 21, 2010 8:43 pm

This is most likely due to related products being actually related in 1.4.9.1. This means, for example, that when you choose item A to be a related product for item B, then item B becomes a related product for item A. This behavior makes sense (and is quite handy!), since you shouldn't really have one-way "related" products.

Image
Image Image Image Image


User avatar
Global Moderator

Posts

Joined
Fri Dec 18, 2009 3:08 am


Post by Qphoria » Tue Sep 21, 2010 10:04 pm

Johnathan wrote: This is most likely due to related products being actually related in 1.4.9.1. This means, for example, that when you choose item A to be a related product for item B, then item B becomes a related product for item A. This behavior makes sense (and is quite handy!), since you shouldn't really have one-way "related" products.
Actually Cross-linked related products was added to 1.4.8. But ya that could be what he is seeing.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hillfish » Tue Sep 21, 2010 10:32 pm

Johnathan wrote: This is most likely due to related products being actually related in 1.4.9.1. This means, for example, that when you choose item A to be a related product for item B, then item B becomes a related product for item A. This behavior makes sense (and is quite handy!), since you shouldn't really have one-way "related" products.
Ah I see - thanks for that ;)
Only thing is that it is a bug to me - the last thing I want to do is lead my visitors round in circles lol.
This being the case, can anyone point me at the bit of code I need to rip out to get it working 'my way' ie only related products I add actually get added. This is critically important to me - really life or death of using opencart for this particular project. Thanks :)

New member

Posts

Joined
Wed Mar 03, 2010 2:31 am

Post by Qphoria » Wed Sep 22, 2010 1:46 am

LOL easy with the drama. Life or Death indeed. You are the odd man out with NOT wanting this as most would expect it.

Anyway, to rip it out you can do:

1. EDIT: admin/model/catalog/product.php
2. FIND & DELETE 2 INSTANCES OF:

Code: Select all

$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
 
3. ALSO FIND & DELETE (thanks dbstr for reminding me):

Code: Select all

$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); 

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hillfish » Wed Sep 22, 2010 2:04 am

Aw that's absolutely brilliant - thanks a huge amount :-*
It's curious - I talked with a collegue today about this and he felt the same as you - said it seemed like the way to do it. Personally I see it exactly 180degrees oposite lol (I don't want anything happening that I didn't specifically ask for). Actually for the project I'm working on it really is completely necassery to do it 'my way' or the whole thing kinda falls appart (it's an odd project lol)
Thanks again - you've saved me having to start over ;D

New member

Posts

Joined
Wed Mar 03, 2010 2:31 am

Post by Qphoria » Wed Sep 22, 2010 11:27 pm

Cleaned up this thread and moved out of bug reports. Try the above changes again, I've merged all 3 changes into one post. There are 3 lines total to delete

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hillfish » Thu Sep 23, 2010 12:00 am

Qphoria wrote:Cleaned up this thread and moved out of bug reports. Try the above changes again, I've merged all 3 changes into one post. There are 3 lines total to delete
Thanks Q - I was feeling a bit bad that this was taking over the bug report thread.
I will follow exactly what you have suggested, and I really appreciate the help :-*

New member

Posts

Joined
Wed Mar 03, 2010 2:31 am

Post by hillfish » Thu Sep 23, 2010 10:01 pm

Hi
It worked like a charm !
Now the cart is operating exactly as I need it to - I'm so pleased :drunk:

Thank you all very much - this forum is so friendly !

New member

Posts

Joined
Wed Mar 03, 2010 2:31 am

Post by colt1911 » Thu Mar 22, 2012 1:59 am

Qphoria, you say to delete 3 lines...

Unless I'm nuts (good possibility :laugh: ) I see *2* lines of the following code that you said to delete *1* time. One around line 86, the other around line 226.

Which instance of this should I delete? Or delete both?

Code: Select all

$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); 
When I deleted all four lines (INSERTS and DELETES), it doesn't reciprocal link (good for me). BUT, if two items are *supposed* to reciprocate, one gets deleted if I add the other. How am I screwing this up?

New member

Posts

Joined
Sat Sep 24, 2011 1:23 am

Post by colt1911 » Thu Mar 22, 2012 2:01 am

PS: my vs is 1.5.1.1

New member

Posts

Joined
Sat Sep 24, 2011 1:23 am

Post by louie55 » Sun Nov 18, 2012 2:05 am

colt1911 wrote:Qphoria, you say to delete 3 lines...

Unless I'm nuts (good possibility :laugh: ) I see *2* lines of the following code that you said to delete *1* time. One around line 86, the other around line 226.

Which instance of this should I delete? Or delete both?

Code: Select all

$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'"); 
When I deleted all four lines (INSERTS and DELETES), it doesn't reciprocal link (good for me). BUT, if two items are *supposed* to reciprocate, one gets deleted if I add the other. How am I screwing this up?
I know this is an older thread, but I also had the same need, so I decided to bring it back to life. I also had the same problem as you after removing the lines. Where it worked fine if you added a related product, it wouldn't show up the other way around when you went to that related product. However, if you WANTED those certain 2 products to point to each other, it would always delete the related product on the opposite one when I added it to the other one.

To fix this, you also need to find and delete this line from the same file:

Code: Select all

$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'");
I am using version 1.5.4.1


I will also explain briefly why I wanted this feature disabled since many don't seem to understand why you wouldn't want it. The answer is, many of my products have a one-to-many relationship. For example, (we sell agricultural parts) we have a bunch of gearbox shafts in our store that all use the same nut that threads on one end. I want that nut to show up as a related product for each shaft, since it is an accessory to it. However, I do NOT want EVERY shaft showing up as a related product when a customer views the nut. Because that would just confuse them as they would never need every shaft, just the one that fits their machine. You could use the same reasoning with a more common type of store, like a store that sells electronics. A pair of headphones fits MANY products. MP3 players, Laptops, CD Players, Tablets, Phones, etc. So, you could add headphones as a related product to all of those things. That would make sense. But if you go to the product page for the headphones, do you really want ALL the things that the headphones fit to show up on related products?? The customer is likely looking at the headphones because they already have a device that they will fit into, so listing every device in your store that take headphones seems unnecessary and a waste of resources and page-load time.

Newbie

Posts

Joined
Sun Nov 18, 2012 1:34 am

Post by wired-circuit » Thu Jan 09, 2014 6:58 am

Shouldn't it be this line

Code: Select all

$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
not

Code: Select all

$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
Also shouldn't one of the delete lines get commented or removed?

Code: Select all

$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'");
or

Code: Select all

$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");

New member

Posts

Joined
Thu Mar 24, 2011 2:48 pm

Post by wired-circuit » Thu Jan 09, 2014 9:42 pm

Hours of playing around with this chasing around in circles, I found that I have had to do the following:

Code: Select all

		if (isset($data['product_related'])) {
			foreach ($data['product_related'] as $related_id) {
				//$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'");
				$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
				//$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'");
				//$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
			}
		}
AND..

Code: Select all

		$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
		//$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'");

		if (isset($data['product_related'])) {
			foreach ($data['product_related'] as $related_id) {
				//$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'");
				$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
				//$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'");
				//$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
			}
		}
Not fully sure what the effect of commenting all the DELETE's out yet, but it was the only way I could get the related products to work in the manner expected, without auto relating on the reverse side. I will update if I find more changes are required.

[Version 1.5.6]

New member

Posts

Joined
Thu Mar 24, 2011 2:48 pm

Post by circey » Wed Jan 22, 2014 12:51 pm

@wired-circuit I could kiss you! You have saved my sanity :)

New member

Posts

Joined
Thu Sep 23, 2010 4:22 pm

Post by matt71 » Thu Jul 17, 2014 2:42 am

For those looking to remove reciprical related products, @wired-circuit's fix is the one that works for 1.5.4.1.

Thanks for the hard work. I've been messing around with this for hours and your fix works perfectly!

New member

Posts

Joined
Sat Jan 19, 2013 4:13 am

Post by matt71 » Sun Nov 20, 2016 12:49 am

Would anyone happen to have this same fix for 2.3.0.2? The lines of code are the same for versions 1.5.4.1 and 2.3.0.2 but the links are still reciprocating when I comment out the correct code.

Thanks
Matt

New member

Posts

Joined
Sat Jan 19, 2013 4:13 am
Who is online

Users browsing this forum: thaoanh12 and 34 guests