Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 08-16-2010 08:26:59

ashley
Member
Registered: 08-16-2010
Posts: 41

Random Related Products

I am trying to get it to display the related products on the product pages.  I need it to only display two items(I've managed to do that, but it's an ugly 'hack') and to display two random products from that category(using xcat, ideally).

Currently I have it to display two products and it seems to be selecting them from the category but unfortunately it wont display randomly.  It just displays the same two each time.

Also all of the categories, with the exception of one, are displaying just two.  However one category is somehow displaying more than 2.

Help would be greatly appreciated.

Last edited by ashley (08-16-2010 08:52:57)

Offline

 

#2 08-16-2010 10:55:36

vbsaltydog
Member
From: Florida
Registered: 05-02-2005
Posts: 947
Website

Re: Random Related Products

ashley wrote:

I am trying to get it to display the related products on the product pages.  I need it to only display two items(I've managed to do that, but it's an ugly 'hack') and to display two random products from that category(using xcat, ideally).

Currently I have it to display two products and it seems to be selecting them from the category but unfortunately it wont display randomly.  It just displays the same two each time.

Also all of the categories, with the exception of one, are displaying just two.  However one category is somehow displaying more than 2.

Help would be greatly appreciated.

It is hard to help without seeing what code edits you made but the general idea is that you edit the code that looks for/pulls related products and change it to pull two items from the xcat of the ref being displayed with order by rand(*) limit 2 in the sql statement but you also need to add id<>$ref so that you dont have related items the same as the main item being displayed.

Note that any of these edits will very possibly be overwritten by CCP updates since you are modifying the Ecom_Prod class.


Latest CCP 7 XMods Available:


Offline

 

#3 08-16-2010 11:03:48

ashley
Member
Registered: 08-16-2010
Posts: 41

Re: Random Related Products

vbsaltydog wrote:

It is hard to help without seeing what code edits you made but the general idea is that you edit the code that looks for/pulls related products and change it to pull two items from the xcat of the ref being displayed with order by rand(*) limit 2 in the sql statement but you also need to add id<>$ref so that you dont have related items the same as the main item being displayed.
Note that any of these edits will very possibly be overwritten by CCP updates since you are modifying the Ecom_Prod class.

I have tried editing the SQL query a few times to no effect.  I ended up detecing what page was loaded and if it was gbu-prodshow then set $count to 2.  However this isn't a great way of doing it, I know, but when editing the SQL it either produced a foreach error or just didn't work.

Offline

 

#4 08-16-2010 11:04:32

KryptoJim
Member
Registered: 07-08-2010
Posts: 455

Re: Random Related Products

ashley wrote:

vbsaltydog wrote:

It is hard to help without seeing what code edits you made but the general idea is that you edit the code that looks for/pulls related products and change it to pull two items from the xcat of the ref being displayed with order by rand(*) limit 2 in the sql statement but you also need to add id<>$ref so that you dont have related items the same as the main item being displayed.
Note that any of these edits will very possibly be overwritten by CCP updates since you are modifying the Ecom_Prod class.

I have tried editing the SQL query a few times to no effect.  I ended up detecing what page was loaded and if it was gbu-prodshow then set $count to 2.  However this isn't a great way of doing it, I know, but when editing the SQL it either produced a foreach error or just didn't work.

Can you post the edits you made?

Offline

 

#5 08-16-2010 11:17:06

vbsaltydog
Member
From: Florida
Registered: 05-02-2005
Posts: 947
Website

Re: Random Related Products

If you cant get the answer that you need in the forum, I could write the mod for you very affordably but the problem is that any CCP Updates that overwrite the Ecom_prod class will overwrite the mod. This is the inherent problem with CCP 7+

In order to mod CCP 7+ , you need to read the changelog for any Updates BEFORE you run them, check to see if your altered files are effected by the update, and restore your changes to the altered files after the update runs. this makes Non-CCP XMODS very difficult to maintain over updates to CCP.

