Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Duplicate zones shipping module

Duplicate zones shipping module

Locked

Views: 3,252

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
14 May 2006, 3:25 PM
#1
blkpower avatar

blkpower

New Zenner

Join Date:
Apr 2006
Posts:
3
Plugin Contributions:
0

Duplicate zones shipping module

Hi, on my website I have to add three kind of shipping opportunities.
All these three have prices different for zones.
So I need to duplicate the zones module (in that way for each zone I will have different shipment methods available).
I copied zones.php in includes/modules/shipping and named it zones_poste.php
I replaced all zones with zones_poste into the file.
After I created zones_poste.php in includes/languages/.../modules/shipping.

What I see is that now I give to my customer different kind of shipping for the same zone but when he chooses one of the two in the first page of the confirmation procedure, in the second page the price added to that of the products is always the zones.php created price.
Which could be the problem?

Is there an easier solution to have different shipping cot for each zone?

Thanks
Vincent

14 May 2006, 5:34 PM
#2
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,883
Plugin Contributions:
3

Re: Duplicate zones shipping module

when you created the duplicates zones modules files, did you remember to change the class names as well,

For xample. I start of with 1 zones.php file in modules/shipping

the class definition is

class zones {

if i then create a duplicate of this file, called zones1.php, I would ned to change the class definition in that file to

class zones1 {

Ian

15 May 2006, 10:27 PM
#3
blkpower avatar

blkpower

New Zenner

Join Date:
Apr 2006
Posts:
3
Plugin Contributions:
0

Re: Duplicate zones shipping module

Yes, of course.
I post my script, maybe someone can give me a help.
the file is zones_poste.php

<?php class zones_poste { var $code, $title, $description, $enabled, $num_zones_poste; // class constructor function zones_poste() { $this->code = 'zones_poste'; $this->title = MODULE_SHIPPING_zones_poste_TEXT_TITLE; $this->description = MODULE_SHIPPING_zones_poste_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_zones_poste_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_zones_poste_TAX_CLASS; // disable only when entire cart is free shipping if (zen_get_shipping_enabled($this->code)) { $this->enabled = ((MODULE_SHIPPING_zones_poste_STATUS == 'True') ? true : false); } // CUSTOMIZE THIS SETTING FOR THE NUMBER OF zones_poste NEEDED $this->num_zones_poste = 3; } // class methods function quote($method = '') { global $order, $shipping_weight, $shipping_num_boxes; $dest_country = $order->delivery['country']['iso_code_2']; $dest_zone = 0; $error = false; for ($i=1; $i<=$this->num_zones_poste; $i++) { $countries_table = constant('MODULE_SHIPPING_zones_poste_COUNTRIES_' . $i); $country_zones_poste = split("[,]", $countries_table); if (in_array($dest_country, $country_zones_poste)) { $dest_zone = $i; break; } } // elari - Added to select default country if not in listing // paulm: added Catch All Others on/of switch 1/3 if (($dest_zone == 0) && (MODULE_SHIPPING_zones_poste_CATCH_ALL == 'True' )) { $dest_zone = $this->num_zones_poste; // the zone is the last zone avalaible } // elari - Added to select default country if not in listing if ($dest_zone == 0) { $error = true; // if the latest zone catches "All Others" this does not happen anymore since by default the value is set to the last zone } else { $shipping = -1; $zones_poste_cost = constant('MODULE_SHIPPING_zones_poste_COST_' . $dest_zone); $zones_poste_table = split("[:,]" , $zones_poste_cost); $size = sizeof($zones_poste_table); for ($i=0; $i<$size; $i+=2) { if ($shipping_weight <= $zones_poste_table[$i]) { $shipping = $zones_poste_table[$i+1]; // paulm: added $shipping_num_boxes to output to display the number of boxes to ship when the max shipping weight is exceeded & ['country']['title'] added by Nils P. $shipping_method = MODULE_SHIPPING_zones_poste_TEXT_WAY . ' ' . $order->delivery['country']['title'] . ' : ' ; if ($shipping_num_boxes > 1) { $shipping_method .= $shipping_num_boxes . 'x'; } $shipping_method .= $shipping_weight . ' ' . MODULE_SHIPPING_zones_poste_TEXT_UNITS; break; } } if ($shipping == -1) { $shipping_cost = 0; $shipping_method = MODULE_SHIPPING_zones_poste_UNDEFINED_RATE; } else { $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_zones_poste_HANDLING_' . $dest_zone); } } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_zones_poste_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title); if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_zones_poste_INVALID_ZONE; return $this->quotes; } function check() { global $db; if (!isset($this->_check)) { $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_zones_poste_STATUS'"); $this->_check = $check_query->RecordCount(); } return $this->_check; } // elari - Added to select default country if not in listing function install() { global $db; $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable zones_poste Method', 'MODULE_SHIPPING_zones_poste_STATUS', 'True', 'Do you want to offer zone rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())"); // paulm: added Catch All Others on/of switch 2/3 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Catch All unlisted', 'MODULE_SHIPPING_zones_poste_CATCH_ALL', 'True', 'Do you want to use the latest zone to Catch All unlisted countries?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())"); $db->Execute("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_zones_poste_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_zones_poste_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); for ($i = 1; $i <= $this->num_zones_poste; $i++) { $default_countries = ''; if ($i == 1) { $default_countries = 'NL'; $shipping_table = '5000:5.00,10000:7.00,20000:8.00,30000:9.00,99000:150'; } if ($i == 2) { $default_countries = 'AT,BE,CY,CZ,DE,DK,EE,ES,FI,FR,GB,GR,HU,IE,IT,LT,LU,LV,MT,PL,PT,SE,SI,SK'; // All EU except NL $shipping_table = '2000:10.00,5000:15.00,10000:20.00,15000:25.00,20000:30.00,30000:40.00,99000:150.00'; } if ($i == 3) { $default_countries = 'All Others'; // this must be the lastest zone $shipping_table = '2000:12.50,5000:17.50,10000:25.00,15000:30,20000:35,99000:150.00'; } $db->Execute("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_poste_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".', '6', '0', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_zones_poste_COST_" . $i ."', '" . $shipping_table . "' , 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights. Example: 3:8.50,7:10.50,... Weights less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.', '6', '0', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_zones_poste_HANDLING_" . $i."', '0', 'Handling Fee for this shipping zone', '6', '0', now())"); } } // elari - Added to select default country if not in listing function remove() { global $db; $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { // paulm: added Catch All Others on/of switch 3/3 $keys = array('MODULE_SHIPPING_zones_poste_STATUS', 'MODULE_SHIPPING_zones_poste_CATCH_ALL', 'MODULE_SHIPPING_zones_poste_TAX_CLASS', 'MODULE_SHIPPING_zones_poste_SORT_ORDER'); for ($i=1; $i<=$this->num_zones_poste; $i++) { $keys[] = 'MODULE_SHIPPING_zones_poste_COUNTRIES_' . $i; $keys[] = 'MODULE_SHIPPING_zones_poste_COST_' . $i; $keys[] = 'MODULE_SHIPPING_zones_poste_HANDLING_' . $i; } return $keys; } } ?>
23 May 2006, 8:54 PM
#4
blkpower avatar

blkpower

New Zenner

Join Date:
Apr 2006
Posts:
3
Plugin Contributions:
0

Re: Duplicate zones shipping module

I found the solution,
you can duplicate one module and substitute zones with another word, but never use the underscore into its name.

Thanks
Blkpower

24 May 2006, 1:42 AM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Duplicate zones shipping module

NOTE: you should also make your replacements CASE sensative so that if you started with item.php and wanted itemusa.php you would change:

item to itemusa

ITEM to ITEMUSA

21 Dec 2010, 1:43 PM
#6
joe1joe1 avatar

joe1joe1

New Zenner

Join Date:
Sep 2009
Posts:
24
Plugin Contributions:
0

Re: Duplicate zones shipping module

Hi,
I duplicate the zones module naming it zonesair.
For some reason, it dose not recognize the country (for example US)
and the module is not available to choose from. Can you see in the code what is wrong? (version 1.3.8a)

<?php class zonesair { var $code, $title, $description, $enabled, $num_zoneair; // class constructor function zonesair() { $this->code = 'zonesair'; $this->title = MODULE_SHIPPING_ZONESAIR_TEXT_TITLE; $this->description = MODULE_SHIPPING_ZONESAIR_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_ZONESAIR_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_ZONESAIR_TAX_CLASS; $this->tax_basis = MODULE_SHIPPING_ZONESAIR_TAX_BASIS; // disable only when entire cart is free shipping if (zen_get_shipping_enabled($this->code)) { $this->enabled = ((MODULE_SHIPPING_ZONESAIR_STATUS == 'True') ? true : false); } // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED $this->num_zonesair = 4; } // class methods function quote($method = '') { global $order, $shipping_weight, $shipping_num_boxes, $total_count; $dest_country = $order->delivery['country']['iso_code_2']; $dest_zone = 0; $error = false; $order_total_amount = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices() ; for ($i=1; $i<=$this->num_zonesair; $i++) { $countries_table = constant('MODULE_SHIPPING_ZONESPOST_COUNTRIES_' . $i); $countries_table = strtoupper(str_replace(' ', '', $countries_table)); $country_zonesair = split("[,]", $countries_table); if (in_array($dest_country, $country_zonesair)) { $dest_zone = $i; break; } if (in_array('00', $country_zonesair)) { $dest_zone = $i; break; } } if ($dest_zone == 0) { $error = true; } else { $shipping = -1; $zonesair_cost = constant('MODULE_SHIPPING_ZONESAIR_COST_' . $dest_zone); $zonesair_table = split("[:,]" , $zonesair_cost); $size = sizeof($zonesair_table); $done = false; for ($i=0; $i<$size; $i+=2) { switch (MODULE_SHIPPING_ZONESAIR_METHOD) { case (MODULE_SHIPPING_ZONESAIR_METHOD == 'Weight'): if (round($shipping_weight,9) <= $zonesair_table[$i]) { $shipping = $zonesair_table[$i+1]; switch (SHIPPING_BOX_WEIGHT_DISPLAY) { case (0): $show_box_weight = ''; break; case (1): $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')'; break; case (2): $show_box_weight = ' (' . number_format($shipping_weight * $shipping_num_boxes,2) . MODULE_SHIPPING_ZONESAIR_TEXT_UNITS . ')'; break; default: $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight,2) . MODULE_SHIPPING_ZONESAIR_TEXT_UNITS . ')'; break; } // $shipping_method = MODULE_SHIPPING_ZONES_TEXT_WAY . ' ' . $dest_country . (SHIPPING_BOX_WEIGHT_DISPLAY >= 2 ? ' : ' . $shipping_weight . ' ' . MODULE_SHIPPING_ZONES_TEXT_UNITS : ''); $shipping_method = MODULE_SHIPPING_ZONESAIR_TEXT_WAY . ' ' . $dest_country . $show_box_weight; $done = true; if (strstr($zonesair_table[$i+1], '%')) { $shipping = ($zonesair_table[$i+1]/100) * $order_total_amount; } else { $shipping = $zonesair_table[$i+1]; } break; } break; case (MODULE_SHIPPING_ZONESAIR_METHOD == 'Price'): // shipping adjustment if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) <= $zonesair_table[$i]) { $shipping = $zonesair_table[$i+1]; $shipping_method = MODULE_SHIPPING_ZONESAIR_TEXT_WAY . ' ' . $dest_country; if (strstr($zonesair_table[$i+1], '%')) { $shipping = ($zonesair_table[$i+1]/100) * $order_total_amount; } else { $shipping = $zonesair_table[$i+1]; } $done = true; break; } break; case (MODULE_SHIPPING_ZONESAIR_METHOD == 'Item'): // shipping adjustment if (($total_count - $_SESSION['cart']->free_shipping_items()) <= $zonesair_table[$i]) { $shipping = $zonesair_table[$i+1]; $shipping_method = MODULE_SHIPPING_ZONESAIR_TEXT_WAY . ' ' . $dest_country; $done = true; if (strstr($zonesair_table[$i+1], '%')) { $shipping = ($zonesair_table[$i+1]/100) * $order_total_amount; } else { $shipping = $zonesair_table[$i+1]; } break; } break; } if ($done == true) { break; } } if ($shipping == -1) { $shipping_cost = 0; $shipping_method = MODULE_SHIPPING_ZONESAIR_UNDEFINED_RATE; } else { switch (MODULE_SHIPPING_ZONESAIR_METHOD) { case (MODULE_SHIPPING_ZONESAIR_METHOD == 'Weight'): // charge per box when done by Price $shipping_cost = ($shipping * $shipping_num_boxes) + constant('MODULE_SHIPPING_ZONESAIR_HANDLING_' . $dest_zone); break; case (MODULE_SHIPPING_ZONESAIR_METHOD == 'Price'): // don't charge per box when done by Price $shipping_cost = ($shipping) + constant('MODULE_SHIPPING_ZONESAIR_HANDLING_' . $dest_zone); break; case (MODULE_SHIPPING_ZONESAIR_METHOD == 'Item'): // don't charge per box when done by Item $shipping_cost = ($shipping) + constant('MODULE_SHIPPING_ZONESAIR_HANDLING_' . $dest_zone); break; } } } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_ZONESAIR_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost))); if ($this->tax_class > 0) { $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title); if (strstr(MODULE_SHIPPING_ZONESAIR_SKIPPED, $dest_country)) { // don't show anything for this country $this->quotes = array(); } else { if ($error == true) $this->quotes['error'] = MODULE_SHIPPING_ZONESAIR_INVALID_ZONE; } return $this->quotes; } function check() { global $db; if (!isset($this->_check)) { $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_ZONESAIR_STATUS'"); $this->_check = $check_query->RecordCount(); } return $this->_check; } function install() { global $db; $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable Zonesair Method', 'MODULE_SHIPPING_ZONESAIR_STATUS', 'True', 'Do you want to offer zoneair rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Calculation Method', 'MODULE_SHIPPING_ZONESAIR_METHOD', 'Weight', 'Calculate cost based on Weight, Price or Item?', '6', '0', 'zen_cfg_select_option(array(\'Weight\', \'Price\', \'Item\'), ', now())"); $db->Execute("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_ZONESAIR_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_ZONESAIR_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_ZONESAIR_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Skip Countries, use a comma separated list of the two character ISO country codes', 'MODULE_SHIPPING_ZONESAIR_SKIPPED', '', 'Disable for the following Countries:', '6', '0', 'zen_cfg_textarea(', now())"); for ($i = 1; $i <= $this->num_zonesair; $i++) { $default_countries = ''; if ($i == 1) { $default_countries = 'US,CA'; } $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Zone " . $i ." Countries', 'MODULE_SHIPPING_ZONESAIR_COUNTRIES_" . $i ."', '" . $default_countries . "', 'Comma separated list of two character ISO country codes that are part of Zone " . $i . ".<br />Set as 00 to indicate all two character ISO country codes that are not specifically defined.', '6', '0', 'zen_cfg_textarea(', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Zone " . $i ." Shipping Table', 'MODULE_SHIPPING_ZONESAIR_COST_" . $i ."', '3:8.50,7:10.50,99:20.00', 'Shipping rates to Zone " . $i . " destinations based on a group of maximum order weights/prices. Example: 3:8.50,7:10.50,... Weight/Price less than or equal to 3 would cost 8.50 for Zone " . $i . " destinations.<br />You can end the last amount as 10000:7% to charge 7% of the Order Total', '6', '0', 'zen_cfg_textarea(', now())"); $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zone " . $i ." Handling Fee', 'MODULE_SHIPPING_ZONESAIR_HANDLING_" . $i."', '0', 'Handling Fee for this shipping zone', '6', '0', now())"); } } function remove() { global $db; $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys() { $keys = array('MODULE_SHIPPING_ZONESAIR_STATUS', 'MODULE_SHIPPING_ZONESAIR_METHOD', 'MODULE_SHIPPING_ZONESAIR_TAX_CLASS', 'MODULE_SHIPPING_ZONESAIR_TAX_BASIS', 'MODULE_SHIPPING_ZONESAIR_SORT_ORDER', 'MODULE_SHIPPING_ZONESAIR_SKIPPED'); for ($i=1; $i<=$this->num_zonesair; $i++) { $keys[] = 'MODULE_SHIPPING_ZONESAIR_COUNTRIES_' . $i; $keys[] = 'MODULE_SHIPPING_ZONESAIR_COST_' . $i; $keys[] = 'MODULE_SHIPPING_ZONESAIR_HANDLING_' . $i; } return $keys; } } ?>