appleguru Posted January 15, 2006 Share Posted January 15, 2006 (edited) Ok, I'm trying to exclude certain items from getting the flat rate shipping option... it doesn't help that I have no idea what I'm doing, but I figured I'd try soemthing like this: // class methods function quote($method = '') { global $order, $cart; //Exclude Some stuff for flat rate $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { if (($products[$i]['contents[$products_id]'] == 86) && ($products[$i]['quantity'] >= 1)) { $this->enabled = false; } } //End Exclude Any tips? (Obviously its wrong, but the idea is right I suppose...) In that example, I'd be trying to disable it if the cart contained product 86... Edited January 15, 2006 by appleguru Quote Link to comment Share on other sites More sharing options...
appleguru Posted January 15, 2006 Author Share Posted January 15, 2006 BTW, what I really need to know is how to get the product ID from the product in the cart (What I have as ['contents[$products_id]'] ) ['contents[$products_id]'] can't be right.. any tips on what is? :) Quote Link to comment Share on other sites More sharing options...
appleguru Posted January 21, 2006 Author Share Posted January 21, 2006 Grrr.. can't figure this one out.. nobody knows how to get the product ID of each product in the cart? Quote Link to comment Share on other sites More sharing options...
dittones Posted January 21, 2006 Share Posted January 21, 2006 Dear appleguru, $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { $products = $cart->get_products(); $products_manufacturers_query = tep_db_query("select products_id, manufacturers_id, products_price, products_weight from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products[$i]['id'] . "'"); Here is some code pieces shows you how to get the product_id from your shopping cart and then retrieve info if needed from product table... look at the function code get_products()... I hope that this helps you... Roman Quote Link to comment Share on other sites More sharing options...
appleguru Posted January 21, 2006 Author Share Posted January 21, 2006 Alright, making a bit of progress.. now I'm getting a: "Fatal error: Call to a member function get_products() on a non-object in /path/to/flat.php on line 45" Line 45 is.. $products = $cart->get_products(); What do I need to do now? Basically, I'm trying to mimic the enable/disable for zones but using the product ID.. the current code looks like this: // class constructor function flat() { global $order, $cart; $this->code = 'flat'; $this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE; $this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS; $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false); if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) { $check_flag = false; $zone_check_flag = false; $product_check_flag = false; $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); while ($check = tep_db_fetch_array($check_query)) { if ($check['zone_id'] < 1) { $zone_check_flag = true; break; } elseif ($check['zone_id'] == $order->delivery['zone_id']) { $zone_check_flag = true; break; } } //Exclude Some stuff for flat rate $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { $check_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products[$i]['id'] . "'"); while ($check = tep_db_fetch_array($check_query)) { if (($check['products_id'] != 86)) { $product_check_flag = true; } } } //End Exclude if ($product_check_flag == true && $zone_check_flag = true) { $check_flag = true; } if ($check_flag == false) { $this->enabled = false; } } } Thanks for the reply... any help is greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Guest Posted January 21, 2006 Share Posted January 21, 2006 Seems like the $cart class is not instantiated. Put some test code to see if its ok. if (tep_session_is_registered('cart') && is_object($cart)) { echo 'cart_ok'; //or var_dump whatever } Quote Link to comment Share on other sites More sharing options...
dittones Posted January 22, 2006 Share Posted January 22, 2006 Hi appleguru Ya can't find the function...the function is in the module E:\??????\www\??????\Includes\Classes\shopping_cart.php and in E:\????????\www\???????\admin\Includes\Classes\shopping_cart.php your choices are copy the function and put it in the flat.php program as a function under the function quote or in a module that is pulled in included when your program runs.... Getting close good... Hope this helps Roman remember that a flat.php maybe located on both sides catalog and admin function get_products() { global $languages_id; global $HTTP_GET_VARS; if (!is_array($this->contents)) { return false; } $products_array = array(); reset($this->contents); Quote Link to comment Share on other sites More sharing options...
dittones Posted January 22, 2006 Share Posted January 22, 2006 Hi appleguru I just love that programmer talk...instantiated. Another little help you may know or not... If you want to see what is in a varable or if code is being executed try this technique... <?php echo "I am here: "; ?> or <?php echo "$varablea: ".$varablea; ?> A little debug technique. Roman Quote Link to comment Share on other sites More sharing options...
appleguru Posted January 22, 2006 Author Share Posted January 22, 2006 Hi appleguru Ya can't find the function...the function is in the module E:\??????\www\??????\Includes\Classes\shopping_cart.php and in E:\????????\www\???????\admin\Includes\Classes\shopping_cart.php your choices are copy the function and put it in the flat.php program as a function under the function quote or in a module that is pulled in included when your program runs.... Getting close good... Hope this helps Roman remember that a flat.php maybe located on both sides catalog and admin function get_products() { global $languages_id; global $HTTP_GET_VARS; if (!is_array($this->contents)) { return false; } $products_array = array(); reset($this->contents); I tried copying the function into flat.php.. but i still get the "Fatal error: Call to a member function get_products() on a non-object" error :/ Quote Link to comment Share on other sites More sharing options...
appleguru Posted January 22, 2006 Author Share Posted January 22, 2006 ...It doesn't help that I know *nothing* about php.. heh.. My programming history is limited to some C++ and some very basic java.. So, even while I genrally don't condone it, any extra hand-holding in this matter would be.. much appreciated :P Quote Link to comment Share on other sites More sharing options...
dittones Posted January 22, 2006 Share Posted January 22, 2006 Hi appleguru Its good that you have a little background in programing.... Ok lets do a little debuging... The echo code that I posted is the place to start.... put some of these echo's in your programs.... Like the program that you are getting the error from and follow the flow of that program backward even the function get_products() this should point you to the exact position of the problem... I know that this may be a little messy but you will get alot of info how Oscommerce programming rtns are done and how the function rtns work..... You have to supply us the form viewers some more info.... Then I can help you more....Good Luck Roman Quote Link to comment Share on other sites More sharing options...
appleguru Posted January 22, 2006 Author Share Posted January 22, 2006 Here's my entire flat.php file as of now: <?php /* $Id: flat.php,v 1.40 2003/02/05 22:41:52 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ class flat { var $code, $title, $description, $icon, $enabled; // class constructor function flat() { global $order; $this->code = 'flat'; $this->title = MODULE_SHIPPING_FLAT_TEXT_TITLE; $this->description = MODULE_SHIPPING_FLAT_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_FLAT_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_FLAT_TAX_CLASS; $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false); if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) { $check_flag = false; $zone_check_flag = false; $product_check_flag = false; $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); while ($check = tep_db_fetch_array($check_query)) { if ($check['zone_id'] < 1) { $zone_check_flag = true; break; } elseif ($check['zone_id'] == $order->delivery['zone_id']) { $zone_check_flag = true; break; } } //Exclude Some stuff for flat rate $products = $cart->get_products(); for ($i=0, $n=sizeof($products); $i<$n; $i++) { $check_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products[$i]['id'] . "'"); while ($check = tep_db_fetch_array($check_query)) { if (($check['products_id'] != 86)) { $product_check_flag = true; } } } //End Exclude if ($product_check_flag == true && $zone_check_flag = true) { $check_flag = true; } if ($check_flag == false) { $this->enabled = false; } } } // class methods function quote($method = '') { global $order; $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_FLAT_TEXT_WAY, 'cost' => MODULE_SHIPPING_FLAT_COST))); if ($this->tax_class > 0) { $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); return $this->quotes; } function check() { if (!isset($this->_check)) { $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FLAT_STATUS'"); $this->_check = tep_db_num_rows($check_query); } return $this->_check; } //get_products() function 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'] : '')); } } //end get_products() return $products_array; } function install() { tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Flat Shipping', 'MODULE_SHIPPING_FLAT_STATUS', 'True', 'Do you want to offer flat rate shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_FLAT_COST', '5.00', 'The shipping cost for all orders using this shipping method.', '6', '0', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FLAT_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_FLAT_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_FLAT_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); } function remove() { tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { return array('MODULE_SHIPPING_FLAT_STATUS', 'MODULE_SHIPPING_FLAT_COST', 'MODULE_SHIPPING_FLAT_TAX_CLASS', 'MODULE_SHIPPING_FLAT_ZONE', 'MODULE_SHIPPING_FLAT_SORT_ORDER'); } } ?> I tried putting in echos to check the output of variables.. But I don't think it's getting a chance to set them as it just errors out with "Fatal error: Call to a member function get_products() on a non-object in /path/to/catalog/html/includes/modules/shipping/flat.php on line 46" If I put an echo in.. it just outputs a ":"... Hmmm... Quote Link to comment Share on other sites More sharing options...
dittones Posted January 22, 2006 Share Posted January 22, 2006 Hi appleguru, function flat() { global $order; to function flat() { global $order, $cart; add the $cart var see what happens... Quote Link to comment Share on other sites More sharing options...
appleguru Posted January 23, 2006 Author Share Posted January 23, 2006 Still gives the same error :( Quote Link to comment Share on other sites More sharing options...
dittones Posted January 23, 2006 Share Posted January 23, 2006 Try moving the function get_products() above function flat() but still within your class (contructor definition)....I am still thinking about it. It is probably something small that we are overlooking. Roman Quote Link to comment Share on other sites More sharing options...
Guest Posted January 23, 2006 Share Posted January 23, 2006 you have another get_products?? what this function is doing in the flat.php file? The get_products is in the cart class so you get the products from there. This is probably the root cause of your trouble. For instance you have no contents member in the flat class. Quote Link to comment Share on other sites More sharing options...
appleguru Posted January 23, 2006 Author Share Posted January 23, 2006 Uhh.. figured it out off a tim on the something awful forums: Well, your immediate problem is that you're calling get_products() on the object $cart, which is not declared in the scope of class flat. Wherever else you are calling get_products in your code, you must have a variable called $cart that you need to initialize in the same manner somewhere in class flat. The easy way (but BAD) to do this is to make $cart a global. Resist that urge and reinstantiate $cart inside this class, or figure out a different way to perform your query. ...All I needed to do was declare $cart in the class variables! Yay :) Seems to work wonderfully now :) Thanks guys! 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.