rovshan Posted October 17, 2007 Share Posted October 17, 2007 Here is modified code in shipping module. So what I need to get message when $shipping_weight== 7.7 or 1.1 .... etc. The problem is that it works , but not for 7.7 and 11 and 12.1 When is weight 11 kg...... only $shipping_weight visible and not $title2 ...... But when is weight 4.4 kg...... it is ok ! I see $shipping_weight and $title2 ........ Where is the problem ??? Thanks in advance...... // class methods function quote($method = '') { global $order, $cart, $shipping_weight; if ($shipping_weight== 7.7) $title2= ''.MODULE_SHIPPING_COLISSIMO_TEXT_UNITS7.''; if ($shipping_weight== 1.1) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; if ($shipping_weight== 4.4) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; if ($shipping_weight== 5.5) $title2= ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5.''; if ($shipping_weight== 8.8) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS8; if ($shipping_weight== 9.9) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS9; if ($shipping_weight== 11) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; if ($shipping_weight== 12.1) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_COLISSIMO_TEXT_TITLE, 'methods' => array()); if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); $dest_country = $order->delivery['country']['iso_code_2']; if (($dest_country != 'FR') && ($dest_country != 'FX')) { $this->quotes['error'] = MODULE_SHIPPING_COLISSIMO_INVALID_ZONE; return $this->quotes; } $cost = constant('MODULE_SHIPPING_COLISSIMO_NATIONAL'); $table = split("[:,]" , $cost); for ($i = 0; $i < sizeof($table); $i+=2) { if ($shipping_weight > $table[$i]) continue; $this->quotes['methods'][] = array('id' => $this->code, 'title' => $shipping_weight . ' ' . $title2, 'cost' => $table[$i+1] + MODULE_SHIPPING_COLISSIMO_HANDLING); if ($this->tax_class > 0) { $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } return $this->quotes; } $this->quotes['error'] = MODULE_SHIPPING_COLISSIMO_TOO_HEAVY; return $this->quotes; } Link to comment Share on other sites More sharing options...
germ Posted October 17, 2007 Share Posted October 17, 2007 Maybe replace this: if ($shipping_weight== 7.7) $title2= ''.MODULE_SHIPPING_COLISSIMO_TEXT_UNITS7.''; if ($shipping_weight== 1.1) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; if ($shipping_weight== 4.4) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; if ($shipping_weight== 5.5) $title2= ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5.''; if ($shipping_weight== 8.8) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS8; if ($shipping_weight== 9.9) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS9; if ($shipping_weight== 11) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; if ($shipping_weight== 12.1) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; With: switch ($shipping_weight) { case "1.1": $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; break; case "4.4": $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; break; case "5.5": $title2= ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5.''; break; case "7.7": $title2= ''.MODULE_SHIPPING_COLISSIMO_TEXT_UNITS7.''; break; case "8.8": $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS8; break; case "9.9": $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS9; break; case "11": $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; break; case "12.1": $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; break; } :unsure: If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
rovshan Posted October 18, 2007 Author Share Posted October 18, 2007 replaced !!!! same problem !!?????????? I really don't understand why ??? Why it does not work only for 7.7 and 11 and 12.1 !!!!! on checkout_shipping.php page I see only $shipping_weight and it is correct ...... but not $title2 ......... Link to comment Share on other sites More sharing options...
germ Posted October 18, 2007 Share Posted October 18, 2007 Maybe on the others the weight is not exact. For example, 4.4 could actually be 4.39999999999999~, but gets rounded up and displayed as 4.4 If you want, I can figure out a way around the rounding error? :unsure: If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
rovshan Posted October 18, 2007 Author Share Posted October 18, 2007 Maybe on the others the weight is not exact. For example, 4.4 could actually be 4.39999999999999~, but gets rounded up and displayed as 4.4 If you want, I can figure out a way around the rounding error? :unsure: Thanks ...... But how it can arrive? I fixed shipping weight for each product 1.1 ...... and there is no place for rounding up !??? and there additional weight for packaging....... SO.......... And if so why rounding up aplicated for 7.7 and not for 5.5........ !? Link to comment Share on other sites More sharing options...
rovshan Posted October 18, 2007 Author Share Posted October 18, 2007 Sorry I would like to say : and there is NO additional weight for packaging Link to comment Share on other sites More sharing options...
Guest Posted October 18, 2007 Share Posted October 18, 2007 Thanks ...... But how it can arrive? I fixed shipping weight for each product 1.1 ...... and there is no place for rounding up !??? and there additional weight for packaging....... SO.......... And if so why rounding up aplicated for 7.7 and not for 5.5........ !? Just to try to make it consistent if ($shipping_weight== 7.7) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS7; if ($shipping_weight== 1.1) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; if ($shipping_weight== 4.4) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; if ($shipping_weight== 5.5) $title2=$shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5.''; if ($shipping_weight== 8.8) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS8; if ($shipping_weight== 9.9) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS9; if ($shipping_weight== 11) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS11; if ($shipping_weight== 12.1) $title2= $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS12; Don't know what you defined for the various MODULE_SHIPPING_COLISSIMO_TEXT_UNITSnn Link to comment Share on other sites More sharing options...
germ Posted October 18, 2007 Share Posted October 18, 2007 rovshan, you don't understand. When dealing with floating point numbers (1.1, 4.4, etc.) there are slight inaccuracies that may or may not be involved, especially when equalities are invloved. If it was a whole number (1, 2, 3, etc.) there wouldn't be any problem. I don't know if that's the problem or not, but we can't rule it out yet. I'll put something together and post it in a few hours... ;) If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
germ Posted October 18, 2007 Share Posted October 18, 2007 Try this code: // set $sw based on weight // default value $sw = '0'; // if in this range if ( ( $shipping_weight > 1.0 ) && ( $shipping_weight < 1.2 ) ) { $sw = '1.1'; } // if in this range if ( ( $shipping_weight > 4.3 ) && ( $shipping_weight < 4.5 ) ) { $sw = '4.4'; } // if in this range if ( ( $shipping_weight > 5.4 ) && ( $shipping_weight < 5.6 ) ) { $sw = '5.5'; } // if in this range if ( ( $shipping_weight > 7.6 ) && ( $shipping_weight < 7.8 ) ) { $sw = '7.7'; } // if in this range if ( ( $shipping_weight > 8.7 ) && ( $shipping_weight < 8.9 ) ) { $sw = '8.8'; } // if in this range if ( ( $shipping_weight > 9.8 ) && ( $shipping_weight < 10.0 ) ) { $sw = '9.9'; } // if in this range if ( ( $shipping_weight > 10.9 ) && ( $shipping_weight < 11.1 ) ) { $sw = '11'; } // if in this range if ( ( $shipping_weight > 12.0 ) && ( $shipping_weight < 12.2 ) ) { $sw = '12.1'; } switch ( $sw ) { case '0': $title2 = $shipping_weight . ' UNDEFINED'; // error condition break; case '1.1': $title2 = $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; break; case '4.4': $title2 = $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; break; case '5.5': $title2 = $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5.''; break; case '7.7': $title2 = $shipping_weight . ' '.MODULE_SHIPPING_COLISSIMO_TEXT_UNITS7.''; break; case '8.8': $title2 = $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS8; break; case '9.9': $title2 = $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS9; break; case '11': $title2 = $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS4; break; case '12.1': $title2 = $shipping_weight . ' ' . MODULE_SHIPPING_COLISSIMO_TEXT_UNITS5; break; } It takes out any slight inaccuracies of floating point numbers and uses a string for comparison in the "switch" statement. String comparisons are exact. I also included an "error condition". If for some reason the shipping weight isn't in the ranges you gave me, you'll see 'UNDEFINED' on whatever page this data get's displayed in. Hopefully that won't happen..... I don't know if this will fix your problem or not. You may have an error in logic or coding somewhere else. If this doesn't work, can you post a link to the site that's using this code so I can see what's happening? :unsure: If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
spannerman Posted October 18, 2007 Share Posted October 18, 2007 Rovshan, Read this : http://uk2.php.net/manual/en/language.types.float.php It may help to explain what Jim & others are trying to do for you. Basically there's a rule in there that states "Never compare floating point numbers for equality" since what you see as 1.1 the computer might see as 1.0000000009, which compared to 1.1 will not match! The Round() function or even converting the numbers to strings and then comparing them may solve your problem. Link to comment Share on other sites More sharing options...
rovshan Posted October 18, 2007 Author Share Posted October 18, 2007 Thnks GERM...... It works... I understood where is the problem ! Many Many thnks to everybody........ spannerman , Coopco :thumbsup: Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.