Archive for the ‘Coding’ Category

git error setting certificate verify locations

Friday, March 11th, 2011

I came across this error having setup a windows vista machine to clone a github repo using msysgit:

error: error setting certificate verify locations:
  CAfile: /bin/curl-ca-bundle.crt
  CApath: none

It turns out it’s just a problem with the path, all you need to do is reset this info and it should be alright:

git config --system http.sslcainfo /bin/curl-ca-bundle.crt

If you run got config -l you can check the git configuration to see exactly what all the settings are.

Share

Magento – product zoom for tall thin images

Wednesday, December 15th, 2010

Current version : 1.4.2.0

While reworking a 1.3.2.3 magento template to work for magento 1.4, I had an issue on a product page where a tall thin image was not being resized correctly by the product zoom javascript. The script seemed to think that the image was small enough to fit inside the image container and so the image was not shrunk and the zoom in bar was disabled, despite the fact that around a third of the image was hidden behind the zoom bar itself.

Digging into it, it turns out that the width of an image is the main dimension used to calculate if the image is oversized or not. But as my image was tall and thin it was the hieght causing the problem and not the width.

I fixed this by simply amending the javascript in /js/varien/product.js.

In the scale function, which is around line 128, change the line that calculates the variable ‘oversize’ from this:

var overSize = (this.imageDim.width > this.containerDim.width && this.imageDim.height > this.containerDim.height);

to this:

var overSize = (this.imageDim.width > this.containerDim.width || this.imageDim.height > this.containerDim.height);

This makes sure that an image is marked as oversize if either the width or hieght exceed the container size, rather than both. Then in the if statement below, amend the first if from this:

if (this.imageDim.width > this.containerDim.width) {
     this.imageEl.style.width = (this.imageZoom*this.containerDim.width)+'px';
}

to this:

if (this.imageDim.width > this.containerDim.width) {
     this.imageEl.style.width = (this.imageZoom*this.containerDim.width)+'px';
} else if (this.imageDim.height > this.containerDim.height) {
     this.imageEl.style.height = (this.imageZoom*this.containerDim.height)+'px';
}

This then resizes the image based on the height of the image if the width is not the reason for the oversize.

Share

Magento payment broken continue button

Friday, October 15th, 2010

Current magento version: 1.4.1.1

We recently upgraded a magento site to version 1.4.1.1 as part of moving the site to a new server. Everything seemed to run smoothly with no issues, job done.

However it didn’t take long for  the customer to ring up – ‘My site’s broken, no one can make payments anymore’. Once customer had entered their credit card details they found that the continue button did not work at all, they were stuck on the payment screen. Uh oh, time to dig around checking the server setups, looking for any reported issues with authorize.net (the payment engine being used) and checking into the changes made in the magento upgrade.

Amazingly the problem turned out to be that in latest version of magento, they had included a new javascript file for validating the payment variables input by the user and without this file the payment process would just stop at the card input screen and refuse to go any further.

The solution is simple. Just add the following line of code to your themes page.xml (in the layouts folder) and all should be fine:

<action method="addJs"><script>lib/ccard.js</script></action>

Everything would have been fine if we’d been using the default theme, or if we hadn’t had to override the default page.xml with our own version for our theme.

It just makes me wonder if there was some way that developers could be notified when key changes are made to files, especially to theme files that are overwritten in most installs to avoid such head scratching and long periods of debugging in the future. As far as I can tell this wasn’t even mentioned in the release notes. Do let me know if I’m wrong though and varien do actually release such useful information!

Share

jQuery slideToggle and ie7

Monday, July 26th, 2010

I had an interesting issue where in ie7, the element that I was displaying using the jQuery slideToggle function, would seem to jump out of place once the animation had finished.

As I was displaying a list, I first assumed that in ie7 the element was adding in the default list margins and ignoring my css. However no amount of fiddling with adding css margins in the slideToggle callback function seemed to sort the problem.

Googling allowed me to find a solution here that worked, although I have no idea why it works.

Basically I needed to add a min-height of 0px on the parent element, and set the height of the ul that I was trying to display to 100%.

Problem sorted!

Share

Magento Products Inc Tax Issue

Friday, July 2nd, 2010

I’ve recently been working on quite a complex magento setup, that involves a number of different stores based in different countries.

A problem was reported where some stores appeared to be adding the tax twice in the shopping cart. The product prices had been setup including tax but the tax was then being added again in the cart, despite the tax settings in the admin clearly stating that the product prices already included tax and the cart subtotal should display excluding tax.

So for a moment I panicked thinking that this was going to be some overly complicated bug that I’d need to fix (not what I needed on a Friday).

So in a desperate effort to avoid that I looked around and fiddled with as many settings as I could think of, hoping that one of these would solve the problem, meaning that there was no horrible bug but just some obscure settings conflict. This was a good plan!

Although the tax calculation settings seemed to be correct, the ‘Default tax destination calculation’ was still set to the default country ‘USA’ so I changed this to the correct country for that particular store. I also changed the shipping origin under ‘Delivery settings’ to be the country rather than the default of ‘USA’ and this is what actually solved the problem.

I know this seems like a really simple thing, but hopefully it’ll save someone else a lot of searching around. I also thought I’d better post this incase I come across this problem again and can’t remember what I did to fix it last time! A blog can be a very useful memory tool!

Share

