I need to import an entire e-shop made with osCommerce into OpenCart. So far, so good. I have successfully imported almost everything, except for SEO and some sparse data bits, but I have a problem with the address format.
osCommerce uses $firstname $lastname$cr$streets$cr$city, $postcode$cr$statecomma$country while OpenCart uses {company} {firstname} {lastname} {address_1} {address_2} {postcode} {city} {country}.
Maybe I’m wrong, but taking a look at the basic differences between those string sets, I thought a regex would be the appropiate tool to convert an osCommerce-formatted address format string into an OpenCart-formatted address format string.
I’m, however, completely null at regexes. Can anyone tell me which regex would fit best my needs? Or, in case it’s doable without regexes or they’re a bad idea, which method should I try with them?
2
Answers
I assume
cr
stands for a carriage return or a newline and there are literal dollar signs$
in the source string.For reordering you must capture the parts of the address and use them in the replacement string
and then replace it with
So this would become
But you can also use
explode
for splittingand then put the parts together again by reordering and inserting the braces.
OpenCart addresses are stored as separate fields for each of those pieces of data. The format for OC that you’ve given is merely for visual data like the address on an invoice. All data for that address however has it’s own field which you can see if you take a look at your
address
ororder
tables. It’s worth noting that addresses have ISO codes attached to them too so you will need to take that into consideration when importing to avoid issues. Assuming osCommerce stores the data in a similar fashion (I’ve not used it personally) then you would simply need to map the old columns to the new one. If they are however stored as a single piece of text and you need to extract it, you can use thisTested using this as an example address