Groundation Posted January 7, 2009 Share Posted January 7, 2009 Hi there I am using a dutch shipping contribution called tntpostf (includes possibility to add shipping rates for all types of different deliveries (COD/Certain/Registered/Letter/Parcel etc) of our local delivery service company TNTPost). I want this contribution only to show at checkout_process when the weight of 1 product in the shopping cart is more than 31.5 kilograms (that is the maximum weight they will deliver per package). I have been trying out a lot of things myself, and i have figured out how to enable it if the total weight of the shopping cart is >31.5 kg, but say a customer orders 10 products of 4kg each, i want them to still be abled to choose the different types of deliveries of our local delivery service because i can simply put the ten products in 2 large packages of 5 products each, and then TNT will accept them. For products weighing larger than 31,5kg i have 2 other options (Pickup at store and delivery by our company).. But delivery by our company is rather expensive for large distances, and i want our customers to have another option: Heres what i have figured out: if ( ($this->enabled == true) && ($shipping_weight >= 31.5) ) { $this->enabled = false; return; } This disablels the module you put the script in ( Put is just above these following lines) return $this->quotes; } This checks the total weight of the shopping cart when about to place an order, but i want the script to see if there is 1 product in the cart weighing more than 31.5 kg's, and only then disable the module. (so when 10 products weighing at 4kg each are in the cart, shipping by TNT is still enabled). Other things i have testen between the ( and > of ($shipping_weight >= 31.5) ) { are: "products_weight" 'products_weight' products_weight $products_weight ($pInfo->products_weight) $pInfo->products_weight '$pInfo->products_weight' "$pInfo->products_weight" ($product['products_weight']) $product['products_weight'] '$product['products_weight']' "$product['products_weight']" $pInfo->products_weight p.products_weight 'p.products_weight' "p.products_weight" weight 'weight' "weight" $weight though i just cannot find the right solution.. Does anyone have an idea how to help me out? Help would be more than appreciated! Quote Link to comment Share on other sites More sharing options...
Groundation Posted January 16, 2009 Author Share Posted January 16, 2009 Nobody? :( I really need to get this done asap, there must be somebody on this forum that is using this too! Quote Link to comment Share on other sites More sharing options...
natrium42 Posted January 17, 2009 Share Posted January 17, 2009 (edited) Well, you could loop through all products in cart and check each one's weight against your cutoff. The cart class is defined in includes/classes/shopping_cart.php For example, you could get an array of all the products in the shopping cart using the $cart->get_products() function (see the above mentioned class). Then just loop through the array like this: $products_array = $cart->get_products(); foreach($products_array as $product) { // now you can use $product variable to get info about current product if($product['weight'] >= 31.5) { $this->enabled = false; break; // break out of the foreach loop (no reason to keep looping once condition met) } } Edited January 17, 2009 by natrium42 Quote Link to comment Share on other sites More sharing options...
Groundation Posted January 19, 2009 Author Share Posted January 19, 2009 Natrium42, Thank you for your reply, this looks like a solution to my problem.. though i just cannot get it to work :/. Should i just place this in my includes/modules/tntpostf.php, just above return $this->quotes; } I have tried this but it remains enabled. Do i have to edit anything in includes/classes/shopping_cart.php? We appreciate your help Quote Link to comment Share on other sites More sharing options...
natrium42 Posted January 19, 2009 Share Posted January 19, 2009 Do i have to edit anything in includes/classes/shopping_cart.php? No, just make sure that ['weight'] is set in get_products() function. Also you can add "echo 'Weight: ' . $product['weight'] . '<br>';" below "foreach($products_array as $product) {" just to check that weight is being returned correctly. Quote Link to comment Share on other sites More sharing options...
Groundation Posted January 20, 2009 Author Share Posted January 20, 2009 Ok, i havn't edited anything in classes/shopping_cart.php, and i have added the weight echo and tested it. The weight is being picked up correctly, because i see "Weight: 32.00" in my browser. I geuss this means $product['weight'] is working correctly, checking the weight of the product in $products_array (shopping_cart.php); though my shipping module is still being displayed when a product >31.5 kg is placed in shopping cart. I have tested these following two scripts $products_array = $cart->get_products(); foreach($products_array as $product) { echo 'Weight: ' . $product['weight'] . '<br>'; // now you can use $product variable to get info about current product if($product['weight'] >= 31.5) { $this->enabled = false; break; // break out of the foreach loop (no reason to keep looping once condition met) } } and; $products_array = $cart->get_products(); foreach($products_array as $product) { echo 'Weight: ' . $product['weight'] . '<br>'; // now you can use $product variable to get info about current product if ( ($this->enabled == true) && ($product['weight'] >= 31.5) ) { $this->enabled = false; break; // break out of the foreach loop (no reason to keep looping once condition met) } } I have also tested it without the weight echo, without the comments and with "$this->enaled == false;" instead of "=false;" though nothing seems to work =/. Does anyone have a clue what i am doing wrong?! Quote Link to comment Share on other sites More sharing options...
natrium42 Posted January 20, 2009 Share Posted January 20, 2009 == is comparison operator, lol :D Perhaps instead of guessing your way, you could at least read some basic tutorial :P I have tried to teach you which files to look in etc., without providing a full solution... I guess you could use "return;" instead of "break;" since you have said that it worked for you before. I don't have the code in front of me to suggest a better way at the moment. It would be better to put the code where the shipping system asks the module whether it's enabled or not, but I can't tell you without looking at the code. This is a giant hack anyway. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.