Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gordon Saxby 1449 posts 1870 karma points
    Jan 26, 2014 @ 21:55
    Gordon Saxby
    0

    Countries and Regions

    As seems usual, I need to do something out of the ordinary with Tea Commerce!

    My client ships around the world but basically has 3 areas in terms of shipping cost - UK, Europe and Rest of World.

    I thought I would / could setup those areas as "countries" and then add the actual countries within each region as nodes below. I can and have done that, however, it doesn't really work how I need it to!

    I need to be able to set the shipping cost at the "region" level - i.e. UK, Europe and Rest of World. I can't expect the customer to edit the shipping cost for every single country when there are only ever 3 different values.

    On the checkout pages, we do not want the purchaser to have to select their region and then select their country ... I want them to just select their country.

    The problem comes when we get to the shipping page - if I don't have the TC Country (or region in this case) dropdown on the information page, the shipping page does not select the correct shipping options. I tried adding code to set the "Country" based on the "Region" selected on the info page ... that works the first time, but if you refresh the page it seems to lose the settings!?

    The documentation doesn't really explain how all this works and what happens ... so I'm getting nowhere again!

    Is it possible to structure TC as described above, and is it possible to only list countries (Regions in TC-speak) to the purchaser?

    I commented out the following in the "information" page script

    <input name="SetCurrentPaymentCountry" type="hidden" value="countryId : paymentCountry" />

    I then replaced the "country" dropdown with the "countryRegion" dropdown.

    In "step-shipping-payment.cshtml" I added code to get the current "region" and set the country based on it

    CountryRegion payCountryRegion = TC.GetCurrentPaymentCountryRegion(storeId);
    CountryRegion shipCountryRegion = TC.GetCurrentShippingCountryRegion(storeId);
    Country country;
    if (shipCountryRegion != null) 
    {
      country = TC.SetCurrentShippingCountry(storeId, shipCountryRegion.CountryId);
    }
      else
    {
     country = TC.SetCurrentPaymentCountry(storeId, payCountryRegion.CountryId);
    }
    (I think the above kind of worked, but not completely!?)
    Am I going about this the completely wrong way? Am I anywhere near close? Why can't I get simple projects?!
  • Anders Burla 2560 posts 8256 karma points
    Jan 27, 2014 @ 13:40
    Anders Burla
    0

    Hi Gordon

    Nice case you got here. You can use countries and regions as you please in Tea Commerce. Only thing to note is that the payment country is used to know which payment methods are available and shipping does the same. If no shipping country is specified - it will fallback and use the payment country to find the available shipping methods and also to calculate the price.

    In your special case you get the country from the selected country region on the order which is ligal. Not you just need to set the country based on the country region that is selected. If you want to do that using the HTML API you need to change how it finds the countryId - this should properly be from a hidden field that you update using Javascript based on the region that is selected.

    The way I would test it, is to first check that my SET code works. Check the DB what value is there. Then I would test my GET code and see if I get the right values from the order and the right ones are used in the SET when I already have set the value ones.

    Kind regards
    Anders

  • Gordon Saxby 1449 posts 1870 karma points
    Jan 27, 2014 @ 14:33
    Gordon Saxby
    0

    Hi Anders,

    talking in terms used in TC - I have created "Countries" of UK, Europe and Rest of World. Then I have created "Regions" underneath each (e.g. UK -> UK, Europe -> Italy, etc).

    The client does not want the "Countries" dropdown on the checkout page, only the full list of "Regions" (i.e. countries!!). So, ideally, I would like to set the "Country" to the parent of the "selected "Region" when I get to the Payment page. That is what I was trying to do in my code, above!? It kind of worked the first time in, but if I refreshed the page, the GetCurrentPaymentCountryRegion function (I think) failed to return anything.

    On the Information page, there are a number of hidden fields - are they used to instruct TC what to do / save?

    What happens if I just set / pass the "Region" to the "Base" and onto the Payment page, will the Country be set accordingly, i.e. to the Country that is the parent of the selected Region?

    I am happy to write .Net in order to override the basic functionality, I already have a function that gets the shipping methods and excludes some for specific reasons. However, I need to understand how Countries and Regions work and how the interact, if at all.

    Should I be specifically dealing with the current order when setting Country & Region, or the "session" instead?

  • Anders Burla 2560 posts 8256 karma points
    Jan 27, 2014 @ 14:56
    Anders Burla
    0

    You should use TC (the razor api) to change things in the order. That uses the session and takes all those things into account. You need to change the country and then the country region. You can't change the country region to one that is not in the country that is currently selected for the order. So use TC to change the country and then the region.

    You can post your HTML for to a /base method and then change the country and region in the .NET code there and then redirect the client to the next step of the cart flow.

    The hidden fields is properly for the HTML API which is a bit to basic for your needs. But you can read a bit more about it here:
    http://documentation.teacommerce.net/html-api/

  • Gordon Saxby 1449 posts 1870 karma points
    Jan 27, 2014 @ 15:49
    Gordon Saxby
    0

    You can post your HTML for to a /base method and then change the country and region in the .NET code there and then redirect the client to the next step of the cart flow.

    That sounds just like what I need to do!! Could you give a clue as to how I catch / process the form submission in "/base" ;-)

  • Anders Burla 2560 posts 8256 karma points
    Jan 27, 2014 @ 15:52
    Anders Burla
    0

    Just find the HTML form in the razor script that generates the step you want to change. Now change the /base/TC url to your own URL. Now TC wont run its magic so you have to do all the update of address information etc for your self. You can also go ahead and use the Javascript API to change things and then let the HTML API update the address info etc. Then just remove the SetCurrentPaymentCountry and SetCurrentPaymentCountryRegion and also shipping in the HTML API method parameters.

    Kind regards
    Anders

  • Gordon Saxby 1449 posts 1870 karma points
    Jan 27, 2014 @ 15:59
    Gordon Saxby
    0

    Ah, OK - I was thinking that there was an event that I could "attach" to and override. That's fine, I will write my own "base" code to handle this particular step.

  • Gordon Saxby 1449 posts 1870 karma points
    Feb 03, 2014 @ 10:30
    Gordon Saxby
    0

    Unfortunately, I was not able to use Countries and Regions in the way I wanted to - because SagePay insisted on having the State (CountryRegion in TC) for US addresses. Therefore, I have had to give up on organising countries by regions and just list them all at one level, so that I could add the US States.

    That does make it very time-consuming to configure shipping options, as I now have to do it for every country in the world! Maybe this is something you could consider for a future upgrade!?

  • Anders Burla 2560 posts 8256 karma points
    Feb 04, 2014 @ 15:27
    Anders Burla
    0

    Hi Gordon

    Thanks for the advice and that you got you case "solved".

    Kind regards
    Anders

Please Sign in or register to post replies

Write your reply to:

Draft