Posted - 10/12/2021 : 07:53:25
Here is how we have auto related items for a few years now by adding a group related function added to the inccrosssell.php
Add this to your includes file: $csgrouprelatedtitle="For example Your Title for auto related items";
Add the group related option to the includes or individually on the productdetails.php, cart.php, etc... as required. $crosssellaction="grouprelated,related";
Adjust how you want the grouping to work $productlist=substr($prodlist,[blue]1,6[/blue]); This matches every product ID from the 1st to 6th characters.
In inccrosssell.php just below the related function around line 163:
[code]
elseif($crosssellaction=='grouprelated'){ // Products recommended with this product (Would need v5.1) if(@$csgrouprelatedtitle=='') $crossselltitle='Alternative choices with items in your cart.'; else $crossselltitle=$csgrouprelatedtitle; if($prodlist==''){ $addcomma=''; $sSQL = "SELECT cartProdID FROM cart WHERE cartCompleted=0 AND cartSessionID='" . escape_string($thesessionid) . "'"; $result=ect_query($sSQL) or ect_error(); while($rs=ect_fetch_assoc($result)){ $prodlist.=$addcomma . "'" . escape_string($rs['cartProdID']) . "'"; $addcomma=','; } ect_free_result($result); } if($prodlist!=''){ [blue]$productlist=substr($prodlist,1,6);[/blue] $sSQL = 'SELECT pID FROM products WHERE pID Like "' . $productlist . '%"'; $addcomma=''; $relatedlist=''; $result=ect_query($sSQL) or ect_error(); while($rs=ect_fetch_assoc($result)){ $relatedlist.=$addcomma . "'" . escape_string($rs['pID']) . "'"; $addcomma=','; } ect_free_result($result); } [/code]
You can also optionally add this to the includes file [blue]$productlist=substr($prodlist,1,6);[/blue] to make it easier to tweak to match your own requirements and scheme for product ID's.
As an example in our product ID's we use 5 numbers at the start which are always unique followed by 2 to 5 letters for related items. e.g. A product ID with 65486RSCA will be auto related to all items with product ID beginning with 65486R. You can tweak to however you want but you do need to first standardise your product ID's so this will work.
John
Edited by - John M on 10/12/2021 09:55:08
|