Why do the customer's shipping options not match the database or module settings in Zen Cart 1.5?
Asked Answered
L

1

23

A client has a custom shipping module in Zen Cart 1.5. Yesterday I adapted the module to be zone-aware (they wanted the original module to apply to the USA, and a copy to be tweaked for non-USA orders).

Now I only have one shipping option in that module, not the configured four. The zone awareness seems to be working (my test orders show the USA fee, not the international fee, for the option that shows) but only the first option shows up.

Here's the code of the module:

/*include functions/functions_categories.pnp for zen_product_in_category method
*/
class tfn
{
    var $code, $title, $description, $icon, $enabled, $types;

    // class constructor
    function tfn() {
        global $order, $db, $types, $fees;

        $this->code = 'tfn';
        $this->title = MODULE_SHIPPING_TFN_TEXT_TITLE;
        $this->description = MODULE_SHIPPING_TFN_TEXT_DESCRIPTION;
        $this->sort_order = MODULE_SHIPPING_TFN_SORT_ORDER;
        $this->icon = '';
        $this->tax_class = MODULE_SHIPPING_TFN_TAX_CLASS;
        $this->tax_basis = MODULE_SHIPPING_TFN_TAX_BASIS;

        // disable only when entire cart is free shipping
        if (zen_get_shipping_enabled($this->code)) {
            $this->enabled = ((MODULE_SHIPPING_TFN_STATUS == 'True') ? true : false);
        }

        if (($this->enabled == true) && ((int)MODULE_SHIPPING_TFN_ZONE > 0)) {
            $check_flag = false;
            $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TFN_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
            while (!$check->EOF) {
                if ($check->fields['zone_id'] < 1) {
                    $check_flag = true;
                    break;
                } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
                    $check_flag = true;
                    break;
                }
                $check->MoveNext();
            }

            if ($check_flag == false) {
                $this->enabled = false;
            }
        }

        $types = array(
            'STD'  => 'Standard',
            'FXH'  => 'USPS Priority Mail',
            'FXES' => 'USPS Express Mail',
            'FXSO' => 'FedEx Overnight'
        );
        // 'FAM' => 'Foreign Airmail',
        // 'FXG' => 'USPS Priority Mail with Delivery Confirmation',
        // 'FX2D' => 'FedEx 2nd Day',

