Posted on

shuffle() or: How I Learned to Stop Worrying and Love PHP

I have said some not very nice things about PHP on this blog, and I’m sure over time I’ll be adding more such criticisms. This time I’d like to highlight a handy little feature in PHP, one that is a great deal easier to use than it’s Java counterpart.

Shuffling the elements in an array is probably a programming exercise in every single 1st year computer science textbook, it’s easy enough to do, but because it’s been done roughly 100 million times before, it feels moronic doing it again. So it’s nice when programming languages offer it as standard language functionality. PHP does by way of the shuffle() function and Java does by Collections.shuffle() static method. Seems simple enough, except that an array is not a collection in Java. So you can’t take your int[] and shuffle the elements quite so easily.

If you have an Integer[] in Java you can just pass it into Arrays.asList(array), get the collection and shuffle it. Uh oh, I said Integer[] which sadly is not the same as an int[]! So the difference between the two means I’m going to need to convert all the elements of the int[] into a Integer[] before I can shuffle it, geez, if I have to iterate the list once to convert type, I may as well just not put them back where I found them!

So this is me admitting there is an advantage to a dynamic language. I maintain I’d still rather pay the upfront cost of a few extra lines of code here-and-there for type safety, try getting a PHP IDE to reliably autocomplete instance methods for you, when it doesn’t know the type of a variable! Perhaps I need to start using Eiffel

Posted on

Google Checkout disabled – Not available with these items

I was recently asked for help on a Google Checkout problem where the Google Checkout Button on the Magento cart page was disabled with a message saying: “Not available with these items“.

I had a look at the Magento store in question and found a few clues to go on but a
Google search on the subject proved to be of little help unfortunately. The button looks like the one shown in the screenshot below:

The disabled Google Checkout button on the Magento cart/checkout screen. It looks like the normal one only greyed out.
The disabled Google Checkout button on the Magento cart/checkout screen. It looks like the normal one only greyed out.

The underlying URL for the button is:

 <img src="https://checkout.google.com/buttons/checkout.gif?merchant_id=5677186919&amp;w=180&amp;h=46&amp;style=white&amp;variant=disabled&amp;loc=en_US" alt="Fast checkout through Google" />

The big clue was the parameter on the Google Checkout button image URL on the problem store. It had variant=disabled which is generated server side, and so had to be coming from somewhere within Magento. A big fat grep over the code uncovered a variant=' string fragment in Link.php.

Continue reading Google Checkout disabled – Not available with these items

Posted on

How to install MAMP on your Leopard Mac

I’m writing a full series on setting up your Mac for Magnto ecommerce development, I should probably start with the first step – installing MAMP on a Leopard Mac, even if it’s a quite basic and hopefully self evident.

Maybe one of the less obvious things is that you do not need MAMP pro to get virtual hosting set up in Apache on a Mac, but it will require you to work with Apache config files as described in my post on setting up virtual hosts in apache on MAMP.

Continue reading How to install MAMP on your Leopard Mac

Posted on

3 Quick Methods To Diagnose Communication Problems between Magento and Google Checkout

There is a lot going on when Magento actually sends a cart to Google Checkout, even more so if you are using Merchant calculated shipping. As a result lots of things can go wrong, with the merchant calculated shipping callback or with the actual server to server posting of the cart contents.

To help you with diagnosing problems I thought I’d shared my top 3 methods for finding out what is going wrong when Magento and Google Checkout are not communicating properly.

1) The Intergration Console

The first and most obvious place to try is the Google Checkout Intergration Console. As you can see in the screenshot below the console is hidden away in the Tools tab of the main seller dashboard. You’ll find it at the bottom of the left menu.

The Intergration Console is tucked away in the tools tab at the bottom of the left menu.
The Intergration Console is tucked away in the tools tab at the bottom of the left menu.

If the Google callbacks have failed or incorrect XML has been sent to Google you will find a report of the errors here. It is a good idea to keep an eye on the timestamps as you do not want to wind up chasing an old problem. It’s also good to periodically check this console while in production, just in case something starts to go wrong. I found when I upgraded to the latest Magento that the HTTPS callback was failing, but I hadn’t found it during development because I do not use SSL in development environments.

Continue reading 3 Quick Methods To Diagnose Communication Problems between Magento and Google Checkout

Posted on

Magento 1.2.0.1 Full Text Search fails after upgrading from earlier versions

Just one more quick note on the Magento upgrade to 1.2.0.1. The new full text search functionality uses an index that does not get built when you upgrade. You will need to manually rebuild it in the UI to get your store search working.

To do the rebuild you access the Cache Management page (System > Cache Management). You will see a new button at the bottom labeled ‘Rebuild’ – press it and depending on how many products you have the index will rebuild in a few seconds or minutes.

Once rebuilt it works well, enjoy!