We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42046
    • 436 Posts
    I've cobbled together a basic custom handler class for weight range based shipping in Minishop2. Instructions for implementation are as follows:

    Upload the following code to \core\components\minishop2\custom\delivery\ and call it rangeDelivery.class.php

    <?php
    class rangeDelivery extends msDeliveryHandler
    {
        
        public function getcost(msOrderInterface $order, msDelivery $delivery)
        {
            $cart        = $order->ms2->cart->status();
            $cart_weight = $cart['total_weight'];
            
            $weight_range = array(
                100,
                500,
                1000,
                2000,
                10000,
                20000,
                "+20000"
            );
            $price_range  = array(
                6.22,
                6.95,
                8.25,
                11.00,
                25.80,
                40.00,
                46.50
            );
            
            for ($loop = 0; $loop < count($weight_range); $loop++) {
                if ($weight_range[$loop]{0} == '+') {
                    $band_weight = (int) (substr($weight_range[$loop], 1));
                    $band_price  = $price_range[$loop];
                    if ($loop > 0) {
                        $start_price  = $price_range[$loop - 1];
                        $start_weight = $weight_range[$loop - 1];
                    } else {
                        $start_price  = 0;
                        $start_weight = 0;
                    }
                    return ($band_price * (ceil(($cart_weight - $start_weight) / $band_weight)) + $start_price);
                }
                if ($weight_range[$loop] > $cart_weight) {
                    return ($price_range[$loop]);
                }
            }
            
            return ($cost);
            
        }
        
    }


    In Minishop2>>Settings>>Deliveries select the delivery method you want to use a weight range calculation on and put rangeDelivery as the Handler class.

    You can change the weight and price ranges by altering the $weight_range and $price_range arrays. First value of the $weight_range array (as an up-to value) corresponds to the first value of the $price_range array etc etc.

    If you want a different weight/price range for another delivery method, duplicate the script with a different name (eg myDelivery.class.php), alter the $weight_range and $price_range arrays and change line two to:
    class myDelivery extends msDeliveryHandler
    then specify the other delivery method Handler class as myDelivery [ed. note: absent42 last edited this post 10 years, 8 months ago.]
      • 36686
      • 165 Posts
      Hi Dan, I would love to have a weight based shipping table such as the above, but I don't get it to work with miniShop 2.1.2. When I add the handler class my checkout page stops working (no delivery fees are added and nothing happens when I click the check out button).

      I'd also love to be able to offert free delivery when the order value exceeds a set amount. I think it's explained at http://bezumkin.ru/modx/minishop2/classes/725/#comment-8365 but I can't quite work out how. Apart from being php illiterate, Google Translate doesn't make it any easier I guess... :-/
        • 11478
        • 6 Posts
        I have the minishop2 version's 2.1.7.

        I have the same problem (cart have a white page) when I write an Handler class in Minishop2>>Settings>>Deliveries.

        Do you have a solution ?