        $fees = array(
            'STD'  => '0.00',
            'FXH'  => '4.50',
            'FXES' => '17.50',
            'FXSO' => '28.00'
        );
        // 'FAM' => '15.00',
        // 'FXG' => '5.50',
        // 'FX2D' => '10.00',
    }

    // class methods
    function quote($method = '') {
        global $order, $types, $fees;

        $methods = array();

        $this->quotes = array(
            'id'     => $this->code,
            'module' => $this->title
        );

        if (($method == '') || (!isset($method))) {
            foreach ($fees as $type => $cost) {
                $methods[] = array(
                    'id'    => $type,
                    'title' => $types[$type],
                    'cost'  => $this->_calculateBaseCost() + $cost
                );
            }
        } else {
            $cost = $fees[$method];
            $methods[] = array(
                'id'    => $method,
                'title' => $types[$method],
                'cost'  => $this->_calculateBaseCost() + $cost
            );
        }

        $this->quotes['methods'] = $methods;
        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);

        return $this->quotes;
    }

    function _calculateBaseCost() {
        global $db, $shipping_cost;

        $total_count = $_SESSION['cart']->count_contents();
        $total_count = $total_count - $_SESSION['cart']->free_shipping_items();
        $foreign_charge = $this->_additionalForeignCharge();
        $shipping_cost = ($total_count * (MODULE_SHIPPING_TFN_BASE_COST + $foreign_charge));

        return $shipping_cost;
    }

    function _additionalForeignCharge() {
        global $db, $order;

        $foreign_charge = 0;

        $dest_country = $order->delivery['country']['iso_code_2'];

        if ($dest_country != 'US') {
            $foreign_charge = MODULE_SHIPPING_TFN_FOREIGN_COST;
        }

        return $foreign_charge;
    }

    function check() {
        global $db;
        if (!isset($this->_check)) {
            $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TFN_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 Item Shipping', 'MODULE_SHIPPING_TFN_STATUS', 'True', 'Do you want to offer per item 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, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_TFN_BASE_COST', '2.50', 'The shipping cost will be multiplied by the number of items in an order that uses this shipping method.', '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 ('Additional Foreign Shipping Cost', 'MODULE_SHIPPING_TFN_FOREIGN_COST', '4.00', 'The additional foreign shipping cost will be multiplied by the number of items and added to the base cost.', '6', '0', 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_TFN_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_TFN_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_TFN_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, date_added) values ('Sort Order', 'MODULE_SHIPPING_TFN_SHIPPING_TYPES', '0', 'Code and Name for each kind of shipping offered.', '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 ( 'Shipping Methods: <br />Standard, Foreign Airmail, FedEx Home Delivery, FedEx Ground, FedEx Express Saver, FedEx 2nd Day, FedEx Standard Overnight', 'MODULE_SHIPPING_TFN_TYPES', 'STD, FAM, FXHD, FXG, FXES, FX2D, FXSO', 'Select the TFN services to be offered.', '6', '13', 'zen_cfg_select_multioption(array(\'STD\',\'FAM\',\'FXHD\', \'FXG\', \'FXES\', \'FX2D\', \'FXSO\'), ', 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 ('Shipping Zone', 'MODULE_SHIPPING_TFN_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
    }

    function remove() {
        global $db;
        $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
        return array(
            'MODULE_SHIPPING_TFN_STATUS', 'MODULE_SHIPPING_TFN_BASE_COST',
            'MODULE_SHIPPING_TFN_FOREIGN_COST', 'MODULE_SHIPPING_TFN_TAX_CLASS',
            'MODULE_SHIPPING_TFN_TAX_BASIS', 'MODULE_SHIPPING_TFN_SORT_ORDER',
            'MODULE_SHIPPING_TFN_TYPES', 'MODULE_SHIPPING_TFN_ZONE'
        );
    }
}
?>

The admin page shows eight shipping options, with the four listed in the code selected.

Here's the relevant database entries, including the international module:

mysql> select configuration_value, configuration_key from configuration where configuration_key LIKE 'MODULE_SHIPPING_%_TYPES';
+-----------------------+----------------------------------------+
| configuration_value   | configuration_key                      |
+-----------------------+----------------------------------------+
| 0                     | MODULE_SHIPPING_TFN_INT_SHIPPING_TYPES | 
| STD                   | MODULE_SHIPPING_TFN_INT_TYPES          | 
| 0                     | MODULE_SHIPPING_TFN_SHIPPING_TYPES     | 
| STD, FXHD, FXES, FXSO | MODULE_SHIPPING_TFN_TYPES              | 
+-----------------------+----------------------------------------+
4 rows in set (0.00 sec)

Updating the _SHIPPING_TYPES settings directly in the database (e.g. setting it to 1 instead of 0) doesn't seem to change anything. I can't find any code which seems to call this setting.

Where is Zen Cart determining the shipping options? How can I make it show the ones I want?

Lagan answered 3/4, 2012 at 14:36 Comment(10)
OK, this is a little ridiculous. If this question is unanswerable, could someone at least comment and let me know what information is missing which would make it answerable? Has SO grown so large that bounties go unclaimed?Lagan
I will try to look on this issue this weekendHoulihan
Great! By this weekend there will be a revival badge on offer. :)Lagan
can you paste the function install() part of the code so I can test on my local install? BTW, it seems like the custom built module is actually just making too much fuss about something that should and could be simple. For example, you could clone the flat rate module 7 times and have a total of 8 flat rate modules and use each for your combinations (4 for US and 4 for international)...Selfinduced
I've restored the install() function. Thanks for taking a look. It's possible that the custom module is overkill, but it was already there when I took over; I was just trying to make it work zone-aware.Lagan
@Lagan sorry, didn't notice you replied. Anyway, I just installed it and tested and it works fine, just as expected from the code. But, I believe I realized what you're after - you have 7 shipping types available in config (check boxes) and your problem is the module doesn't respond to your selection, right? Please correct me if I'm wrong. If I'm right, then you can simply forget that you even have those check boxes since the code logic isn't done. The shipping options are simply hard coded and you did a good job with zone awareness, but that's as far as your module can go w/o further codingSelfinduced
Yes, the shipping types checkboxes (eight of them, actually) are available in config, and the module does not respond to selection. I'm not surprised that the shipping options are hard-coded; I'm surprised that there's only one, and not four, reflecting the $types and $fees arrays.Lagan
I'm not sure I follow. You're saying you get only one option at checkout? I got 4, take a look: tinypic.com/r/j9t25i/6 and it's a clean install, I just installed your module w/o changes. And there are 7 shipping methods :) Of course, when tested with another zone, the module didn't show up at all, as expected. Am I missing something?Selfinduced
Yes, I only get one option at checkout: imgur.com/kqKUX Maybe I should uninstall/reinstall the module? I'm not sure how that's done.Lagan
I don't think reinstall will help since the settings and options have nothing to do with the database entries (it's hard coded), but you sure can try. In admin->modules->shipping just click the module, click delete button and then click install. Did you check your /cache folder for any error logs? And, maybe a stupid question, but are you sure you're using the correct module and file combination? :) Perhaps check the module file to make sure you didn't comment out the fees/methods arrays and/or you're using the matching fee/method?Selfinduced
T
0

When shipping modules don't show up its usually because of a mistake in the file naming and file structure of the shipping option. You know how you have to make 50 different files just to add 1 page in zen cart?

Carefully follow the instructions here and make sure your naming conventions as well as file placement are all correct.

http://www.zen-cart.com/wiki/index.php/Creating_Your_Own_Shipping_Module

Tiller answered 8/1, 2014 at 23:4 Comment(2)
Thanks for the answer! I'm no longer working on this project, so I can't check to see if it works, but hopefully if someone else finds the question they'll have this to refer to.Lagan
Search usually does it for me.Lagan

© 2022 - 2024 — McMap. All rights reserved.