What I would like to do have one master brand setting which I can set in ie. config.php
So let's say: $config_brand = "philips";
The rest of the site should only use products from this brands.
Categories.php / merchants.php / products.php / search.php should only give results where brand=$config_brand
Any suggestions how to fix this?
Hi David,
Yes I would like to have the other products remain in the database. So it should be possible to change the brand anytime. Still any suggestions?
Paul
Hi Paul,
Bear with me - i'll run through the SQL statements that would need changing...
Hi,
In categories.php, change line 6 to:
$sql = "SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` WHERE brand='".database_safe($config_brand)."' ORDER BY category";
In merchants.php, change line 6 to:
$sql = "SELECT DISTINCT(merchant) FROM `".$config_databaseTablePrefix."products` WHERE brand='".database_safe($config_brand)."' ORDER BY merchant";
As you will notice, this is a more complex query than the original. I think it will be ok, but keep an eye on performance when selecting the merchant list. I'm assuming here that you only want the list of merchants who have products in $config_brand....
In products.php, you need to insert a line at line 74:
$where .= " AND brand = '".database_safe($config_brand)."'";
The above code needs to go between the line that builds the $sql = ... and the previous $where .= statement.
search.php needs quite a few changes. If you have made modifications already it's probably best to look at a separate copy of the original files to see which lines to change....
Line 43, insert:
$where .= " AND brand ='".database_safe($config_brand)."' ";
Line 68 change to:
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants, MATCH name AGAINST ('".database_safe($parts[0])."') AS relevance FROM `".$config_databaseTablePrefix."products` WHERE brand='".database_safe($config_brand)."' AND MATCH name AGAINST ('".database_safe($parts[0])."') GROUP BY name";
Line 70 change to:
$sqlResultCount = "SELECT COUNT(DISTINCT(name)) as resultcount FROM `".$config_databaseTablePrefix."products` WHERE brand='".$config_brand."' AND MATCH name AGAINST ('".database_safe($parts[0])."')";
Line 73 change to:
$sql = "SELECT * , MIN( price ) AS minPrice, MAX( price ) AS maxPrice, COUNT( id ) AS numMerchants FROM `".$config_databaseTablePrefix."products` WHERE brand='".database_safe($config_brand)."' AND search_name LIKE '%".database_safe($parts[0])."%' GROUP BY name";
Line 75 change to:
$sqlResultCount = "SELECT COUNT(DISTINCT(name)) as resultcount FROM `".$config_databaseTablePrefix."products` WHERE brand='".database_safe($config_brand)."' AND search_name LIKE '%".database_safe($parts[0])."%'";
I think that's it....!
Hope this helps,
Cheers,
David.
Hi,
Do you still want other products to remain in the database? If not, the easiest way to do this would be to limit the import to $config_brand. You could do this in includes/admin.php within the admin__importRecordHandler() function. Go to line 226 where you will find the following comment:
/* construct brand value if required */
Immediately after the associated code, and before the dupe_hash code you could add the following to restrict your site at import time:
global $config_brand;
if ($brand <> $config_brand) return;
By return from the record handler function the product will not be imported unless the brand field matches $config_brand...
Hope this helps!
Cheers,
David.