Web Design and Build

Creating a mobile version of an Opencart shop – 4 Last updated:21 February 2012

Spent today mostly hacking the login/purchase forms to make them behave better, and removing the tables at the same time. Like this:

My account Login Customer form

Not sure about the styling on those radio buttons at the moment….

Creating a mobile version of an Opencart shop – 1 Last updated:20 February 2012

Yesterday I started playing around with creating a version of our Opencart store suitable for mobiles. Here’s how I got on.

I began by considering the use of css @media queries to apply a separate css to be used on mobiles, but quickly discarded this approach as there was just too much data to fit on the screen. I then switched to the current approach, which is to create a new store within Opencart, and use a different theme wherever possible to render pages differently. Opencart is fantastic in the way it supports this – in five minutes I had two separate stores, running on m.mytestdomain.com and mytestdomain.com, bot using the same data and admin suite. Further, Opencart allows the use of separate categories and products by store – so I can use categories with less products on the mobile store only to limit the amount of scrolling – one of our live categories has 59 products in it.

I’ve been trying, wherever possible, to restrict mobile-specific code to the theme itself, so as not to compromise maintainability. However, after some experimentation I decided that I wanted to display a full list of categories and products on the home page, but not at all on subsequent pages, and this required a change to catalog/controller/common/column_left.php so that I can identify whether the rendered page is the homepage or not. I used:

		$homepage = "/";
		$currentpage = $_SERVER['REQUEST_URI'];

		if($homepage==$currentpage) { 
		$this->data['home'] = true;
		} else {
		$this->data['home'] = false;
		}

and then some conditional code on column_left.tpl to display the category module only on the home page (and not display any other modules at all).

So far, I’ve done the home page and category pages. I’ve removed all the tables encountered so far, ripped out all the extraneous stuff, and simplified wherever possible. Here’s what the pages look like so far, some more styling needed (screenshots using http://www.iphonetester.com/).

Home page on an iPhone emulator Category page on an iPhone emulator

Quite an interesting and thought-provoking challenge to minimise the size of the pages. The home page is currently less than 20k and loads noticeably quicker than the main site home page, even over my broadband link.

Creating a mobile version of an Opencart shop – 2 Last updated:18 February 2012

Been fiddling about with the layout again today and having checked the site on another emulator I’ve decided I need to rework the category page to make the image smaller, otherwise I’m struggling with room again. It would be quite nice to have a product image that isn’t square, but it seems Opencart doesn’t like images that break the original aspect ratio. Fair enough. Although the revised image fits better it doesn’t look as nice I think. I can feel the temptation to use tables to layout the category grid – am trying to resist this.

Anyway, here’s the latest iteration, tried the Opera Mobile Emulator today:

Reworked category page

I’ve been examining the CostCo mobile site as that was well-rated on a site I was reading, but I spotted this afternoon that if you go down the navigation until you actually get to a product detail page, then it links to the main site, so you can’t actually buy anything direct from the mobile site. Seems odd.

To do list: I think the main menu (see previous post) could actually manage with links that are less deep, and I’m also thinking about reducing the header size to fit the “My Account” and “Basket links” alongside it, also think the input fields on that category page are too large.

page-break-after failing with position:absolute and floated elements Last updated:7 February 2012

In the last couple of days I’ve been working on a small application to print raffle ticket numbers, which requires a certain number of tickets to be printed per page. In a simple case I was able to generate four consecutive numbers per page and then enforce a page-break via page-break-after:always. So far so good.

I then floated some elements within the page, which caused the page break to fail in every browser I tried (including FF10 and Opera 11 – and if it doesn’t work in both of those, something’s wrong…). This persisted even with the floated elements enclosed in non-floated elements to which page-break-after was applied. Some Googling suggested floats don’t play nicely at all with page-break, so with gritted teeth I used tables instead, and all was well.

Later, I needed use absolute positioning for the ticket numbers. You can’t use absolute positioning directly within a td element, so I included a div nested within the td. This broke the page-break again. Fine without absolute positioning, broken with – tested in FF10. Amazingly this fails in FF10 but works in IE8 (and that’s not a phrase I’ve written often). Investigating this I added a border to the td element, just so I could see what was happening on the page, and all of a sudden everything was fine again. By experimentation, a single border on the td fixes the problem in FF10 – even if it’s transparent. Weird.

So, to summarise, with the following html structure:

<table>
<tr>
<td><div><p>Some text</p></div></td>
</tr>
</table>

and this css:

table{page-break-after:always}
div{position:relative}
p{position:absolute}

then Firefox 10 does not honour the page-breaks, but IE8 does. Making the css:

table{page-break-after:always;}
td{border-bottom:1px solid transparent}
div{position:relative}
p{position:absolute}

results in Firefox 10 printing correctly.

Heart Internet and CSS3PIE/PIE.htc Last updated:6 February 2012

Discovered this evening that a website I’d built a month or so ago using CSS3PIE for box-shadow and border-radius had lost both of these. I’d just made a couple of changes so at first I thought I’d messed something up, but after backing all the changes out only to find the problem was still there, and then discovering all was fine using xampp locally, it looks to me like Heart have changed something on their servers. I fixed the problem by using a php file which forces the PIE.htc file to be served as the correct content type – see the CSS3PIE pages for the details of this.

Just thought I’d post this in case anyone else is searching for the same issue.