Please refer to TemplateMonster Support for any issues surrounding TemplateMonster/TemplateTuning Themes – thanks, Jigoshop Team

Extra shipping class

Phil

04 Feb, 2012 11:30 AM

Hi,

I created an extra shippping class that allowed for a special delivery option, ive just updated to Version 1.0 and my shipping class has been removed. Thats ok as I can re add but its not working. Has the set up been changed to not allow you to add extra shipping methods?

As before it would just for extra classes in the shipping folder?

Thanks in advance,
Phil

  1. Support Staff 2 Posted by Jeff on 04 Feb, 2012 09:50 PM

    Jeff's Avatar

    Yes, unfortunately for this case, the changes made will break this. How it worked prior was to bulk load any (and all) files found in the shipping folder.

    This is a blatant security risk and has been removed.

    All you really need to do is convert you module to a plugin. This is actually what was intended all along. Our Table Rates extension for example works this way. So the start of your file will need something like:

    /*
    

    Plugin Name: Table Rate Shipping for Jigoshop
    Plugin URI: https://jigoshop.com
    Description: Extends JigoShop to include a table rate shipping option. Table rate shipping lets you define rules based on price, weight, or the number of items in the cart vs destination.
    Version: 2.0.3
    Author: Chris Balchin / Robert Rhoades
    Author URI: https://jigoshop.com

    */
    

    In it’s constructor there is this:
    add_action(‘jigoshop_update_options’, array(&$this, ‘process_admin_options’));

    There is also:
    add_action(‘jigoshop_shipping_init’, ‘table_rate_shipping_init’);

    And:
    function add_table_rate_shipping_method( $methods ) {

    $methods[] = 'table_rate_shipping'; return $methods;
    

    } add_filter(‘jigoshop_shipping_methods’, ‘add_table_rate_shipping_method’ );

    There may be a few other things; this is off the top of my head. Leave it with me overnight and I’ll respond better tomorrow.

  2. Support Staff 3 Posted by Jeff on 05 Feb, 2012 07:51 AM

    Jeff's Avatar

    So essentially, if you have modelled your shipping module similar to the included ‘flat_rate.php’ shipping module found in the ‘shipping’ folder; in looking at that file there is a class definition that extends ‘jigoshop_shipping_method’.

    All the Table Rates Shipping plugin does is wrap that whole class definition in a function and gets an ‘add_action’ call to include it in Jigoshop Shipping:

    function table_rate_shipping_init() {
        class table_rate_shipping extends jigoshop_shipping_method {
            // constructor includes the following line
            add_action( 'jigoshop_update_options', array(&$this, 'process_admin_options'));
            // process_admin_options function
            // all other functions
        }
    }
    add_action( 'jigoshop_shipping_init', 'table_rate_shipping_init' );
    function add_table_rate_shipping_method( $methods ) {
        $methods[] = 'table_rate_shipping'; return $methods;
    }
    add_filter( 'jigoshop_shipping_methods', 'add_table_rate_shipping_method' );
    

    So, you call the ‘jigoshop_shipping_init‘ action to get your shipping module constructed and initialized.

    And you should probably already have the filter that returns the name of your module to ‘jigoshop_shipping_methods‘.

    I hope this clears it up enough for you, let me know if you need anything else.

    Cheers.

  3. 4 Posted by Phil on 05 Feb, 2012 01:00 PM

    Hi Jeff,

    Thanks for coming back to me, However I still seem to having touble, will I need to add come code to the shipping class for it now to read my new function?

    Ive strucutured it as you displayed above with all the functions from flat rate now being in side that class and function you pasted above.

    Thanks again

  4. Support Staff 5 Posted by Jeff on 05 Feb, 2012 01:30 PM

    Jeff's Avatar

    No, the only thing you need to do is wrap your shipping class inside of a function as I’ve shown. And the trailing ‘add_action’ will add your function to jigoshop when the time is right. There is code within jigoshop_shipping.class.php that calls that ‘action’ and instantiates each shipping module:

        private static function shipping_inits() {
        do_action('jigoshop_shipping_init'); /* loaded plugins for shipping inits */
        $load_methods = apply_filters('jigoshop_shipping_methods', array());
        foreach ($load_methods as $method) :
            self::$shipping_methods[] = new $method();
        endforeach;
    }
    

    So it’s important, the ‘filter’ you have should exactly return the name of your class that you extend. That’s how it gets instantiated.

    Finally, the comment block at the beginning of the file as I’ve show in my first post … and activate your plugin.

  5. 6 Posted by Phil on 05 Feb, 2012 05:57 PM

    Thanks Jeff!

    All sorted 🙂

    Should I put a copy of that somewhere? As Im assuming the next upgrade will revert that file back?

    Cheers, Phil

  6. Support Staff 7 Posted by Jeff on 05 Feb, 2012 07:48 PM

    Jeff's Avatar

    Hmm, you lost me … which file?

    To finish this off, you made the changes to your module, and moved it into it’s own plugin folder within the WordPress plugins folder and activated it?

    If so, no updates will effect it.

    Other than that, not sure I follow.

  7. 8 Posted by Phil on 05 Feb, 2012 09:17 PM

    Ah yeah sorry put it in the wrong place! Doh all taken care of and activated now 🙂

    Thanks again for your help

  8. Support Staff 9 Posted by Jeff on 05 Feb, 2012 11:09 PM

    Jeff's Avatar

    🙂

  9. 10 Posted by Vik Cheema on 22 Apr, 2013 09:07 PM

    Hi Jeff,

    This is Vik Cheema. I will appreciate if you will help me. I created custom shipping module/plugin extending the shipping methos. The issue is if the price calculated is null its showing the method as free on the cart page and checkout page. How can I exclude those methods.

    Thanks
    Regards
    Vik Cheema

  10. Support Staff 11 Posted by Jeff on 22 Apr, 2013 09:49 PM

    Jeff's Avatar

    If your shipping modules is not able to provide a rate in a certain instance, you need to set the error flag. This is how Premium Shipping does it:

                // no rules have been satisfied, therefore, this method cannot be chosen
                $this->has_error = empty($this->rates);
    
  11. 12 Posted by Vik Cheema on 23 Apr, 2013 05:13 PM

    Hi Jeff,

    Thanks for the reply. I tried your code and its not working for me. I am still getting some methods showing as free.

    Kind regards
    Vik Cheema

  12. 13 Posted by Vik Cheema on 23 Apr, 2013 07:33 PM

    Hi Jeff,

    Also should I set the flag when calculating item shipping price before applying taxes or after the shipping price.

    kind regards
    Vik Cheema

  13. 14 Posted by Vik Cheema on 23 Apr, 2013 07:42 PM

    Hi Jeff,

    Sorry for sending so many queries. So I set the error flag and it is set as I checked editing some core files but those methods are still shown as free. Can you please help me out as I am stuck now.

    Kind regards
    Vik Cheema

Reply to this discussion

Internal reply

Formatting help or Preview

Attached Files

You can attach files up to 10MB

If you don’t have an account yet, we need to confirm you’re human and not a machine trying to post spam.