Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Hide products from customer groups for SPPC - Multiple Groups per User


Shadow-Lord

Recommended Posts

Hi,

 

How can I have 'Hide products from customer groups for SPPC' work for multiple groups per user.

 

If the user is a member of multiple groups how can I get it work this way.

 

0 - Retail.

1 - Games.

2 - CDs.

3 - Wholesale.

 

So the user is a member of groups 0,1,2 but not a member of 4.

 

My customers_group_id field in customer Table is like:

 

 `customers_group_id` char(250) collate utf8_unicode_ci NOT NULL default '';

 

The data in that field is in the format of e.g. 0,1,2

 

 

Can anyone get this working please.

Link to comment
Share on other sites

How can I have 'Hide products from customer groups for SPPC' work for multiple groups per user.

 

If the user is a member of multiple groups how can I get it work this way.

 

0 - Retail.

1 - Games.

2 - CDs.

3 - Wholesale.

 

So the user is a member of groups 0,1,2 but not a member of 4.

 

My customers_group_id field in customer Table is like:

I don't see how you could do this. I don't even see how you can make SPPC work. How do you determine the price for a customer when he/she belongs to multiple groups?

Link to comment
Share on other sites

I don't see how you could do this. I don't even see how you can make SPPC work. How do you determine the price for a customer when he/she belongs to multiple groups?

 

Sorry, just what it to work for the hiding of the products/categories.

I wont be using it for the pricing.

Link to comment
Share on other sites

Sorry, just what it to work for the hiding of the products/categories.

You would have at least have to make up your mind now on what you want to do.

 

For example hide the product/category when the customer is in one of the groups for which it is hidden or not hide the product when the customer is in another group for which it is not hidden.

Link to comment
Share on other sites

You would have at least have to make up your mind now on what you want to do.

 

For example hide the product/category when the customer is in one of the groups for which it is hidden or not hide the product when the customer is in another group for which it is not hidden.

 

If the user is a member of 3 groups, I want him to have access to any of the products/categories in those 3 groups at the one time and any other groups be hidden from him.

Link to comment
Share on other sites

Can it work this way.

If you only use it for hiding products and categories I would think so. But the queries should be adjusted to have an and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0 for every group id (explode the comma separated value first to put them in an array etcetera.

Link to comment
Share on other sites

If you only use it for hiding products and categories I would think so. But the queries should be adjusted to have an and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0 for every group id (explode the comma separated value first to put them in an array etcetera.

 

Not sure what you mean.

Link to comment
Share on other sites

If the user is a member of 3 groups, I want him to have access to any of the products/categories in those 3 groups at the one time and any other groups be hidden from him.

This code seems to work for product_info.php. Of course the "hide logic" is reversed now. You are not hiding the product or category when there is an entry for it in the "hide from" column but only showing it when that group is in there. The find_in_set = 0 now becomes find_in_set > 0:

 


    // BOF Separate Pricing Per Customer, hide products and categories from groups
    global $sppc_customer_group_id;
    if(!tep_session_is_registered('sppc_customer_group_id')) { 
    $customer_group_id = ''; // not zero! this has many consequences for queries for price etcetera
    } else {
     $customer_group_id = $sppc_customer_group_id;
    }

 if (strlen($customer_group_id) == 0) {
   $product_check['total'] = 0;
 } else {
 $customer_group_id_array = explode(",", $customer_group_id);
 // weed out double entries if there are any
 $customer_group_id_array = array_unique($customer_group_id_array);
 $and_hide_product_from = "and (";
 $and_hide_category_from = "and (";
 foreach ($customer_group_id_array as $group_id) {
   $and_hide_product_from_array[] = "find_in_set('". (int)$group_id ."', products_hide_from_groups) > 0";
   $and_hide_category_from_array[] = "find_in_set('". (int)$group_id ."', categories_hide_from_groups) > 0";
 } 
 $and_hide_product_from .= implode(" or ", $and_hide_product_from_array);
 $and_hide_product_from .= ") ";
 $and_hide_category_from .= implode(" or ", $and_hide_category_from_array);
 $and_hide_category_from .= ")";
/* old query:
 $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) left join " . TABLE_CATEGORIES . " c using(categories_id) where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0 and find_in_set('" . $customer_group_id . "', categories_hide_from_groups) = 0"); */
 $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) left join " . TABLE_CATEGORIES . " c using(categories_id) where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' " . $and_hide_product_from . $and_hide_category_from . " ");
  $product_check = tep_db_fetch_array($product_check_query);
  // EOF Separate Pricing Per Customer, hide products and categories from groups
}
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

Of course this has to be changed accordingly in a large number of files...

Link to comment
Share on other sites

Thanks for replying with this.

 

Do I still need to have the hide_products_and_categories and separate_price_per_customers mod or just the above code.

 

Could you post your full working product_info.php file, if you wouldn't mind please.

Link to comment
Share on other sites

Do I still need to have the hide_products_and_categories and separate_price_per_customers mod or just the above code.

 

Could you post your full working product_info.php file, if you wouldn't mind please.

This is the code I changed. If you don't use the rest of SPPC you should have no SPPC code further on.

Link to comment
Share on other sites

My product_info.php is :

 

<?php
/*
 $Id$

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);

    // BOF Separate Pricing Per Customer, hide products and categories from groups
    global $sppc_customer_group_id;
    if(!tep_session_is_registered('sppc_customer_group_id')) { 
    $customer_group_id = ''; // not zero! this has many consequences for queries for price etcetera
    } else {
     $customer_group_id = $sppc_customer_group_id;
    }

 if (strlen($customer_group_id) == 0) {
   $product_check['total'] = 0;
 } else {
 $customer_group_id_array = explode(",", $customer_group_id);
 // weed out double entries if there are any
 $customer_group_id_array = array_unique($customer_group_id_array);
 $and_hide_product_from = "and (";
 $and_hide_category_from = "and (";
 foreach ($customer_group_id_array as $group_id) {
   $and_hide_product_from_array[] = "find_in_set('". (int)$group_id ."', products_hide_from_groups) > 0";
   $and_hide_category_from_array[] = "find_in_set('". (int)$group_id ."', categories_hide_from_groups) > 0";
 } 
 $and_hide_product_from .= implode(" or ", $and_hide_product_from_array);
 $and_hide_product_from .= ") ";
 $and_hide_category_from .= implode(" or ", $and_hide_category_from_array);
 $and_hide_category_from .= ")";
/* old query:
 $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) left join " . TABLE_CATEGORIES . " c using(categories_id) where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0 and find_in_set('" . $customer_group_id . "', categories_hide_from_groups) = 0"); */
 $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) left join " . TABLE_CATEGORIES . " c using(categories_id) where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' " . $and_hide_product_from . $and_hide_category_from . " ");
         $product_check = tep_db_fetch_array($product_check_query);
  // EOF Separate Pricing Per Customer, hide products and categories from groups
}


 require(DIR_WS_INCLUDES . 'template_top.php');
