简体   繁体   中英

Opencart Shipping Method Required

I have created a new shipping module based on the post below

http://forum.opencart.com/viewtopic.php?f=142&t=30226

The shipping method checks what members group the user is in, and if they then qualify for free delivery based on the cart price. All works great, except when you go to the checkout and select the free shipping method it comes back with the error "Warning: Shipping method required!"

The model for the shipping is below, can anyone shed any light on this?

<?php
class ModelShippingFreeusergroup extends Model {
    function getQuote($address) {
        $this->language->load('shipping/freeusergroup');

        $customer_group_id = $this->customer->getCustomerGroupId();
        if ($customer_group_id < 1)$customer_group_id = 1;

        $cart_total = $this->cart->getTotal();

        $strQuery = "SELECT * FROM " . DB_PREFIX . "members_delivery " . 
            " WHERE price <= '" . $cart_total . "' AND customer_group_id = '" . $customer_group_id . "' " . 
            " LIMIT 1";
        $query = $this->db->query($strQuery);

        //$ShipArray = array();
        $method_data = array();
        if ($query->num_rows > 0)
        {
            foreach ($query->rows as $result) {
                $quote_data['freeusergroup'] = array(
                    'code'          => 'freeusergroup',
                    'title'         =>  'Free Delivery',
                    'cost'          =>  0.00,
                    'tax_class_id'  => $this->config->get('weight_tax_class_id'),//0,
                    'text'          => $this->currency->format(0.00)
                );

                $method_data = array(
                    'code'          => 'freeusergroup',
                    'title'         => 'Free Delivery',
                    'quote'         => $quote_data,
                    'sort_order'    => $this->config->get('freeusergroup_sort_order'),
                    'error'         => false
                );
            }
        }
        return $method_data;

    }
}
?>

I've managed to fix it, I didn't realize the method data quote data required a . in the code, checking the validate function on the controller pointed me to the fact that the 'code' in the quote data should be 'freeusergroup.freeusergroup'

The first part of the code is taken from the method_data,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM