PDA

View Full Version : Individual Product Shipping Prices - v1.0



michael_s
02-23-2007, 04:13 PM
if no products exists in the shopping-box and if then the user like to pop-up the shipping-cost information - an sql-error are displayed.

I corrected the code so that the individual shipping methods (defined within the product) only displayed if the box is not empty.

=============================
backup backup backup backup backup
=============================

catalog/includes/classes/shipping.php
---------------------------------------
Find (around row 20-58):
// INDIV_SM BEGIN (this is messy i know)
global $cart;
// New to fix attributes bug
$cart_products = $cart->get_products();
$real_ids = array();
foreach($cart_products as $prod){
$real_ids[] = tep_get_prid($prod['id']);
}
$sql = "SELECT shipping_methods FROM ".TABLE_PRODUCTS." WHERE products_id IN (".implode(',',$real_ids).") AND shipping_methods IS NOT NULL AND shipping_methods ''";
$query = mysql_query($sql);
// End new bug fix
$allow_mod_array = array();
while($rec = mysql_fetch_array($query)){
if(empty($allow_mod_array)) $startedempty = true;
$methods_array = array();
$methods_array = explode(';',$rec['shipping_methods']);
if(!empty($methods_array)){
foreach($methods_array as $method){
$allow_mod_array[] = $method;
}
}
if($startedempty){
$startedempty = false;
}else{
$temp_array = array();
foreach($allow_mod_array as $val){
$temp_array[$val]++;
}
$allow_mod_array = array();
foreach($temp_array as $key => $val){
if($val > 1){
$allow_mod_array[] = $key;
}
}
}
}
// INDIV_SM END

and replaced it with:

// INDIV_SM BEGIN (this is messy i know)
global $cart;
// New to fix attributes bug
$cart_products = $cart->get_products();
if (tep_not_null($cart_products)) {
$real_ids = array();
foreach($cart_products as $prod){
$real_ids[] = tep_get_prid($prod['id']);
}
$sql = "SELECT shipping_methods FROM ".TABLE_PRODUCTS." WHERE products_id IN (".implode(',',$real_ids).") AND shipping_methods IS NOT NULL AND shipping_methods ''";
$query = mysql_query($sql);
// End new bug fix
$allow_mod_array = array();
while($rec = mysql_fetch_array($query)){
if(empty($allow_mod_array)) $startedempty = true;
$methods_array = array();
$methods_array = explode(';',$rec['shipping_methods']);
if(!empty($methods_array)){
foreach($methods_array as $method){
$allow_mod_array[] = $method;
}
}
if($startedempty){
$startedempty = false;
}else{
$temp_array = array();
foreach($allow_mod_array as $val){
$temp_array[$val]++;
}
$allow_mod_array = array();
foreach($temp_array as $key => $val){
if($val > 1){
$allow_mod_array[] = $key;
}
}
}
}
}
// INDIV_SM END


second change (around row 63-73):

Find:
// INDIV_SM START
$temp_array = $this->modules;
$this->modules = array();
foreach($temp_array as $val){
if(mysql_num_rows($query)==0 || in_array(str_replace('.php','',$val),$allow_mod_ar ray)) {
$this->modules[] = $val;
}
}
// INDIV_SM END

and replace it with:

// INDIV_SM START
if (tep_not_null($cart_products)) {
$temp_array = $this->modules;
$this->modules = array();
foreach($temp_array as $val){
if(mysql_num_rows($query)==0 || in_array(str_replace('.php','',$val),$allow_mod_ar ray)) {
$this->modules[] = $val;
}
}
}
// INDIV_SM END


Thats all. Hope this solve it for everyone, within my shop it works. ;-))

I've attached my shipping.php -- use winmerge or other tools to compare it with your own version! I've installed some other contribution that changed this file.

kind regards

peter

More... (http://www.oscommerce.com/community/contributions,1333)