13 Replies Latest reply: Jul 10, 2014 6:06 PM by TheBCMan RSS

    Free Shipping by Postcode?

    jsbalmer Community Member

      Hi,

       

      racking my brains on this one.

       

      Have a list of postcodes which I want to be able to offer free shipping on all orders to.

       

      The easiest option would seem to be to simply set the value generated by (I think) shippingCalc to 0, but I can't seem to find a way of making this happen. From what I can see it doesn't seem to be a value I can directly manipulate.

       

      I've tried setting up an option in Shipping Options in BC, with the idea of hiding it and then displaying it after evaluating the entered postcode against an array and selecting it if it matches (using javascript), but no luck, alas.

       

      Any suggestions would be extremely welcome, as this one is important to be able to implement. I've only recently launched into javascript, so would prefer to stick with what I'm currently learning rather than venture in to jQuery or json or Ajax, but if that's what it takes, please let me know.

       

      On a more general note, I would also like to be able to input the postcode before the user clicks on the dropdown to select their shipping options - I presume my best bet there is to use javascript to get the values, hide the system-generated output and then pass them to my own output?

       

      Cheers,

       

      Jason

        • 1. Re: Free Shipping by Postcode?
          TheBCMan Community Member

          Jason,

           

          You need to overwrite the BC javascript on the page or hook the functions. You have to remember you are dealing with a quasi AJAX(pro) system and make sure you send the data back the server when you are trying to select thing. It's a very detailed process and took alot of time an error on my part, I build a library to do it but because of the time invested I sell it as a packaged solution to customers.

          • 2. Re: Free Shipping by Postcode?
            Liam Dilley CommunityMVP

            We have a very small and simple way to handle BC stuff with proper binding these days so that sort of stuff is never a problem any more within our projects. Can be a hassle doing updates built by other people but that aspect is not an issue.

            @Jason - The key thing is basically having a set of shipping options and running a postcode check to find a match, you can use things like the google map API and then based on the postcode and how your running the regions etc you can auto select the shipping option.

            • 3. Re: Free Shipping by Postcode?
              jsbalmer Community Member

              Cheers for the responses to you, both.

               

              I guess in this case I was after a bit more specific information, which I seem to have not communicated very well.

               

              I get the impression, given this is essentially a meeting place between two categories of BC users, that giving stackoverflow-type answers is not really going to work for the web developers who post here, as it's essentially them doing work for free. I get that, and appreciate it. What I'm asking for is advice that falls somewhere in between stackoverflow and what you both have given above. It is completely ok if neither of you wish to provide that sort of help, but that's essentially what I would need.

               

              So, regarding this: "The easiest option would seem to be to simply set the value generated by (I think) shippingCalc to 0, but I can't seem to find a way of making this happen. From what I can see it doesn't seem to be a value I can directly manipulate."

               

              Is that true? Or is it possible to target that value directly?

               

              So to make this easier on anyone who may be willing to help, this is what I had:

               

              function freeLocalDelivery() {

                  var freePostCodes = ["( 2000, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2016, 2017, 2021, 2025, 2027, 2028)"]

                  var ShippingOptions = document.getElementById("ShippingOptions");

                  var shippingPostcode = document.getElementById("shippingPostcode");

                  {

                      if ("shippingPostcode" in "freePostCodes" == true)

                              ShippingOptions.onchange(ShippingOptions.selectedIndex = ???);

                          }

                  }

               

              This is obviously not working, and I truly do not understand why. I've tried variations on the onchange, including .value, using an index value as well as the shippingOption selected value, and I'm just at my wits end. So help by letting me know what needs to replace the question marks for a start, if you'd be so kind, or just give me a slightly more focused idea of how I need to proceed. I'm not asking anyone to write code for me, I just want to learn what I'm doing wrong.

               

              Cheers.

              • 4. Re: Free Shipping by Postcode?
                TheBCMan Community Member

                The selected index for any of the shipping values could be anywhere in the list, I've seen free shipping listed at the top or the bottom, if you are going to use index BC might change the order so I don't recommend that, that is created when you make the shipping option so either you should attempt to select by the text in the option field.

                 

                I can't write the code for you, few things, when you select a shipping option BC does a quazii AJAX update, the server sends back the entire DIV (container) HTML and the error code in a javascript array. So you will have to also stop that or re-write the page (again) once the onchange is called because it will undo your (custom code) users selection.

                The next thing is look at the console, look at the returns from BC's server for the "AJAX" calls and see if you are doing what you need to do.

                • 5. Re: Free Shipping by Postcode?
                  jsbalmer Community Member

                  @BCMan - now that's helpful, thank you.

                   

                  There's so much assumed knowledge in this broader community - case in point, I did not know that the shipping options can change the order in which they display, hence invalidating index. I always assumed the order was determined by something server-side, and static. I get that the developers here will know this, but for people like myself (and let's be honest, a substantial part of BCs marketing is aimed at people like me, with some *modest* coding skills but not at professional level), this sort of stuff is like mana.

                   

                  Would I be correct in thinking that I need to add a hash check to the url to prevent updating?

                   

                  And I will say once more, I do not want anyone to write code for me That's not how you learn, or at least, not how I learn.

                   

                  Cheers, and will post back with success or a gif of a PC sailing through a window...

                  • 6. Re: Free Shipping by Postcode?
                    TheBCMan Community Member

                    With any system you have to assume if you are doing something unsupported or messing with the BC server side calls directly (BC has the right to change this), but with that said Liam (from the site) has publicly said BC wont change them. So I've developed versions that are very light in terms of not trying to rock the boat too much with changing the page (in case BC changes) and other versions that I re-wrote all the BC Javascript and made the AJAX calls myself to BC server side, I also have an API version that can do any custom shipping amount dynamically (as BC supports this in the API).... so with that all said, it is all possible.

                     

                    Regarding your question, take a look at the BC javascript, it does the AJAX call then injects the server response (assuming no error) into the container DIV, just trap that (stop it from doing it) or allow it too do it, but write a DOM attribute in the body tag or drop a cookie or hash tag in URL or some way you can detect that the post code has already been selected and that you need to put it back in, your javascript will not re-execute when the DIV update (because it's not a page reload). So make sure you can detect when the DIV was updated so you can fire off your code to update the display. Also all the discount codes, remove item and update item will also refresh the DIV so you'll also have to trap them depending on your implementation.

                     

                    You will also have to make sure people don't enter in a free post code then change it too a non free post code and then checkout with zero shipping.

                    • 7. Re: Free Shipping by Postcode?
                      Liam Dilley CommunityMVP

                      All change with the new rendering engine of course though

                      • 8. Re: Free Shipping by Postcode?
                        jsbalmer Community Member

                        @BCMan - Perfect, thank you Hadn't even considered the problem of people hustling the postcodes to get free delivery, so thank you again for that one.

                         

                        @Liam - Yes, I'd forgotten that... another learning curve, sigh (but seriously, Liquid looks great).

                         

                        Cheers to you both.

                        • 9. Re: Free Shipping by Postcode?
                          TheBCMan Community Member

                          @JSbalmer: No problems.

                           

                          @Liam: I'm assuming that the new render engine wont be forced on all existing sites the day it's launched as it would most likely break thousands of sites.

                          • 10. Re: Free Shipping by Postcode?
                            Liam Dilley CommunityMVP

                            It is an update to the system, Liquid is not the same version as it was before. Its been done from scratch and All existing system features will work. The new rendering engine is when you use it. So liquid will run when you use it.

                            • 11. Re: Free Shipping by Postcode?
                              TheBCMan Community Member

                              Liam: Functions to what level? Javascript functions? Does it straight replace existing "code functions" or are the AJAX server side calls changed as well?

                              • 12. Re: Free Shipping by Postcode?
                                Liam Dilley CommunityMVP

                                They have not announced any javascript changes. You have json data for everything and direct object access to data through liquid.

                                • 13. Re: Free Shipping by Postcode?
                                  TheBCMan Community Member

                                  Cool just as I thought, thanks for the info, I'm buying the coffee when I visit your office next