shaggy2dope2125 Posted September 24, 2008 Share Posted September 24, 2008 (edited) heres the code: <?php /* $Id: item_model.php, V 1.0 2005/14.09 05:03:31 hpd1 Exp $ Written by Kevin Myers, [email protected] osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright © 2003 osCommerce Copyright ? 2005 Magickoncepts.com Released under the GNU General Public License */ class item_model { var $code, $title, $description, $icon, $enabled; // class constructor function item_model() { global $order; $this->code = 'item_model'; $this->title = MODULE_SHIPPING_ITEM_MODEL_TEXT_TITLE; $this->description = MODULE_SHIPPING_ITEM_MODEL_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_ITEM_MODEL_SORT_ODER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_ITEM_MODEL_TAX_CLASS; $this->enabled = ((MODULE_SHIPPING_ITEM_MODEL_STATUS == 'True') ? true : false); $this->num_zones = 5; if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_ITEM_MODEL_ZONE > 0) ) { $check_flag = false; $check_query = tep_db_query("SELECT zone_id FROM " . TABLE_ZONE__TO_GEO_ZONES . " WHERE geo_zone_id = '" . MODULE_SHIPPING_ITEM_MODEL_ZONE . "' and zone_county_id '" . $order->delivery['country']['id'] . "' ORDER BY zode_id"); while ($check = tep_fetch_array($check_query)) { if ($check['zone_id'] < 1) { $check_flag = true; break; } elseif ($check['zone_id'] == $order->delivery['zone_id']) { $check_flag = true; break; } } if ($check_flag == false) { $this->enabled = false; } } } // class methods function quote($method = '') { global $order, $total_count, $order_id; $dest_country = $order->delivery['country']['iso_code_2']; $dest_zone = 0; $error1 = false; for ($i=1; $s<=$this->num_zones; $i++) { $countries_table = constant(MODULE_SHIPPING_ITEM_MODEL_COUNTRIES_ . $i); $country_zones = split("[,]", $countries_table); if(in_Array($dest_country, $country_zones)) { $dest_zone = $i; break; }//ends if statement }//ends for loop if ($dest_zone == 0) { for ($i=1; $i<=$this->num_zones; $i++) { $countries_table = constant(MODULE_SHIPPING_ITEM_MODEL_COUNTRIES_ . $i); if ($countries_table == '' or $countries_table == '*') { $dest_zone = $i; break; } } } if ($dest_zone == 0) { $error1 = true; } $orders_products_query = tep_db_query("SELECT orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price FROM ". TABLE_ORDER_PRODUCTS. "WHERE order_id = '" . (int)$orders_id ."'"); $num_orders = mysql_num_rows($orders_products_query); $x = 0; while($orders_products = tep_db_fetch_array($orders_product_query)) { $this->products[$x] = array( 'qty' => $orders_products['products_quantity'], 'id' => $orders_products['products_id'], 'name' => $orders_products['products_name'], 'model' => $orders_products['products_model'], 'tax' => $orders_products['products_tax'], 'price' => $orders_products['produacts_price'], 'final_price' => $orders_products['final_price']); $x++; } for($X = 0; $X <= $num_orders; $X++) { if($this->products[$X]['model'] == 'single') { $singles_count++; } elseif($this->products[$X]['model'] == 'box') { $box_count++; } elseif($this->products[$X]['model'] == 'set') { $set_count++; } elseif($this->products[$X]['model'] == 'deck') { $deck_count++; } elseif($this->products[$X]['model'] == 'lot') { $lot_count++; } } if($singles_count < "30") { $shipping_singles = 1; } else { $shipping_singles = 1 + ($shipping_count - "30")* ".1"; } $shipping_box = $box_count * 2; $shipping_set = $set_count * 2; $shipping_deck = $deck_count * 0.75; $shipping_lot = $lot_count * 2; $shipping_total = $shipping_singles + $shipping_box + $shipping_set + $shipping_deck + $shipping_lot; //this is where i set up the additional charge for each "zone" if($dest_zone == 1) { $shipping_total = $shipping_total; } elseif($dest_zone == 2) { $shipping_total = $shipping_total + ($shipping_total * .02); } elseif($dest_zone == 3) { $shipping_total = $shipping_total + ($shipping_total * .025); } elseif($dest_zone == 4) { $shipping_total = $shipping_total + ($shipping_total * .03); } elseif($dest_zone == 5) { $shipping_total = $shipping_total + ($shipping_total * .045); }//this ends the shipping totals for each zone define ("MODULE_SHIPPING_ITEM_MODEL_COST", $shipping_total); $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_ITEM_MODEL_TEXT_TITLE, 'methodes' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_ITEM_MODEL_TEXT_WAY, 'cost' => MODULE_SHIPPING_ITEM_MODEL_COST )//closes second array )//closes first aray );//closes the qutes array 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; }//ends the quote functions function check() { if (!isset($this->_check)) { $check_query = tep_db_query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_SHIPPING_ITEM_MODEL_STATUS'"); $this->_check = tep_db_num_rows($check_query); } return $this->_check; }//ends check function 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 Model Shipping', 'MODULE_SHIPPING_ITEM_MODEL_STATUS', 'True', 'Do you want to offer model shipping rates?', '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, use_function, set_function, date_added) VALUES ('Tax Class', 'MODULE_SHIPPING_ITEM_MODEL_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, date_added) VALUES ('Sort Order', 'MODULE_SHIPPING_ITEM_MODEL_SORT_ORDER' , '0', 'Sort Order of display.', '6', '0', now())"); for ($i = 1; $i <= $this->num_zones; $i++) { if ($i == 1) { $default_countries = 'US'; } elseif ($i == 2) { $default_countries = 'CA'; } elseif ($i == 3) { $default_countries = 'AT,BE,GB,FR,DE,GL,IS,IE,IT,NO,NL,DK,PL,ES,SE,CH,FI,PT,IL,GR'; } elseif ($i == 4) { $default_countries = 'JP,AU,NZ,SG'; } elseif ($i == 5) { $default_countries = 'TW,CN,HK'; }//ends the if statments for default countires //tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".', '6', '0', now())"); tep_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Zone " . $i ." Countries', 'MODULE_SHIPPING_ITEM_MODEL_COUNTRIES_" . $i ."', ' .$default_countries . ', 'Comma seprtated list of two character ISO country codes that are part of zone " . $i . ".', '6', '0', now())"); }//ends the for loop }//ends the install function function remove() { tep_db_query("DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key in ('" . implode(" ', '", $this->keys()) . "')"); }//ends the remove function function keys() { $keys = array('MODULE_SHIPPING_ITEM_MODEL_STATUS', 'MODULE_SHIPPING_ITEM_MODEL_TAX_CLASS', 'MODELU_SHIPPING_ITEM_MODEL_SORT_ORDER'); for ($i=1; $i<=$this->num_zones; $i++) { $keys[] = 'MODULE_SHIPPING_ITEM_ZONES_COUNTRIES_' . $i; }//ends the for loop return $keys; }//ends the keys function }//ends the modlue ?> it installs, but under the admin section it doesn't display a sort order, so thats messed up also. but when i try to place an order it tell me that MODULE_SHIPPING_ITEM_ZONES_COUNTIRES_ isn't there. heres the error from the page: Warning: constant() [function.constant]: Couldn't find constant MODULE_SHIPPING_ITEM_MODEL_COUNTRIES_6 in /home/ravenslo/public_html/catalog/includes/modules/shipping/item_model.php on line 63 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '0'' at line 1 SELECT orders_products_id, products_id, products_name, products_model, products_price, products_tax, products_quantity, final_price FROM TABLE_ORDER_PRODUCTSWHERE order_id = '0' [TEP STOP] im lost, been trying to fix it for a few days now. thanks. edit: i fixed the space problem in the SELECT statement, but now it throws itself into a never ending loop of the MODULE_SHIPPING_ITEM_MODEL_COUNTRIES_ Edited September 24, 2008 by shaggy2dope2125 Quote Link to comment Share on other sites More sharing options...
shaggy2dope2125 Posted September 24, 2008 Author Share Posted September 24, 2008 ok, i got the addon to work now, but its not running the query for get the order. its telling me that the order id is zero. Quote Link to comment Share on other sites More sharing options...
shaggy2dope2125 Posted September 24, 2008 Author Share Posted September 24, 2008 ignore this post. im a moron and didn't realize that i was looking for an order that didn't get placed yet. its all stored in the basket until i complete the order. Quote Link to comment Share on other sites More sharing options...
shaggy2dope2125 Posted September 24, 2008 Author Share Posted September 24, 2008 ok, i lied. heres the problem that i have encountered now. it works but will not display the option to select it as a shipping method. im unsure on how to solve this problem. code: <?php /* $Id: item_model.php, V 1.0 2005/14.09 05:03:31 hpd1 Exp $ Written by Kevin Myers, [email protected] osCommerce, Open Source E-Commerce Solutions [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url] Copyright © 2003 osCommerce Copyright ? 2005 Magickoncepts.com Released under the GNU General Public License */ class item_model { var $code, $title, $description, $icon, $enabled; // class constructor function item_model() { global $order; $this->code = 'item_model'; $this->title = MODULE_SHIPPING_ITEM_MODEL_TEXT_TITLE; $this->description = MODULE_SHIPPING_ITEM_MODEL_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_ITEM_MODEL_SORT_ODER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_ITEM_MODEL_TAX_CLASS; $this->enabled = ((MODULE_SHIPPING_ITEM_MODEL_STATUS == 'True') ? true : false); $this->num_zones = 5; if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_ITEM_MODEL_ZONE > 0) ) { $check_flag = false; $check_query = tep_db_query("SELECT zone_id FROM " . TABLE_ZONE__TO_GEO_ZONES . " WHERE geo_zone_id = '" . MODULE_SHIPPING_ITEM_MODEL_ZONE . "' and zone_county_id '" . $order->delivery['country']['id'] . "' ORDER BY zode_id"); while ($check = tep_fetch_array($check_query)) { if ($check['zone_id'] < 1) { $check_flag = true; break; } elseif ($check['zone_id'] == $order->delivery['zone_id']) { $check_flag = true; break; } } if ($check_flag == false) { $this->enabled = false; } } } // class methods function quote($method = '') { global $order, $total_count, $order_id, $oID, $cartID, $customer_id; $dest_country = $order->delivery['country']['iso_code_2']; $dest_zone = 0; $error1 = false; for ($i=1; $s<=$this->num_zones; $i++) { echo "LOOP 1"; $countries_table = constant(MODULE_SHIPPING_ITEM_MODEL_COUNTRIES_ . $i); $country_zones = split("[,]", $countries_table); if(in_Array($dest_country, $country_zones)) { $dest_zone = $i; break; }//ends if statement }//ends for loop if ($dest_zone == 0) { for ($i=1; $i<=$this->num_zones; $i++) { ECHO "LOOP 2"; $countries_table = constant(MODULE_SHIPPING_ITEM_MODEL_COUNTRIES_ . $i); if ($countries_table == '' or $countries_table == '*') { $dest_zone = $i; break; } } } if ($dest_zone == 0) { $error1 = true; } $this->Cart_contents = tep_db_query("SELECT * FROM " . TABLE_CUSTOMERS_BASKET . " WHERE customers_id = '". (int)$customer_id."'"); $this->num_cards = mysql_num_rows($this->Cart_contents); $this->Cart_contents = tep_db_fetch_array($this->Cart_contents); for($x=1;$x<=$this->num_cards;$x++) { $this->productsID[$x] = $this->Cart_contents['products_id']; } $this->num_products = count($this->productsID); for($X=1;$X<=$this->num_products;$X++) { $product_Info = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS . " WHERE products_id = '". $this->productsID[$X]."'"); $this->products = tep_db_fetch_array($product_Info); if($this->products['products_model'] == 'single') { $singles_count++; } elseif($this->products['products_model'] == 'box') { $box_count++; } elseif($this->products['products_model'] == 'set') { $set_count++; } elseif($this->products['products_model'] == 'deck') { $deck_count++; } elseif($this->products['products_model'] == 'lot') { $lot_count++; } } if($singles_count < "30") { $shipping_singles = 1; } else { $shipping_singles = 1 + (($singles_count - "30")* .1); } $shipping_box = $box_count * 2; $shipping_set = $set_count * 2; $shipping_deck = $deck_count * 0.75; $shipping_lot = $lot_count * 2; $shipping_total = $shipping_singles + $shipping_box + $shipping_set + $shipping_deck + $shipping_lot; //this is where i set up the additional charge for each "zone" if($dest_zone == 1) { $shipping_total = $shipping_total; } elseif($dest_zone == 2) { $shipping_total = $shipping_total + ($shipping_total * .02); } elseif($dest_zone == 3) { $shipping_total = $shipping_total + ($shipping_total * .025); } elseif($dest_zone == 4) { $shipping_total = $shipping_total + ($shipping_total * .03); } elseif($dest_zone == 5) { $shipping_total = $shipping_total + ($shipping_total * .045); }//this ends the shipping totals for each zone $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_ITEM_MODEL_TEXT_TITLE, 'methodes' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_ITEM_MODEL_TEXT_WAY, 'cost' => $shipping_total )//closes second array )//closes first aray );//closes the qutes array 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; }//ends the quote functions function check() { if (!isset($this->_check)) { $check_query = tep_db_query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_SHIPPING_ITEM_MODEL_STATUS'"); $this->_check = tep_db_num_rows($check_query); } return $this->_check; }//ends check function 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 Model shipping', 'MODULE_SHIPPING_ITEM_MODEL_STATUS', 'True', 'Do you want to offer model 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, use_function, set_function, date_added) VALUES ('Tax Class', 'MODULE_SHIPPING_ITEM_MODEL_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, date_added) VALUES ('Sort Order', 'MODULE_SHIPPING_ITEM_MODEL_SORT_ORDER' , '0', 'Sort Order of display.', '6', '0', now())"); for ($i = 1; $i <= $this->num_zones; $i++) { if ($i == 1) { $default_countries = 'US'; } elseif ($i == 2) { $default_countries = 'CA'; } elseif ($i == 3) { $default_countries = 'AT,BE,GB,FR,DE,GL,IS,IE,IT,NO,NL,DK,PL,ES,SE,CH,FI,PT,IL,GR'; } elseif ($i == 4) { $default_countries = 'JP,AU,NZ,SG'; } elseif ($i == 5) { $default_countries = 'TW,CN,HK'; }//ends the if statments for default countires //tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_ZONES_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".', '6', '0', now())"); tep_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Zone " . $i ." Countries', 'MODULE_SHIPPING_ITEM_MODEL_COUNTRIES_" . $i ."', '" .$default_countries . "', 'Comma seprtated list of two character ISO country codes that are part of zone " . $i . ".', '6', '0', now())"); }//ends the for loop }//ends the install function function remove() { tep_db_query("DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key in ('" . implode(" ', '", $this->keys()) . "')"); }//ends the remove function function keys() { $keys = array('MODULE_SHIPPING_ITEM_MODEL_STATUS', 'MODULE_SHIPPING_ITEM_MODEL_TAX_CLASS', 'MODELU_SHIPPING_ITEM_MODEL_SORT_ORDER'); for ($i=1; $i<=$this->num_zones; $i++) { $keys[] = 'MODULE_SHIPPING_ITEM_ZONES_COUNTRIES_' . $i; }//ends the for loop return $keys; }//ends the keys function }//ends the modlue ?> Quote Link to comment Share on other sites More sharing options...
shaggy2dope2125 Posted September 24, 2008 Author Share Posted September 24, 2008 ok. i figured that one out. now the problem is that with another shipping mod enabled, i can select mine and the other one will be the one that works. if its just mine installed it will not move to the next page. im lost on this one here. 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.