So we have a few shipping method options available in advshipper, but found that we wanted to restrict certain methods for certain categories.
Below is how we achieved it, bit mechanical, but it works.
In mysql, copy the table and structure of the 'advshipper_method_categories' to a new table called 'advshipper_method_categories_exclude'
For each method that you want to exclude for a category then add it in.
for example i want to exclude method 2 for all products in category 274
i simply insert: 1,2,1,274 to the table.
in the includes/modules/shipping/advshipper.php
around line 580 find:
Code:
// First, determine if this product is included in any specific shipping methods
if ($use_product_selection_lookups) {
$product_specific_methods =
$this->_getProductSpecificShippingMethods($product_id, $product_attributes);
$product_methods = $product_specific_methods;
}
then after add:
Code:
$category_specific_methods =
$this->_getCategoryExcludeShippingMethods($product_id);
//
//$disabled_methods[] = $disabled_methods_result->fields['method'];
//
for ($csm_i = 0, $num_csm = sizeof($category_specific_methods); $csm_i < $num_csm;
$csm_i++) {
if (!in_array($category_specific_methods[$csm_i], $disabled_methods)) {
$disabled_methods[] = $category_specific_methods[$csm_i];
}
}
around line 1098 add:
Code:
function _getCategoryExcludeShippingMethods($product_id)
{
global $db;
$category_specific_methods = array();
// Get all categories this product is in
$categories_for_product = array();
$categories_for_product_query = "
SELECT
DISTINCT categories_id
FROM
" . TABLE_PRODUCTS_TO_CATEGORIES . "
WHERE
products_id = '" . (int) $product_id . "';";
$categories_for_product_result = $db->Execute($categories_for_product_query);
while (!$categories_for_product_result->EOF) {
$categories_for_product[] = $categories_for_product_result->fields['categories_id'];
$categories_for_product_result->MoveNext();
}
if (sizeof($categories_for_product) > 0) {
// Must get all sub-categories for the categories found
$parent_categories = array();
foreach ($categories_for_product as $category_id) {
zen_get_parent_categories($parent_categories, $category_id);
}
$categories_for_product = array_merge($categories_for_product, $parent_categories);
$category_ids_string = implode(',', $categories_for_product);
$check_methods_for_categories_sql = "
SELECT
DISTINCT asmc.method
FROM
advshipper_method_categories_exclude asmc
WHERE
asmc.config_id = '" . $this->_config_id . "'
AND
asmc.category_id IN (" . $category_ids_string . ")
ORDER BY
asmc.method;";
$check_methods_for_categories_result = $db->Execute($check_methods_for_categories_sql);
if ($check_methods_for_categories_result->EOF) {
// No methods specifically cover these categories
} else {
while (!$check_methods_for_categories_result->EOF) {
$category_exclude_methods[] =
$check_methods_for_categories_result->fields['method'];
$check_methods_for_categories_result->MoveNext();
}
}
}
return $category_exclude_methods;
}
thats it.
Bookmarks