PHP Rounding Issue

Friday, June 25th, 2010

So today I came across a wierd rounding issue in PHP, where the round function was just not returning the result that I was expecting. It seemed to be rounding the value down rather than up.

Passing a float value of 14.875 (generated by a multiplier calculation) I was expecting the result 14.88 but was actually recieving 14.87. Reading around I know that there are a few issues and difficulties when it comes to dealing with float numbers, precision and rounding, though later versions of php may well handle these slightly better (on this project I’m using php 5.2.6, running on Ubuntu 4.6).

The easiest way that I found to get around the problem was to turn the number that I sent into round into a string, simply by concatenating an empty string on the end, eg round($value.”). I think that this then makes the value a simple string of 14.875 that can be easily rounded rather than a float that is susceptible to the nuances of precision rounding, though I’m really not an expert and simply speculating here.

This also may not be the best or most elegant way to sort this problem but it worked for me.

If you know of a better way to get around this then do please let me know, I’d be really interested to hear how other people have got around this issue.

Share

Coding standards

Thursday, November 26th, 2009

First off let me apologise if this turns into a little bit of a rant from me but this is a pet topic of mine so I could be liable to  go off on one. I’ve also just been working on a project that has had me running into the corner of the room screaming because of the standard of the code (luckily my colleagues are used to my slight idiosyncrasies).

Coding standards are not a new thing by any means, and in my view are really essential to any organisation. They help to promote consistency and ensure that anyone working on a project knows how they should layout and structure their code. This way it becomes much easier to read (especially at first glance), new developers have a handy reference detailing what they should be doing and everyone is generally on the same page with how things should be done.

PHP_codesniffer

Pear LogoTo make life even easier there are applications around like PHP_CodeSniffer that can automatically check that your code confirms to the set coding standards so you don’t have to worry about remembering every single point in the standards. I’m not going to write much about this in detail as there are already some very good references out there such as this one on techportal by lornajane. The documentation on the PEAR site is also very good and shows you how to create your own sniffs, and there are also plugins out that link into some of the most widely used IDE’s, such as this one for eclipse.
(more…)

Share

Magento – changing the root folder after install

Tuesday, September 22nd, 2009

Current magento version – 1.3.2.4

I’m guessing that quite a few people will have done what I did when I initially set up Magento, which was to just move the magento folder into my required document root and then go in and run the installer.
Logically all the files then got installed into that magento folder resulting in all my urls having “/magento/” in them which wasn’t exactly ideal. Of course this fact only registered with me once I’d done quite a bit of work, so the idea of doing a fresh install to sort this out was extremely unappealing to me.

Luckily for me it is possible to change the magento root from “/magento/” to “/”, but as you might imagine this sort of thing is fraught with danger (if that’s not too dramatic).

So I will stress here that it’s best to setup your root folders correctly on install, or run a fresh install if you can. But if you really need to change the root after the event then here’s what you have to do: (more…)

Share

Magento – using jQuery

Wednesday, September 9th, 2009

Current magento version – 1.3.2.4

Jquery logo

jQuery is my favoured javascript library. It is the one I use most so it’s familiar and I can develop quickly with it. Magento however relies heavily on a mix of prototype, scriptalicious and their own varien scripts, none of which I’m familiar with or feel particularly confident about extending and adapting to my own needs.

So when I needed to add some custom javascript functionality to my magento site, I immediately thought “Wouldn’t it be great if I could use jQuery”. Now obviously this raises some issues. Firstly you’ll be adding in another javascript library to the mix, so the first thing to decide is “is this really necessary?”. You don’t want to add a whole load of extra code just for a really small bit of functionality as that doesn’t justify the performance hit or the extra bulk (if I can call it that). It is also well known that jQuery and prototype don’t really get on, so you’ll need to make sure that you can get them to play nicely together.

If you decide that it is worth it and you can justify adding the extra library, then here is what you need to do: (more…)

Share

Magento – add custom layout template

Tuesday, August 18th, 2009

Current magento version – 1.3.2.4

This is what you need to do to add a new layout template, eg 4 column page layout.

  1. Copy app/code/core/Mage/Page/etc/config.xml
    to app/code/local/Mage/Page/etc/config.xml.
    Creating this new file will allow magento core updates to occure without over-writing your changes (you’ll probably have to look out for changes to the core config.xml to megre them into your custom file).
  2. Register your custom module by adding a new file to app/etc/modules, called something like Mage_Local.xml
  3. In this file add the following code:
    <?xml version="1.0"?>
    <config>
    <modules>
    <Mage_Page> //relates to file structure
    <active>true</active> //set to active
    <codePool>local</codePool> //tell which folder to look in
    <depends> //requires the mage core
    <Mage_Core/>
    </depends>
    </Mage_Page>
    </modules>
    </config>
  4. Now create your new template file, easy way is to copy an existing one such as 3columns.phtml (in app/design/frontend/your_package/your_theme/template/page), and give it a name, such as 4columns.phtml
  5. Register this new template in the config.xml file your created in step 1 by adding your module to the layouts list. For my 4 column example I have added:
    <four_columns module="page" translate="label">
    <label>4 columns</label>
    <template>page/4columns.phtml</template>
    <layout_handle>page_four_columns</layout_handle>
    </four_columns>

You should now be able to access this new template in the cms->manage pages option in the magento admin backend.

Share