?>

<script language="javascript"><!--
function popupWindow(url) {
 window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}
//--></script>

   <?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">
<?php
 if ($product_check['total'] < 1) {
?>
     <tr>
       <td><?php new infoBox(array(array('text' => TEXT_PRODUCT_NOT_FOUND))); ?></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
         <tr class="infoBoxContents">
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
               <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
               <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
               <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
             </tr>
           </table></td>
         </tr>
       </table></td>
     </tr>
<?php
 } else {
   $product_info_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
   $product_info = tep_db_fetch_array($product_info_query);

   tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . (int)$languages_id . "'");

   if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
// BOF Separate Pricing per Customer
     if ($customer_group_id > 0) { // only need to check products_groups if customer is not retail
       $scustomer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id']. "' and customers_group_id =  '" . $customer_group_id . "'");
       if ($scustomer_group_price = tep_db_fetch_array($scustomer_group_price_query)) {
         $product_info['products_price']= $scustomer_group_price['customers_group_price'];
         }
     } // end if ($customer_group_id > 0)
// EOF Separate Pricing per Customer

     $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
   } else {
// BOF Separate Pricing per Customer
     if ($customer_group_id > 0) { // only need to check products_groups if customer is not retail
       $scustomer_group_price_query = tep_db_query("select customers_group_price from " . TABLE_PRODUCTS_GROUPS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id']. "' and customers_group_id =  '" . $customer_group_id . "'");
       if ($scustomer_group_price = tep_db_fetch_array($scustomer_group_price_query)) {
       $product_info['products_price']= $scustomer_group_price['customers_group_price'];
       }
   } // end if ($customer_group_id > 0)
// EOF Separate Pricing per Customer
     $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
   }

   if (tep_not_null($product_info['products_model'])) {
     $products_name = $product_info['products_name'] . '<br><span class="smallText">[' . $product_info['products_model'] . ']</span>';
   } else {
     $products_name = $product_info['products_name'];
   }
?>
     <tr>
       <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
         <tr>
           <td class="pageHeading" valign="top"><?php echo $products_name; ?></td>
           <td class="pageHeading" align="right" valign="top"><?php echo $products_price; ?></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td class="main">
<?php
   if (tep_not_null($product_info['products_image'])) {
?>
         <table border="0" cellspacing="0" cellpadding="2" align="right">
           <tr>
             <td align="center" class="smallText">
<script language="javascript"><!--
document.write('<?php echo '<a href="javascript:popupWindow(\\\'' . tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $product_info['products_id']) . '\\\')">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], addslashes($product_info['products_name']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '<br>' . TEXT_CLICK_TO_ENLARGE . '</a>'; ?>');
//--></script>
<noscript>
<?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES . $product_info['products_image']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], $product_info['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '<br>' . TEXT_CLICK_TO_ENLARGE . '</a>'; ?>
</noscript>
             </td>
           </tr>
         </table>
<?php
   }
?>
         <p><?php echo stripslashes($product_info['products_description']); ?></p>
<?php
// BOF SPPC Hide attributes from customer groups
   $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', attributes_hide_from_groups) = 0 ");
   $products_attributes = tep_db_fetch_array($products_attributes_query);
   if ($products_attributes['total'] > 0) {
?>
         <table border="0" cellspacing="0" cellpadding="2">
           <tr>
             <td class="main" colspan="2"><?php echo TEXT_PRODUCT_OPTIONS; ?></td>
           </tr>
<?php
     $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', attributes_hide_from_groups) = 0 order by popt.products_options_name");
     while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
       $products_options_array = array();
       $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix, pa.products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', attributes_hide_from_groups) = 0");
       $list_of_prdcts_attributes_id = '';
       $products_options = array(); // makes sure this array is empty again
       while ($_products_options = tep_db_fetch_array($products_options_query)) {
       $products_options[] = $_products_options;
       $list_of_prdcts_attributes_id .= $_products_options['products_attributes_id'].",";
   }

     if (tep_not_null($list_of_prdcts_attributes_id) && $customer_group_id != '0') { 
        $select_list_of_prdcts_attributes_ids = "(" . substr($list_of_prdcts_attributes_id, 0 , -1) . ")";
    $pag_query = tep_db_query("select products_attributes_id, options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES_GROUPS . " where products_attributes_id IN " . $select_list_of_prdcts_attributes_ids . " AND customers_group_id = '" . $customer_group_id . "'");
    while ($pag_array = tep_db_fetch_array($pag_query)) {
        $cg_attr_prices[] = $pag_array;
    }

    // substitute options_values_price and prefix for those for the customer group (if available)
    if ($customer_group_id != '0' && tep_not_null($cg_attr_prices)) {
       for ($n = 0 ; $n < count($products_options); $n++) {
        for ($i = 0; $i < count($cg_attr_prices) ; $i++) {
            if ($cg_attr_prices[$i]['products_attributes_id'] == $products_options[$n]['products_attributes_id']) {
               $products_options[$n]['price_prefix'] = $cg_attr_prices[$i]['price_prefix'];
               $products_options[$n]['options_values_price'] = $cg_attr_prices[$i]['options_values_price'];
            }
        } // end for ($i = 0; $i < count($cg_att_prices) ; $i++)
       }
       } // end if ($customer_group_id != '0' && (tep_not_null($cg_attr_prices))
     } // end if (tep_not_null($list_of_prdcts_attributes_id) && $customer_group_id != '0')

  for ($n = 0 ; $n < count($products_options); $n++) {
         $products_options_array[] = array('id' => $products_options[$n]['products_options_values_id'], 'text' => $products_options[$n]['products_options_values_name']);
         if ($products_options[$n]['options_values_price'] != '0') {
           $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options[$n]['price_prefix'] . $currencies->display_price($products_options[$n]['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
         }
       }
// EOF SPPC attributes mod

       if (is_string($HTTP_GET_VARS['products_id']) && isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
         $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
       } else {
         $selected_attribute = false;
       }
?>
           <tr>
             <td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>
             <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>
           </tr>
<?php
     }
?>
         </table>
<?php
   }
?>
       </td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
<?php
   $reviews_query = tep_db_query("select count(*) as count from " . TABLE_REVIEWS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'");
   $reviews = tep_db_fetch_array($reviews_query);
   if ($reviews['count'] > 0) {
?>
     <tr>
       <td class="main"><?php echo TEXT_CURRENT_REVIEWS . ' ' . $reviews['count']; ?></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
<?php
   }

   if (tep_not_null($product_info['products_url'])) {
?>
     <tr>
       <td class="main"><?php echo sprintf(TEXT_MORE_INFORMATION, tep_href_link(FILENAME_REDIRECT, 'action=url&goto=' . urlencode($product_info['products_url']), 'NONSSL', true, false)); ?></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
<?php
   }

   if ($product_info['products_date_available'] > date('Y-m-d H:i:s')) {
?>
     <tr>
       <td align="center" class="smallText"><?php echo sprintf(TEXT_DATE_AVAILABLE, tep_date_long($product_info['products_date_available'])); ?></td>
     </tr>
<?php
   } else {
?>
     <tr>
       <td align="center" class="smallText"><?php echo sprintf(TEXT_DATE_ADDED, tep_date_long($product_info['products_date_added'])); ?></td>
     </tr>
<?php
   }
?>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
         <tr class="infoBoxContents">
           <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
             <tr>
               <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
               <td class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params()) . '">' . tep_image_button('button_reviews.gif', IMAGE_BUTTON_REVIEWS) . '</a>'; ?></td>
               <td class="main" align="right"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?></td>
               <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
             </tr>
           </table></td>
         </tr>
       </table></td>
     </tr>
     <tr>
       <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
     </tr>
     <tr>
       <td>
<?php
   if ((USE_CACHE == 'true') && empty($SID)) {
     echo tep_cache_also_purchased(3600);
   } else {
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }
 }
?>
       </td>
     </tr>
   </table></form>

<?php
 require(DIR_WS_INCLUDES . 'template_bottom.php');
 require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

 

When I go to product_info.php?products_id=21

I get Product not found!

 

In the catalog admin I have the two groups in the product ticked.

As you said ticking the boxes to hide the products from groups, will now show them.

 

In the database I have for Table customers, field customers_group_id is 1,2

 

In the Table products I have field products_hide_from_groups equal to @,1,2 for product_id 21

Link to comment
Share on other sites

When I go to product_info.php?products_id=21

I get Product not found!

 

In the catalog admin I have the two groups in the product ticked.

As you said ticking the boxes to hide the products from groups, will now show them.

 

In the database I have for Table customers, field customers_group_id is 1,2

 

In the Table products I have field products_hide_from_groups equal to @,1,2 for product_id 21

I assume you want to tell me that after having hid the category (so now show it) for that product and the product itself, product_info.php still tells you the product is not found whereas it should now show it.

 

Are you logged in as that customer group (1 or 2). Not logged-in customers will always see the product not found there.

Link to comment
Share on other sites

I assume you want to tell me that after having hid the category (so now show it) for that product and the product itself, product_info.php still tells you the product is not found whereas it should now show it.

 

Are you logged in as that customer group (1 or 2). Not logged-in customers will always see the product not found there.

 

I am logged in with the user that has 1,2 in the customers_group_id.

So shouldn't I be able to see any products for group 1 and 2

Link to comment
Share on other sites

I am logged in with the user that has 1,2 in the customers_group_id.

So shouldn't I be able to see any products for group 1 and 2

Yes. Why don't you deliberately add an error to the count query (say change pd.language_id to pod.language_id) and see if the query is built well. Then check the query directly to the database to see if you get an count query bigger than zero.

Link to comment
Share on other sites

Yes. Why don't you deliberately add an error to the count query (say change pd.language_id to pod.language_id) and see if the query is built well. Then check the query directly to the database to see if you get an count query bigger than zero.

Sorry, not sure how to check that.

 

I renamed the pd.language_id to pod.language_id but it didn't give an error.

Link to comment
Share on other sites

After a lot of trial and error I got it all working except for 2 problems.

 

1. When I am logged out and at the index.php the Categories Box shows empty which is correct.

cat1z.jpg

 

If I go to the login.php page, the Categories Box Shows wrong.

cat2qk.jpg

 

This is my includes/boxes/categories.php

 

<?php
/*
 $Id$

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 function tep_show_category($counter) {
   global $tree, $categories_string, $cPath_array;

   for ($i=0; $i<$tree[$counter]['level']; $i++) {
     $categories_string .= "  ";
   }

   $categories_string .= '<a href="';

   if ($tree[$counter]['parent'] == 0) {
     $cPath_new = 'cPath=' . $counter;
   } else {
     $cPath_new = 'cPath=' . $tree[$counter]['path'];
   }

   $categories_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">';

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '<b>';
   }

// display category name
   $categories_string .= $tree[$counter]['name'];

   if (isset($cPath_array) && in_array($counter, $cPath_array)) {
     $categories_string .= '</b>';
   }

   if (tep_has_category_subcategories($counter)) {
     $categories_string .= '->';
   }

   $categories_string .= '</a>';

   if (SHOW_COUNTS == 'true') {
     $products_in_category = tep_count_products_in_category($counter);
     if ($products_in_category > 0) {
       $categories_string .= ' (' . $products_in_category . ')';
     }
   }

   $categories_string .= '<br>';

   if ($tree[$counter]['next_id'] != false) {
     tep_show_category($tree[$counter]['next_id']);
   }
 }
?>
<!-- categories //-->
         <tr>
           <td>
<?php
 $info_box_contents = array();
 $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);

 new infoBoxHeading($info_box_contents, true, false);

 $categories_string = '';
 $tree = array();

// BOF SPPC hide categories from groups
 if (strlen($customer_group_id) == 0) {
   $product_check['total'] = 0;
 } else {
 $customer_group_id_array = explode(",", $customer_group_id);
 // weed out double entries if there are any
 $customer_group_id_array = array_unique($customer_group_id_array);
 $and_hide_product_from = "and (";
 $and_hide_category_from = "and (";
 foreach ($customer_group_id_array as $group_id) {
   $and_hide_product_from_array[] = "find_in_set('". (int)$group_id ."', products_hide_from_groups) > 0";
   $and_hide_category_from_array[] = "find_in_set('". (int)$group_id ."', categories_hide_from_groups) > 0";
 } 
 $and_hide_product_from .= implode(" or ", $and_hide_product_from_array);
 $and_hide_product_from .= ") ";
 $and_hide_category_from .= implode(" or ", $and_hide_category_from_array);
 $and_hide_category_from .= ")";

 $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' " . $and_hide_category_from . " order by sort_order, cd.categories_name");
 while ($categories = tep_db_fetch_array($categories_query))  {
   $tree[$categories['categories_id']] = array('name' => $categories['categories_name'],
                                               'parent' => $categories['parent_id'],
                                               'level' => 0,
                                               'path' => $categories['categories_id'],
                                               'next_id' => false);

   if (isset($parent_id)) {
     $tree[$parent_id]['next_id'] = $categories['categories_id'];
   }

   $parent_id = $categories['categories_id'];

   if (!isset($first_element)) {
     $first_element = $categories['categories_id'];
   }
 }

 //------------------------
 if (tep_not_null($cPath)) {
   $new_path = '';
   reset($cPath_array);
   while (list($key, $value) = each($cPath_array)) {
     unset($parent_id);
     unset($first_id);
     $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$value . "' and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' " . $and_hide_category_from . " order by sort_order, cd.categories_name");
     if (tep_db_num_rows($categories_query)) {
       $new_path .= $value;
       while ($row = tep_db_fetch_array($categories_query)) {
         $tree[$row['categories_id']] = array('name' => $row['categories_name'],
                                              'parent' => $row['parent_id'],
                                              'level' => $key+1,
                                              'path' => $new_path . '_' . $row['categories_id'],
                                              'next_id' => false);

         if (isset($parent_id)) {
           $tree[$parent_id]['next_id'] = $row['categories_id'];
         }

         $parent_id = $row['categories_id'];

         if (!isset($first_id)) {
           $first_id = $row['categories_id'];
         }

         $last_id = $row['categories_id'];
       }
       $tree[$last_id]['next_id'] = $tree[$value]['next_id'];
       $tree[$value]['next_id'] = $first_id;
       $new_path .= '_';
     } else {
       break;
     }
   }
 }
 tep_show_category($first_element); 

}
// EOF SPPC hide categories from groups

 $info_box_contents = array();
 $info_box_contents[] = array('text' => $categories_string);

 new infoBox($info_box_contents);
?>
           </td>
         </tr>
<!-- categories_eof //-->

 

2. The second problem is, how do I only show the Manufactures in the Drop down Box that should be available to the groups.

 

Thanks.

Link to comment
Share on other sites

If I go to the login.php page, the Categories Box Shows wrong.

Peculiar why this would only happen on that page.

This is my includes/boxes/categories.php

Since $product_check is only used on product_info.php and you rely on $customer_group_id being a global variable which might be tricky I personally would change a little bit:

 

// BOF SPPC hide categories from groups
// global variable (session) $sppc_customer_group_id -> local variable customer_group_id

 if (isset($_SESSION['sppc_customer_group_id'])) {
   $customer_group_id = $_SESSION['sppc_customer_group_id'];
 } else {
   $customer_group_id = '';
 }

 if (strlen($customer_group_id) > 0) {
//    $product_check['total'] = 0;
//  } else {
 $customer_group_id_array = explode(",", $customer_group_id);

If that doesn't help for the display of the arrow maybe a little hack (it's not really a thorough solution) would help to see if the customers is logged-in for displaying the arrow. This would not work if there would be categories you would like to show to visitors.

 

   if (tep_has_category_subcategories($counter) && isset($_SESSION['sppc_customer_group_id']) ) {
     $categories_string .= '->';
   }

2. The second problem is, how do I only show the Manufactures in the Drop down Box that should be available to the groups.

Since there is no hide code for manufacturers this would need to be a code rewritte. Probably extracting the unique manufacturers_id's from the table products joined with categories restricting the products using the hide fields and then build the code for the dropdown with the knowledge which manufacturers can be shown and which not.

Link to comment
Share on other sites

Peculiar why this would only happen on that page.

 

Since $product_check is only used on product_info.php and you rely on $customer_group_id being a global variable which might be tricky I personally would change a little bit:

 

// BOF SPPC hide categories from groups
// global variable (session) $sppc_customer_group_id -> local variable customer_group_id

 if (isset($_SESSION['sppc_customer_group_id'])) {
   $customer_group_id = $_SESSION['sppc_customer_group_id'];
 } else {
   $customer_group_id = '';
 }

 if (strlen($customer_group_id) > 0) {
//    $product_check['total'] = 0;
//  } else {
 $customer_group_id_array = explode(",", $customer_group_id);

If that doesn't help for the display of the arrow maybe a little hack (it's not really a thorough solution) would help to see if the customers is logged-in for displaying the arrow. This would not work if there would be categories you would like to show to visitors.

 

   if (tep_has_category_subcategories($counter) && isset($_SESSION['sppc_customer_group_id']) ) {
     $categories_string .= '->';
   }

 

Since there is no hide code for manufacturers this would need to be a code rewritte. Probably extracting the unique manufacturers_id's from the table products joined with categories restricting the products using the hide fields and then build the code for the dropdown with the knowledge which manufacturers can be shown and which not.

 

Thanks for the help again.

 

Both problems now fixed.

 

Thanks again.

Link to comment
Share on other sites

Is there any chance you could take a look at includes/classes/shopping_cart.php, please.

 

Not sure how to get this part to work with hiding the attributes and products that are already in the users cart.

 

<?php
/*
 $Id$

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 class shoppingCart {
   var $contents, $total, $weight, $cartID, $content_type;

   function shoppingCart() {
     $this->reset();
   }

   function restore_contents() {
     global $customer_id;

     if (!tep_session_is_registered('customer_id')) return false;

// insert current cart contents in database
     if (is_array($this->contents)) {
       reset($this->contents);
// BOF SPPC attribute hide/invalid check: loop through the shopping cart and check the attributes if they
// are hidden for the now logged-in customer
     $this->cg_id = $this->get_customer_group_id();
       while (list($products_id, ) = each($this->contents)) {
                   // only check attributes if they are set for the product in the cart
                  if (isset($this->contents[$products_id]['attributes'])) {
               $check_attributes_query = tep_db_query("select options_id, options_values_id, IF(find_in_set('" . $this->cg_id . "', attributes_hide_from_groups) = 0, '0', '1') as hide_attr_status from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . tep_get_prid($products_id) . "'");
               while ($_check_attributes = tep_db_fetch_array($check_attributes_query)) {
                   $check_attributes[] = $_check_attributes;
               } // end while ($_check_attributes = tep_db_fetch_array($check_attributes_query))
               $no_of_check_attributes = count($check_attributes);
               $change_products_id = '0';

               foreach($this->contents[$products_id]['attributes'] as $attr_option => $attr_option_value) {
                   $valid_option = '0';
                   for ($x = 0; $x < $no_of_check_attributes ; $x++) {
                       if ($attr_option == $check_attributes[$x]['options_id'] && $attr_option_value == $check_attributes[$x]['options_values_id']) {
                           $valid_option = '1';
                           if ($check_attributes[$x]['hide_attr_status'] == '1') {
                           // delete hidden attributes from array attributes, change products_id accordingly later
                           $change_products_id = '1';
                           unset($this->contents[$products_id]['attributes'][$attr_option]);
                           }
                       } // end if ($attr_option == $check_attributes[$x]['options_id']....
                   } // end for ($x = 0; $x < $no_of_check_attributes ; $x++)
                   if ($valid_option == '0') {
                       // after having gone through the options for this product and not having found a matching one
                       // we can conclude that apparently this is not a valid option for this product so remove it
                       unset($this->contents[$products_id]['attributes'][$attr_option]);
                       // change products_id accordingly later
                       $change_products_id = '1';
                   }
               } // end foreach($this->contents[$products_id]['attributes'] as $attr_option => $attr_option_value)

         if ($change_products_id == '1') {
              $original_products_id = $products_id;
              $products_id = tep_get_prid($original_products_id);
              $products_id = tep_get_uprid($products_id, $this->contents[$original_products_id]['attributes']);
                        // add the product without the hidden attributes to the cart
              $this->contents[$products_id] = $this->contents[$original_products_id];
                    // delete the originally added product with the hidden attributes
              unset($this->contents[$original_products_id]);
           }
                 } // end if (isset($this->contents[$products_id]['attributes']))
               } // end while (list($products_id, ) = each($this->contents))
      reset($this->contents); // reset the array otherwise the cart will be emptied
// EOF SPPC attribute hide/invalid check
       while (list($products_id, ) = each($this->contents)) {
         $qty = $this->contents[$products_id]['qty'];
         $product_query = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
         if (!tep_db_num_rows($product_query)) {
           tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . tep_db_input($qty) . "', '" . date('Ymd') . "')");
           if (isset($this->contents[$products_id]['attributes'])) {
             reset($this->contents[$products_id]['attributes']);
             while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
               tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id) . "', '" . (int)$option . "', '" . (int)$value . "')");
             }
           }
         } else {
           tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . tep_db_input($qty) . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
         }
       }
     }

// reset per-session cart contents, but not the database contents
     $this->reset(false);

     $products_query = tep_db_query("select products_id, customers_basket_quantity from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
// BOF SPPC Hide products and categories from groups
         $no_of_products_in_basket = 0;
     while ($_products = tep_db_fetch_array($products_query)) {
       $temp_post_get_array[] = $_products['products_id'];
           $products[] = $_products;
           $no_of_products_in_basket += 1;
      }
 if ($no_of_products_in_basket > 0) {
           $hide_status_products = array();
           $hide_status_products = tep_get_hide_status($hide_status_products, $this->cg_id, $temp_post_get_array);
           for ($i=0 ; $i < $no_of_products_in_basket; $i++) {
             foreach($hide_status_products as $key => $subarray) {
               if ($subarray['products_id'] == tep_get_prid($products[$i]['products_id']) && $subarray['hidden'] == '0') {
// not hidden for this customer, can be added to the object shoppingCart
       $this->contents[$products[$i]['products_id']] = array('qty' => $products[$i]['customers_basket_quantity']);
// attributes
                  $attributes_query = tep_db_query("select products_options_id, products_options_value_id from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products[$i]['products_id']) . "'");
                  while ($attributes = tep_db_fetch_array($attributes_query)) {
            $this->contents[$products[$i]['products_id']]['attributes'][$attributes['products_options_id']] = $attributes['products_options_value_id'];
                  }
               } elseif ($subarray['products_id'] == tep_get_prid($products[$i]['products_id']) && $subarray['hidden'] == '1') {
// product is hidden for the customer, don't add to object shoppingCart, delete from db next
               $products_to_delete_from_cb[] = $products[$i]['products_id'];
               } // end if/elseif
             }// end foreach ($hide_status_products as $key => $subarray)
           } // end for ($i=0 ; $i < $no_of_products_in_basket; $i++)

// delete from the database those products that are hidden from this customer
     if (tep_not_null($products_to_delete_from_cb)) {
        $no_of_iterations = count($products_to_delete_from_cb);
// since the products_id in the table customer_basket and customer_basket_attributes can contain
// attributes like 1{4}2{3}6 we need to delete them one by one for the two tables
       for ($y = 0; $y < $no_of_iterations; $y++) {
          tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and (products_id = '" . (int)$products_to_delete_from_cb[$y] . "' or products_id REGEXP '^" .  (int)$products_to_delete_from_cb[$y] . "{');");
          tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and (products_id = '" . (int)$products_to_delete_from_cb[$y] . "' or products_id REGEXP '^" .  (int)$products_to_delete_from_cb[$y] . "{');");
        } // end for ($y = 0; $y < $no_of_iterations; $y++)
     } // end if (tep_not_null($products_to_delete_from_cb))
} // end if ($no_of_products_in_basket > 0)
// EOF SPPC Hide products and categories from groups
     $this->cleanup();

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
     $this->cartID = $this->generate_cart_id();
   }

   function reset($reset_database = false) {
     global $customer_id;

     $this->contents = array();
     $this->total = 0;
     $this->weight = 0;
     $this->content_type = false;

     if (tep_session_is_registered('customer_id') && ($reset_database == true)) {
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "'");
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "'");
     }

     unset($this->cartID);
     if (tep_session_is_registered('cartID')) tep_session_unregister('cartID');
   }

   function add_cart($products_id, $qty = '1', $attributes = '', $notify = true) {
     global $new_products_id_in_cart, $customer_id;
// BOF Separate Pricing Per Customer 
     $this->cg_id = $this->get_customer_group_id();
// EOF Separate Pricing Per Customer

     $products_id_string = tep_get_uprid($products_id, $attributes);
     $products_id = tep_get_prid($products_id_string);

     if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$qty > MAX_QTY_IN_CART)) {
       $qty = MAX_QTY_IN_CART;
     }

     $attributes_pass_check = true;

     if (is_array($attributes) && !empty($attributes)) {
       reset($attributes);
       while (list($option, $value) = each($attributes)) {
         if (!is_numeric($option) || !is_numeric($value)) {
           $attributes_pass_check = false;
           break;
         } else {
           $check_query = tep_db_query("select products_attributes_id from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "' limit 1");
           if (tep_db_num_rows($check_query) < 1) {
             $attributes_pass_check = false;
             break;
           }
         }
       }
     } elseif (tep_has_product_attributes($products_id)) {
       $attributes_pass_check = false;
     }

     if (is_numeric($products_id) && is_numeric($qty) && ($attributes_pass_check == true)) {
// BOF SPPC attribute hide check, original query expanded to include attributes
               $check_product_query = tep_db_query("select p.products_status, options_id, options_values_id, IF(find_in_set('" . $this->cg_id . "', attributes_hide_from_groups) = 0, '0', '1') as hide_attr_status from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_ATTRIBUTES . " using(products_id) where p.products_id = '" . (int)$products_id . "'");
               while ($_check_product = tep_db_fetch_array($check_product_query)) {
                   $check_product[] = $_check_product;
               } // end while ($_check_product = tep_db_fetch_array($check_product_query))
               $no_of_check_product = count($check_product);

 if (is_array($attributes)) {
               foreach($attributes as $attr_option => $attr_option_value) {
                   $valid_option = '0';
                   for ($x = 0; $x < $no_of_check_product ; $x++) {
                       if ($attr_option == $check_product[$x]['options_id'] && $attr_option_value == $check_product[$x]['options_values_id']) {
                           $valid_option = '1';
                           if ($check_product[$x]['hide_attr_status'] == '1') {
                           // delete hidden attributes from array attributes
                           unset($attributes[$attr_option]);
                           }
                       } // end if ($attr_option == $check_product[$x]['options_id']....
                   } // end for ($x = 0; $x < $no_of_check_product ; $x++)
                   if ($valid_option == '0') {
                       // after having gone through the options for this product and not having found a matching one
                       // we can conclude that apparently this is not a valid option for this product so remove it
                       unset($attributes[$attr_option]);
                   }
               } // end foreach($attributes as $attr_option => $attr_option_value)
   } // end if (is_array($attributes))
// now attributes have been checked and hidden and invalid ones deleted make the $products_id_string again
               $products_id_string = tep_get_uprid($products_id, $attributes);

       if ((isset($check_product) && tep_not_null($check_product)) && ($check_product[0]['products_status'] == '1')) {
// EOF SPPC attribute hide check
         if ($notify == true) {
           $new_products_id_in_cart = $products_id;
           tep_session_register('new_products_id_in_cart');
         }

         if ($this->in_cart($products_id_string)) {
           $this->update_quantity($products_id_string, $qty, $attributes);
         } else {
           $this->contents[$products_id_string] = array('qty' => (int)$qty);
// insert into database
           if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET . " (customers_id, products_id, customers_basket_quantity, customers_basket_date_added) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id_string) . "', '" . (int)$qty . "', '" . date('Ymd') . "')");

           if (is_array($attributes)) {
             reset($attributes);
             while (list($option, $value) = each($attributes)) {
               $this->contents[$products_id_string]['attributes'][$option] = $value;
// insert into database
               if (tep_session_is_registered('customer_id')) tep_db_query("insert into " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " (customers_id, products_id, products_options_id, products_options_value_id) values ('" . (int)$customer_id . "', '" . tep_db_input($products_id_string) . "', '" . (int)$option . "', '" . (int)$value . "')");
             }
           }
         }

         $this->cleanup();

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
         $this->cartID = $this->generate_cart_id();
       }
     }
   }

   function update_quantity($products_id, $quantity = '', $attributes = '') {
     global $customer_id;

     $products_id_string = tep_get_uprid($products_id, $attributes);
     $products_id = tep_get_prid($products_id_string);

     if (defined('MAX_QTY_IN_CART') && (MAX_QTY_IN_CART > 0) && ((int)$quantity > MAX_QTY_IN_CART)) {
       $quantity = MAX_QTY_IN_CART;
     }

     $attributes_pass_check = true;

     if (is_array($attributes)) {
       reset($attributes);
       while (list($option, $value) = each($attributes)) {
         if (!is_numeric($option) || !is_numeric($value)) {
           $attributes_pass_check = false;
           break;
         }
       }
     }

     if (is_numeric($products_id) && isset($this->contents[$products_id_string]) && is_numeric($quantity) && ($attributes_pass_check == true)) {
       $this->contents[$products_id_string] = array('qty' => (int)$quantity);
// update database
       if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET . " set customers_basket_quantity = '" . (int)$quantity . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "'");

       if (is_array($attributes)) {
         reset($attributes);
         while (list($option, $value) = each($attributes)) {
           $this->contents[$products_id_string]['attributes'][$option] = $value;
// update database
           if (tep_session_is_registered('customer_id')) tep_db_query("update " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " set products_options_value_id = '" . (int)$value . "' where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id_string) . "' and products_options_id = '" . (int)$option . "'");
         }
       }
     }
   }

   function cleanup() {
     global $customer_id;

     reset($this->contents);
     while (list($key,) = each($this->contents)) {
       if ($this->contents[$key]['qty'] < 1) {
         unset($this->contents[$key]);
// remove from database
         if (tep_session_is_registered('customer_id')) {
           tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
           tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($key) . "'");
         }
       }
     }
   }

   function count_contents() {  // get total number of items in cart 
     $total_items = 0;
     if (is_array($this->contents)) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {
         $total_items += $this->get_quantity($products_id);
       }
     }

     return $total_items;
   }

   function get_quantity($products_id) {
     if (isset($this->contents[$products_id])) {
       return $this->contents[$products_id]['qty'];
     } else {
       return 0;
     }
   }

   function in_cart($products_id) {
     if (isset($this->contents[$products_id])) {
       return true;
     } else {
       return false;
     }
   }

   function remove($products_id) {
     global $customer_id;

     unset($this->contents[$products_id]);
// remove from database
     if (tep_session_is_registered('customer_id')) {
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
       tep_db_query("delete from " . TABLE_CUSTOMERS_BASKET_ATTRIBUTES . " where customers_id = '" . (int)$customer_id . "' and products_id = '" . tep_db_input($products_id) . "'");
     }

// assign a temporary unique ID to the order contents to prevent hack attempts during the checkout procedure
     $this->cartID = $this->generate_cart_id();
   }

   function remove_all() {
     $this->reset();
   }

   function get_product_id_list() {
     $product_id_list = '';
     if (is_array($this->contents)) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {
         $product_id_list .= ', ' . $products_id;
       }
     }

     return substr($product_id_list, 2);
   }

   function calculate() {
     global $currencies;

     $this->total = 0;
     $this->weight = 0;
     if (!is_array($this->contents)) return 0;

     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
       $qty = $this->contents[$products_id]['qty'];

// products price
       $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
       if ($product = tep_db_fetch_array($product_query)) {
         $prid = $product['products_id'];
         $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
         $products_price = $product['products_price'];
         $products_weight = $product['products_weight'];

         $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
         if (tep_db_num_rows ($specials_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         }

         $this->total += $currencies->calculate_price($products_price, $products_tax, $qty);
         $this->weight += ($qty * $products_weight);
       }

// attributes price
       if (isset($this->contents[$products_id]['attributes'])) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
           $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
           $attribute_price = tep_db_fetch_array($attribute_price_query);
           if ($attribute_price['price_prefix'] == '+') {
             $this->total += $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
           } else {
             $this->total -= $currencies->calculate_price($attribute_price['options_values_price'], $products_tax, $qty);
           }
         }
       }
     }
   }

   function attributes_price($products_id) {
     $attributes_price = 0;

     if (isset($this->contents[$products_id]['attributes'])) {
       reset($this->contents[$products_id]['attributes']);
       while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
         $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
         $attribute_price = tep_db_fetch_array($attribute_price_query);
         if ($attribute_price['price_prefix'] == '+') {
           $attributes_price += $attribute_price['options_values_price'];
         } else {
           $attributes_price -= $attribute_price['options_values_price'];
         }
       }
     }

     return $attributes_price;
   }

   function get_products() {
     global $languages_id;

     if (!is_array($this->contents)) return false;

     $products_array = array();
     reset($this->contents);
     while (list($products_id, ) = each($this->contents)) {
       $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$products_id . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
       if ($products = tep_db_fetch_array($products_query)) {
         $prid = $products['products_id'];
         $products_price = $products['products_price'];

         $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$prid . "' and status = '1'");
         if (tep_db_num_rows($specials_query)) {
           $specials = tep_db_fetch_array($specials_query);
           $products_price = $specials['specials_new_products_price'];
         }

         $products_array[] = array('id' => $products_id,
                                   'name' => $products['products_name'],
                                   'model' => $products['products_model'],
                                   'image' => $products['products_image'],
                                   'price' => $products_price,
                                   'quantity' => $this->contents[$products_id]['qty'],
                                   'weight' => $products['products_weight'],
                                   'final_price' => ($products_price + $this->attributes_price($products_id)),
                                   'tax_class_id' => $products['products_tax_class_id'],
                                   'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''));
       }
     }

     return $products_array;
   }

   function show_total() {
     $this->calculate();

     return $this->total;
   }

   function show_weight() {
     $this->calculate();

     return $this->weight;
   }

   function generate_cart_id($length = 5) {
     return tep_create_random_value($length, 'digits');
   }

   function get_content_type() {
     $this->content_type = false;

     if ( (DOWNLOAD_ENABLED == 'true') && ($this->count_contents() > 0) ) {
       reset($this->contents);
       while (list($products_id, ) = each($this->contents)) {
         if (isset($this->contents[$products_id]['attributes'])) {
           reset($this->contents[$products_id]['attributes']);
           while (list(, $value) = each($this->contents[$products_id]['attributes'])) {
             $virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$products_id . "' and pa.options_values_id = '" . (int)$value . "' and pa.products_attributes_id = pad.products_attributes_id");
             $virtual_check = tep_db_fetch_array($virtual_check_query);

             if ($virtual_check['total'] > 0) {
               switch ($this->content_type) {
                 case 'physical':
                   $this->content_type = 'mixed';

                   return $this->content_type;
                   break;
                 default:
                   $this->content_type = 'virtual';
                   break;
               }
             } else {
               switch ($this->content_type) {
                 case 'virtual':
                   $this->content_type = 'mixed';

                   return $this->content_type;
                   break;
                 default:
                   $this->content_type = 'physical';
                   break;
               }
             }
           }
         } else {
           switch ($this->content_type) {
             case 'virtual':
               $this->content_type = 'mixed';

               return $this->content_type;
               break;
             default:
               $this->content_type = 'physical';
               break;
           }
         }
       }
     } else {
       $this->content_type = 'physical';
     }

     return $this->content_type;
   }

   function unserialize($broken) {
     for(reset($broken);$kv=each($broken);) {
       $key=$kv['key'];
       if (gettype($this->$key)!="user function")
       $this->$key=$kv['value'];
     }
   }

// added for Separate Pricing Per Customer, returns customer_group_id
   function get_customer_group_id() {
     if (isset($_SESSION['sppc_customer_group_id']) && $_SESSION['sppc_customer_group_id'] != '') {
       $_cg_id = $_SESSION['sppc_customer_group_id'];
     } else {
        $_cg_id = '';
     }
     return $_cg_id;
   }

 }
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...