Your basket is currently empty!
Author: Flamekebab
-
Figuring out how to use the JigoShop API
When someone orders stuff from Fox Box I get a notification email with the details. It’s functional but ugly. More to the point it’s not formatted for label paper of any kind. Something like this:
You have received an order from Ben Fox. Their order is as follows:
=====================================================================
Fox Box
admin@fox-box.co.uk
ORDER #: 2588 Date: September 16, 2012
=====================================================================
1 x Ork Warbike 2 (#912) - £2.50The original invoice generator I wrote was both impressive and hacky. It would query the MySQL database, find the relevant order information, decode it, and spit it out onto a template. There may well have been a better way of getting information out of a WordPress database but that was a can of worms I was not going to open.
Unfortunately by doing things this way I was locked in. As soon as the order information format changed the script broke. Annoying but to be expected, really.
It was one of many reasons I held off upgrading to JigoShop 2.x. Luckily I held off long enough that JigoShop 2.1 was released and it included an API. An API is essentially a convenient way of talking to a program. Instead of dealing with the internal workings it offers a load of convenient ways to get information in and out of the program.
The main problem I ran into with all this is the fact that, like many other things, the documentation explaining how to use it was written for people that already know how to use an API. I don’t expect it to explain the basics entirely but a simple “Don’t know what this means? Head over to [SITE] and take a look at their API tutorial.” would have helped a great deal.
The first major problem was this: where is the API?
The documentation talks about https://jigoshop.dev/api/v1/orders/:id
Initially I thought this meant that my JigoShop instance would contact their servers to act as a middleman. Nope.
There’s nothing in my files at https://fox-box.co.uk/api/v1/orders/:2588 either – it just throws a 404 error. I did find https://fox-box.co.uk/wp-content/plugins/jigoshop-ecommerce/src/Jigoshop/Api.php/v1/ but that seemed to be a dead-end too.I posted a topic about this over on the support forum but didn’t get an answer so eventually I emailed them to ask. It turns out that it is at https://fox-box.co.uk/api/v1/ but other bits of syntax were wrong. That colon? Yeah, that’s not supposed to be there. Not a clue why it is, convention I imagine.
If you try visiting https://fox-box.co.uk/api/v1/orders/2588 you’ll get a blank page, not a 404. That means it’s working – but you don’t have authorisation to view the page. Further proof that it’s working can be found here: https://fox-box.co.uk/api/v1/ping
{"success":true,"time":1494332877}
That’s what we’re after! JSON encoded data! Nearly everything can easily process JSON and it’s quite easy to read without being a computer too. It’s just a load of “Variable name”: value – e.g. “name”: “Fox Box Frankenork”. So now it’s just a matter of how the bloody hell authorisation works.
To people who know about APIs this is probably very easy stuff but for me it was a matter of trying to figure out how complex the problem is. APIs are usually aimed at developers and so the idea might have been that I was expected to code up something complicated that exchanged keys or did a special handshake or something.
The documentation was… unhelpful. On my end I had a username, password, and “secret key”. The documentation told me I was supposed to pass a header with “Authorization: Bearer [token]” and then sort of wandered off to have a smoke or something.
After trying various things I eventually figured out that by sending over the username and password it would send back a temporary token. I’d then use that token in future requests. Eventually it expires and a new one is needed.
So I’d send:
curl https://fox-box.co.uk/api/v1/token -X POST -u user:password
The server would send back:
{"success":true,"token":"[censored]"}
Then I’d use that token to ask it for details about order 2588.
curl https://fox-box.co.uk/api/v1/orders/2588 -X GET -H "Authorization: Bearer [censored]"
Lo and behold I’d get this lot back!
Then it was just a matter of figuring out how PHP talks to cURL (a little bit fiddly but not too bad) and sticking the relevant bits of info into the right places on the old form.
So the old code might say:
echo $order_details_unserialized['shipping_address_1'];
The new way of storing order information doesn’t have address_1 and address_2, just address so the new code just says:
echo $shipping_details['address'];
Admittedly I also took the time to write a bit of extra code that would format addresses more appropriately for some countries. Lots of places use what I think of as the “European” style of address (Postcode – City rather than a separate line for the postcode) so the new system should result in better labels too now that it takes those into account. Similarly the US has state initials before their zip codes.
I’d show you the result but seeing as examples contain personal details there’s not much left after I’ve censored them!
Right, back to pouring resin into hollow blocks of silicone.
-
Timely references and CSS
I’m not sure if I can face another perplexing error with the site. I’ve spent at least the last week or so attempting to upgrade the website.
We run JigoShop as our ecommerce software and it in turn runs on top of WordPress. It’s far from the best solution but when we setup back in 2011 the other options we tried were worse. So for years we ran the 1.x series of JigoShop. There were tweaks and upgrades along the way but mostly it sort of haphazardly wobbled along.
Some time in 2016 they released JigoShop 2.0. Unless there’s a serious problem I rarely upgrade software until it’s had time to get itself sorted. Bugs and other broken stuff are common. There’s nothing like exposing software to the general public for finding bugs!
Anyway, a while ago I received an email telling me that JigoShop 1.x was being retired at the end of March 2017. There’d be no more support for it. Given that I’d had a few problems over the years it seemed like I’d best make plans to upgrade to the 2.x branch before some show-stopping problem forced the upgrade on me at an inopportune time.
So…
Well getting PHP upgraded was tricky. Well, the upgrade was easy – finding out what broke and why less so!
One of the major problems that I only found mentioned in an obscure AskUbuntu comment was that it disabled short PHP tags by default. Simple explanation of what that means: there’s two ways to indicate that a text file contains PHP code:
Long tags Short tags <?php code here ?>
<? code here ?>
Yeah, by default PHP 7.1 was set to only read code with the long tags. As a result loads of random stuff broke. I’m mostly mentioning it here in case it pops up as a search result for someone else and helps them!
Anyway, eventually I got all the requirements sorted and it was migration time! JigoShop migrated all the 1.x data over to the 2.x software without error (impressive considering the hundreds of products in the database). Excellent stuff.
Then came the problems…
The first major one was the lack of an off switch.
That is to say that in the 1.x branch of JigoShop there was a simple button in the admin panel to turn off their theme. Yeah, that was gone. Someone else had the same problem but the answer provided wasn’t helpful so I stuck my obnoxious oar in and eventually got enough of a clue out of the JigoShop support staff to figure out the solution.
So their theme was turned off. Amazing! Except it’s 1999 up in here:
That is to say they changed something making my theme no longer work. Themes use CSS to make pages look a certain way, that an a load of images, icons, and stuff like that. Well CSS code is generally written to apply to a certain thing on a page. There might be some stuff for the overall page but say a button used to have the identifier “button” and now its identifier is “btn”. You see where I’m going with this?
So the last few days have been spent trying to find out what’s changed, what hasn’t changed, and trying to make things actually work again. It turns out that JigoShop has its own CSS but it also has CSS for some other stuff that it loads in – like the shipping calculator. That was so unbelievably broken until I figured that out…
Those kinds of problems are within my ability although I had to learn a fair bit about CSS to get it done. Aside from being exhausting it was kind of fun. Also, importantly, I don’t touch the code of JigoShop – as soon as I start messing with that there’s no guarantee of the changes being permanent – an upgrade could overwrite the file and things would break again.
The other kind of problems are settings in JigoShop that straight-up don’t work. Things that you’d think they’d have caught in 6+ months!
For example:
Only one of those items is in stock. Attempting to click the “Add to cart” button on the first two just pops up an out of stock notice.
Great, thanks. I’m sure customers won’t find that bloody maddening. I’m not just having a moan – I filed a bug about it as soon as I found out. There’s some other corkers out there too although the one that really took the biscuit was the one I’m about to bore you with.
I have a paid for extension to JigoShop called “Premium Shipping”. It lets me set weight ranges and destination countries to work out my shipping rates. Weirdly the cart on here says shipping is “estimated”. It’s not. What you see is what you’ll pay. Doing it any other way would be bloody stupid.
Anyway, we’re talking about models here, not gym weights. I can’t set things to grams but I could at least use decimals. Could.
Yeah, the 2.x branch of JigoShop only deals in whole kilos. They’ve since helped me fix that one but come on, how did no one fix that in the months that the 2.x branch has been out?
That’s quite enough of that. Time for the good bits!
The new software branch performs noticeably better. I was concerned I’d need to upgrade my server or something but not, the new code is fast and makes using the site much nicer. It wasn’t terrible before but it wasn’t something I was proud of either.
Other good stuff – by getting my hands dirty with CSS I’ve changed a whole load of small things that in general make the site feel more polished. I feel far better equipped to deal with future challenges as a result. Even back when I was making web pages from scratch as a spotty teenager I didn’t understand CSS as well as I do now.
So, this is basically a “soft” launch for our JigoShop 2.x install. Maybe later in the week I’ll be able to release some products and bang the drum a bit.
If you’ve got any problems with the site please, please, please let me know! We’re on Twitter, you can message us on Facebook, and of course there’s the contact form that emails me directly.
-
Sale time! (11th – 18th April 2017)
We don’t go on many holidays and they’re rarely anywhere glamorous. This time we’re heading to Wales to visit my parents. I know, that Instagram life I lead. Anyway, my folks always ask how things are going with the business and it’d be nice to be able to have a good moan about all the work I’m going to need to do when we get back!
So to encourage that sort of thing we’re doing a sale on our stuff. As always that means things we make – Fox Box stuff. Not the plastic bitz, not TakUnderhand’s beautiful laser-cut acrylics, not the odds and ends in the Mek’z Speshul category. Just our stuff! That’s quite a lot of products these days, I’m proud to say.
As the graphic below says the code to put in at checkout is “eggthingy2017”. Mmmm eggs…
We run JigoShop as our ecommerce solution and have done since it was a fairly new bit of software. A little while back, a few months, something like that, they finally hit version 2.0. I don’t make a habit of upgrading production software until it’s been out a while just in case there’s some show-stopping bugs that haven’t been found yet.
So when we get back from our holiday I’ll be tinkering with the software and doing my best to make sure everything is running smoothly. This could take a few hours, or it could take days. I have no idea – that’s one of the reasons I’ve been putting off doing it!
I’ll also be revising our postage costs slightly as it’s now a new financial year and that means the Royal Mail have once again raised their prices. One more reason to get orders in before the sale ends!
Now if only I could convince someone to buy me a chocolate egg. It’s been bloody years!
-
Not many miscasts now, I’m afraid.
I love these things:
They’re great. Growing up I had tiny jerrycans that came with the old GW Ork Wartrukk model but they were puny even by the standards of the day. I’d dig one out and photograph it but just trust me – they were tiny. 28mm Heroic isn’t really a scale though so it’s difficult to get sizes right. Things like barrels are especially tricky given the bases the models stand on. We usually just fudge it and these jerry cans are no exception – they’d come up to chest height if that Ork was human!
I’m really pleased with them but it has taken quite a while to bring them to market due to my own incompetence. Sometimes I finish masters for something and just can’t get them to cast right. It’s rarely a problem with the masters themselves – normally it’s how I’ve laid out the mould. I experiment fairly often when making new ones though and I’m always learning. Well, apart from when I’m not.
This mould still needs a bit of work: got some air bubbles in our jerrycans… Quick, next order gets free miscasts! pic.twitter.com/PpVV3xcCFr
— Fox Box (@FoxBoxBitz) September 24, 2015
Anyway, these seem to be casting happily now so that means I can soon fill my own builds up with cans. Next stop – kegs!
Oh and you can buy the jerrycans here:
-
Riot Shield Retrospective?
I should probably start doing blog posts every time we release a product, now I come to think about it. Maybe they’ll cover what’s new about the new thing, or something. Hmm. Well let’s give it a go and see where it takes us!
So, most recent release, erm, yep, these things:
They’re the 3.0 iteration of our Orc Riot Shields. They’re improved in many ways but there’s still a fair bit of the originals from late 2012 in there. Has it really been that long?
Since then they’ve hit 2.0 which saw the introduction of bludgeon arms to go with them (a pipe, a club with nails in it, and a barbed wire cudgel thingy). This latest version bumps it up to five designs of each. One of the shields uses an old phone card as part of its master. Back when I was getting into wargaming in ’98 plasticard (styrene sheeting) was damn near impossible to find near me. I’d just been sent off to boarding school and my boarding house had a pay phone that used these cards. I’d collect all I could find and use them to convert my Gorkamorka vehicles. No need to any more, of course, but there’s a few odds and ends still kicking about that still date back that far. The guy that runs a bitz shop is a bit of a pack rat? Alert the media!
Also it’s the first time I’ve handled the photos this way. I’ve never managed to get ink to stick to raw resin so these are coated in the modern equivalent of Bleached Bone (I know, I’m old…) first. I’m fairly pleased with the result, frankly.
Bringing them up to five also makes it easier to equip units with them. I’m planning on using a couple of sets for my 40K Orks!