This heavily impacts the extensibility of CCP 7+

Last edited by vbsaltydog (08-16-2010 11:27:16)


Latest CCP 7 XMods Available:


Offline

 

#6 08-16-2010 11:17:59

ashley
Member
Registered: 08-16-2010
Posts: 41

Re: Random Related Products

Code:

// +--

// | Piece together our SQL statement and execute it.

// +--



if (empty($count)) {$count = 10;}

$theURL = explode("/", $_SERVER['REQUEST_URI']);

if($theURL[2] == "gbu0-prodshow") {
     $count = 2;
}

$sql .= $where;

if($theURL[2] == "gbu0-prodshow") {

$result = $this->KHXC_DB->sql_do(array('sql'    => $sql,

                                       'table'  => $table,

                                       'order'  => "RAND()",

                                       'count'  => $count,

                                       'offset' => $offset));

} else {
     $result = $this->KHXC_DB->sql_do(array('sql'    => $sql,

                                       'table'  => $table,

                                       'order'  => array($sortfield => $sorttype),

                                       'count'  => $count,

                                       'offset' => $offset));
}

Starts on like 836ish in GBU_Prod.php.  Like I said, ugly hack though!

Last edited by ashley (08-16-2010 11:18:44)

Offline

 

#7 08-16-2010 11:23:43

vbsaltydog
Member
From: Florida
Registered: 05-02-2005
Posts: 947
Website

Re: Random Related Products

Enable debugging to see what your resulting sql statement is and any errors. I think you will find that your rand needs to be rand(*)


Latest CCP 7 XMods Available:


Offline

 

#8 08-16-2010 11:32:18

ashley
Member
Registered: 08-16-2010
Posts: 41

Re: Random Related Products

vbsaltydog wrote:

Enable debugging to see what your resulting sql statement is and any errors. I think you will find that your rand needs to be rand(*)

It does produce results, it outputs just two results but just not randomly. 

Now trying to * in the query.

Edit: Just tried adding the * into the rand() and it made no difference.  Still displaying two results(the same on every page for each category) so not randomly.

Last edited by ashley (08-16-2010 11:33:49)

Offline

 

#9 08-16-2010 11:37:25

vbsaltydog
Member
From: Florida
Registered: 05-02-2005
Posts: 947
Website

Re: Random Related Products

Enable the debugger and paste the SQL that was run.


Latest CCP 7 XMods Available:


Offline

 

#10 08-17-2010 00:21:49

KryptoJim
Member
Registered: 07-08-2010
Posts: 455

Re: Random Related Products

You could always ignore the RAND from SQL, and use shuffle within php.

Offline

 

#11 08-17-2010 02:51:19

ZipSkins
Member
From: United Kingdom
Registered: 01-15-2006
Posts: 822
Website

Re: Random Related Products

Surely, if it's in GBU_Prod then it's not CCP7?

May not make any difference to the code, but I suggest the thread is in the wrong forum.

Nigel


| Professional Quality Customisable Skins for your ClickCartPro Powered Site


-----------------------------
Certified Support Partner

Offline

 

#12 08-17-2010 03:02:26

ashley
Member
Registered: 08-16-2010
Posts: 41

Re: Random Related Products

kryptsupport wrote:

You could always ignore the RAND from SQL, and use shuffle within php.

Well that would work but I am limiting the query to only two results (except when it's not working on one page) so shuffling the array will only switch which of the two items displays first and not displaying different products each time.

I had an idea of using array_slice() to cut down the $result array to a suitable size (depending on the page, ofcourse) but unfortunately it didn't seem to reduce the amount of items being displayed. 

I tried...

Code:

array_slice($result, 0, 2);

But that kept the SQL at the default length of 10.  So shuffling the array and then slicing it (in theory) will work, but I can't quite get it to work.  Any ideas?

Last edited by ashley (08-17-2010 03:17:15)

Offline

 

Board footer