Mostly resolved.
I have one minor thing that I want to do, that I have not yet figured out - and that is, I want the usps module to return a reasult set that will simply parse into the estimator and rate chart - You'll see it in the code to follow in usps.php where, for now I simply return an error value.
NOTE all paths I mention are from the /catalog/ directory..
file: /includes/databse.php
Bottom of the file, about line 98
//BOM: UPS RESTRICTION on products - NOTE: Must run the following query on store's database manually - if your db uses a prefix, you need to edit the query
//create table restricted_products (id int(11) unsigned not null auto_increment,products_id int(11) not null default 0, primary key id(id), index productid(products_id))type=MyISAM;
define('TABLE_RESTRICTED_PRODUCTS',DB_PREFIX.'restricted_products');
//EOM: UPS RESTRICTION on products
file:/includes/languages/english/modules/shipping/usps.php
end of file, around like 28
//BOM: UPS Ground only restriction
//NOTE: This language string is desired to be shown in the rate chart and/or estimator, need to adjust usps.php module to get a correct return
define('MODULE_SHIPPING_USPS_RESTRICTED','<br />Due to a restricted product in your shopping cart, we are only able to offer UPS Ground shipping.');
//EOM: UPS Ground only restriction
file: /includes/modules/shipping/ups.php
around line 179, after $qsize variable
$qsize = sizeof($upsQuote);
//BOM: Restricted shipping to UPS ground only
$restricted_products = array();
global $db;
$ups_only=$db->Execute("select * from ".TABLE_RESTRICTED_PRODUCTS." order by products_id");
while(!$ups_only->EOF)
{
array_push($restricted_products,$ups_only->fields['products_id']);
$ups_only->MoveNext();
}
//Testing:
//$restricted_products = array('130');
$restricted_in_cart = $_SESSION['cart']->get_products();
while($check_is_restricted=array_shift($restricted_in_cart))
{
if(in_array($check_is_restricted['id'],$restricted_products))
{
$is_ground_only = true;//setting this just in case I want to use it elsewhere
$allowed_methods = array('GND');
}
}
//EOM: Restricted shipping to UPS ground only
File: /includes/modules/shipping/usps.php
around line 183-185
$this->_setWeight($shipping_pounds, $shipping_ounces);
$uspsQuote = $this->_getQuote();
//BOM: UPS ground on restricted items
//At this point, since we are checking for ground only shipments, we want to force UPS , so return
//a value indicating items in cart are restricted and must ship UPS ground only
$restricted_products = array();
global $db;
$ups_only=$db->Execute("select * from ".TABLE_RESTRICTED_PRODUCTS." order by products_id");
while(!$ups_only->EOF)
{
array_push($restricted_products,$ups_only->fields['products_id']);
$ups_only->MoveNext();
}
//Testing:
//$restricted_products = array('130');
$restricted_in_cart = $_SESSION['cart']->get_products();
while($check_is_restricted=array_shift($restricted_in_cart))
{
if(in_array($check_is_restricted['id'],$restricted_products))
{
//TODO: Need to set up so that the quotes returns a single line which can be parsed and displayed *only* (without allowing it to be selected) somewhere in both estimator and quote/shipping method selection.. havent gotten to that yet, so returning an error for now.
$this->quotes = array('module' => $this->title,'error' => MODULE_SHIPPING_USPS_RESTRICTED);
return $this->quotes;
}
}
//EOM: UPS ground on restricted items
if (is_array($uspsQuote)) {
if (isset($uspsQuote['error'])) {
Now for the admin side- I just made a simple hack rather than a more correct modular plugin - quick and dirty does the job well enough
file: {ADMIN_FOLDER}/includes/modules/product/collect_info.php
around line 504 (of mine) insert a new table row just before the close table tag:
<!-- BOM: Restrict product to UPS ground only --->
<?php
$restricted_check=$db->Execute("select * from restricted_products where products_id='".$pinfo->products_id."'");
if(!$restricted_check->EOF)
{
$is_restricted=1;
}
?>
<tr>
<td class="main"><?php echo 'Restricted Product'; ?></td>
<td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_checkbox_field('is_restricted', '1',$is_restricted,1); ?></td>
</tr>
<!-- EOM: Restrict product to UPS ground only -->
</table></td>
and finally ..
file: {ADMIN_FOLDER}/includes/modules/update_product.php
starting around line 85 ...
$db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
(products_id, categories_id)
values ('" . (int)$products_id . "', '" . (int)$current_category_id . "')");
//BOM: Restricted product to ground shipping only.
if(!empty($_POST['is_restricted']) && $_POST['is_restricted'] == 1)
{
$db->Execute("insert into restricted_products (products_id) values ('" . (int)$products_id . "')");
}
else
{
//However if we uncheck the box later, we need to remove it...
$db->execute("delete from restricted_products where products_id in ('" . (int)$products_id . "')");
//var_dump($_POST['is_restricted']);
}
//EOM: Restricted product to ground shipping only
///////////////////////////////////////////////////////
//// INSERT PRODUCT-TYPE-SPECIFIC *INSERTS* HERE //////
//// *END OF PRODUCT-TYPE-SPECIFIC INSERTS* ////////
///////////////////////////////////////////////////////
} elseif ($action == 'update_product') {
$update_sql_data = array( 'products_last_modified' => 'now()',
'master_categories_id' => ($_POST['master_category'] > 0 ? zen_db_prepare_input($_POST['master_category']) : zen_db_prepare_input($_POST['master_categories_id'])));
$sql_data_array = array_merge($sql_data_array, $update_sql_data);
zen_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', "products_id = '" . (int)$products_id . "'");
//BOM: Restricted product to ground shipping only.
if(!empty($_POST['is_restricted']) && $_POST['is_restricted'] == 1)
{
$db->Execute("insert into restricted_products (products_id) values ('" . (int)$products_id . "')");
}
else
{
//However if we uncheck the box later, we need to remove it...
$db->execute("delete from restricted_products where products_id in ('" . (int)$products_id . "')");
}
//EOM: Restricted product to ground shipping only
// reset products_price_sorter for searches etc.
zen_update_products_price_sorter((int)$products_id);
///////////////////////////////////////////////////////
//// INSERT PRODUCT-TYPE-SPECIFIC *UPDATES* HERE //////
Pretty simplistic, but it does exactly the job I need it to do, and for products so added to the restricted products table, it does indeed work exactly as intended - forces UPS Ground as the only possible shipping option when specific restricted products are selected.
I'm sure the code above can be used as the basis for some module or plugin to solve several other "similar, but not identical" issues that other people may have.