Just a forewarning, while I am using this, it is not even close to a complete solution. I also do not use the category filtering in this mod, or the cross-site carts so I have no idea if this would effect their functionality although it seems unlikely. I may never get around to providing this as an addition to this module, so figured it was still worth posting.
I had the need to limit which products were displayed by the stores by something other than categories. For the most part I needed to be able to restrict by manufacturer, but I figured why not make it more flexible while I was at it. So I decided to use the products_status field in the products table. Basically the idea is that you can create a filter group of products by making all of their products_status=2 (or any number). I keep the regular products that all stores can see on status=1. Then only the stores that are specifically given access to a status of 2 will be able to see the products in question. Doing this gives me unlimited product filtering flexibility. If I wanted to create tools to limit it by manufacturer it would be simple enough, although at the moment I just manually update the database where I see fit.
The other advantage to this solution for me is that I share the products,categories,manufacturers tables (mysql symbolic link) with another non-multisite store. By limiting products in this way the non-multisite store without any modifications will not see the products specified in a filter group.
What I did was install this function (put it in a file in includes/functions/extra_functions of any PHP filename):
PHP Code:
function status_query_phrase()
{
global $status_access;
$query_phrase = "(";
foreach ((array)$status_access as $status)
{ $query_phrase .= "p.products_status = '". $status ."' OR "; }
$query_phrase = rtrim($query_phrase,"OR ");
$query_phrase .= ")";
return $query_phrase;
}
In each store config file includes\config_sites\www.example.com_config.php create the $status_access array:
PHP Code:
$status_access = array("1","2");
Make sure each store has at least "1" so it can see the globally available products. You could make that a default in the function (if the array didn't exist) if you'd like, I chose not to.
Then I just used the zen cart developer tool to search for p.products_status and replaced each occurrence where products_status is in the "where" clause with status_query_phrase() like the example below from includes/functions/functions_categories.php
PHP Code:
$products_query = "select count(*) as total
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
where p.products_id = p2c.products_id
and ". status_query_phrase() ."
and p2c.categories_id = '" . (int)$category_id . "'";
Then you have to update the database and set the products you want in their respective filter groups. So for example if I wanted the manufacturer_id=5 to be only visible to one of my stores I would:
Code:
update products set products_status=2 where manufacturers_id=5;
Then in the config file for the store that needs access add 2 to the status_access array.
Anyway, sorry for the roughness of this but I hope it's useful to someone out there.
Bookmarks