So we have a project which has two different database connections. After having read on the web for a bit I didn’t run into the ideal solution to inserting into a table which was not in the default database. It turned out to be pretty simple though:

So we stumbled onto this problem with a new customer who was using a module called Techtwo_Mailplus. When trying to make a rest connection HHVM would cause the following exception to be thrown: Invalid chunk size “” unable to read chunked body. This did not happen with their old server which ran bog standard PHP DSO. Now, I was not looking forward to debugging it because it’s a complex module and the error eventually ended up in Zend_Rest_Client after tracing it through 4 other files and multiple functions in those files. However, I stumbled onto this post which gave me the solution: http://framework.zend.com/issues/browse/ZF-741

To fix the Techtwo_Mailplus module I edited app/code/community/Techtwo/Mailplus/Helper/Rest.php and around line 160 you will find:

This is the spot where you can add the fix from the Zend post. So just add it to the end of this part so it looks like this:

I don’t have time to figure out exactly why this happening but forcing HTTP version 1.0 seems to “walk a different path” in Zend Framework and doesn’t hit the part that causes the error.

During an import I managed to get the order wrong of the selectable attributes of some Magento Configurable products. So I had to change the sort order of the Magento configurable attributes. It took me a little while to figure out how to fix this but it as pretty easy actually. You can find the function below which will loop over all configurables and set a new position value if there are more than 1 attributes. It does not seem to matter if position is greater than the amount of attributes or if it skips a number.

I saw this error today while updating a shop to Magento 1.9.1.0 while trying to re-index from the commandline using the indexer.php, turns out it was as easy to solve as just flushing the cache. In our case a redis-cli flushall but always make sure Magento didn’t spontaniously create a var/cache dir or even a dir in /tmp/, it likes to do that if your config is not rock solid.

4449_CE191BlogGraphic_r1v1

Another version of Magento (1.9.1.0) was released and this one promises some welcome fixes!

As always here’s a download link off my VPS which should be faster than the official download location:
https://robotsystematic.com//magento/magento-1.9.1.0.tar.gz
md5sum: 79ca01aa9736a402e68ec34361222b96 magento-1.9.1.0.tar.gz

The full release notes can be found here:
http://www.magentocommerce.com/knowledge-base/entry/ce19-later-release-notes

The most notable changes/fixes for me are:

  • Magento Community Edition 1.9.1 works with MySQL 5.6 and PHP 5.5
  • Improved product save performance with a large number of rule-based product relations.
  • Catalog price rule expiration dates are observed.
  • Improved indexing performance.
  • The Update on Save option works properly (reindexing is not required).

After importing lots of data into Magento I had problems reindexing. I had no experience with fixing indexing errors Magento before and digging through the EAV structure in MySQL is not something you look forward to. Turns out there was a pretty easy fix for this which basically makes sure that all the tables are actually linking to an existing product. If there is a link to a product that doesn’t exist (anymore) for some reason you can expect to see errors like:

It’s as easy as running the following SQL commands:

Original post where I found this:

http://stackoverflow.com/questions/8111889/cant-re-index-new-products-after-upgrading-to-version-1-6/19837851#19837851

Another nice little function I created during my import adventures where I had to add a simple to configurable product in Magento. I’m sure this will come in handy for someone..

Sometimes you’d just like to add an unpaid invoice to Magento order without it being set to paid status (Cash on Delivery anyone?). Once again I found a tutorial on Inchoo which described the biggest part of generating an invoice programmatically for an order, but it was always set to paid status. Well, I found the solution:

It’s mostly the line $invoice->setState() which I changed. And I switched to offline capturing, all other options are documented.

I was calling this function from an event observer but you could also just load an order using:

Like the title says, the cron was broken when using Aoe_Scheduler so I decided to write my own little script from Xtento’s own code.

I put this file in the shell directory and actually just call it with a crontab at 00:00 every day:

The contents of the export function could also just be placed in the contruct, and it might not necessarily need the secureArea and setCurrentStore but it’s the contstruct I always use and it works ;)

Magento Configurable Option UpdateFor a project I had to figure out how to update options of a configurable product in the Magento Cart.

Considering the code from the famous Inchoo post from 2009 does not work anymore in Magento 1.8+ and I managed to get it working I decided to document the function for my fellow Magento developers out there on the interwebs. The code from the Inchoo post does change a few parts of the quote item but misses a few vital parts like changing the SKU. So on the frontend you might think it has properly changed the product, it will even show up fine in your cart, but once you checkout it will still use the old product! Turns out there’s a cart function called updateItem which can not only change the quantity but also the selected option of configurable.

Hope you’re all happy with this one, it took one of our developers more than 2 weeks to not get it working and I managed it in a day, once again. Mind you, a day is still frustratingly long for me, hence the post because everyone should be able to save that amount of time while working in a project..

The function I wrote to update options of a configurable product in the Magento Cart

To update the flavor of a configurable project we currently use a url like this:

http://somedomain.com/modulename/cart/updateajaxcart?productId=7260&itemId=3004&productQty=1&supperAttributeId=175&childId=237

Some explanation of the various variables you’re supposed to pass to the function:

  • $superAttributeId is the id of the attribute, in our case flavor which has id 175.
  • $childId is the id of the selected option of the attribute
  • $itemId is the id of the item in the cart
  • $productId is the id of the actual product, in this case the configurable
  • $refresh: if set will force the current page to refresh after updating the cart (handy for cart page since you want to not only refresh the ajax cart but also the whole cart page)

I cleaned up the code while writing the post so an error might have slipped in during the process, if you find anything wrong with it please don’t hesitate to comment and I will fix the code