The start of something great (possibly)..

by Dan on Jul.05, 2012, under Magento, Module Development, PHP

When I first setup this website, it was mainly for my own benefit – a place to note down annoyances, bug fixes, work-arounds for various issues in the tech world. I’d use it to refer back to (or refer other people to) when I’d been asked to help/offer advise on a particular topic that I’d covered previously.


All that seems to have died off now, all the bugs got fixed, and I’m no longer annoyed (LOL -now there’s a dream). So, in order to make it look like this website is still being updated (since I’ve only posted once this year so far!), I’m going to start a series on Magento module development, offering tutorials, how-to’s, tips and tricks, for developing your own Magento modules with. I’ll cover areas such as;

  • The basics
  • Blocks, Models and Helpers in-depth
  • “Mysql4″
  • Using events and observers
  • The administration area
  • Shipping methods
  • Payment gateways

..and much more. Watch this space for what will probably be the most I’ve ever written in a really long time!

I might offer more than Magento tutorials in the future. If you have a particular topic/subject area you’d like me to cover, get in touch¬†and I’ll see what I can do!

-Dan :)

Leave a Comment :, , more...

Creating products programmatically in Magento

by Dan on May.22, 2012, under Magento, PHP, Software

Let’s face it – importing is hard. Especially if it’s from some other unfamiliar product, or something that doesn’t already have a Dataflow/import plugin for Magento already. Dataflow has its limits. I’ve actually found it easier to import manually (creating models for products) as opposed to writing Dataflow routines. However, one of my biggest bug bears is not just creating products in Magento programmatically, but creating them successfully. We always end up with stock or relationship issues between simple and configurable products.

Continue reading “Creating products programmatically in Magento” »

15 Comments more...

Get website-level configuration in Magento

by Dan on Dec.07, 2011, under Magento, PHP

I stumbled across this one a couple of times now, and it’s caught me out every time.

With Magento, you have the method Mage::getStoreConfig() to get a store-level config, but nothing obvious to get a website-level configuration (such as a default URL for the website).

So I used this;


It’s the same syntax as what’s used in Mage::getStoreConfig(), but uses getWebsite() instead of getStore(). Hopefully this won’t catch me out anymore!

2 Comments :, , , more...

Bug in Magento affecting development sites using base_url

by Dan on Nov.14, 2011, under Magento, PHP

I installed a copy of Magento on a dev site I setup to do some testing with Varnish with (more on that later). However, in the requirement to be able to get to Magento using 2 different URL’s, I stumbled across this quite annoying bug.

a:5:{i:0;s:67:"Illegal scheme supplied, only alphanumeric characters are permitted";i:1;s:729:"#0 /home/dan/workspace/magento1610/app/code/core/Mage/Core/Model/Store.php(712): Zend_Uri::factory('{{base_url}}')
#1 /home/dan/workspace/magento1610/app/code/core/Mage/Core/Controller/Varien/Front.php(313): Mage_Core_Model_Store->isCurrentlySecure()
#2 /home/dan/workspace/magento1610/app/code/core/Mage/Core/Controller/Varien/Front.php(161): Mage_Core_Controller_Varien_Front->_checkBaseUrl(Object(Mage_Core_Controller_Request_Http))
#3 /home/dan/workspace/magento1610/app/code/core/Mage/Core/Model/App.php(349): Mage_Core_Controller_Varien_Front->dispatch()
#4 /home/dan/workspace/magento1610/app/Mage.php(640): Mage_Core_Model_App->run(Array)
#5 /home/dan/workspace/magento1610/index.php(80): Mage::run('', 'store')
#6 {main}";s:3:"url";s:85:"/index.php/admin/system_config/edit/section/web/key/41c8c3d3f4bcb72e3c267ae0b73333d7/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}

Bug reports on Magento’s site here, here, here and here. Not being patient enough for Varien to fix it, I developed a small extension which resolves the problem. It’s available to download below.

Put the tarball in the Magento webroot and extract. After you install this extension, you’ll need to empty the cache manually (if it was enabled). I assume if you’re reading this, then your Magento installation is broken. To do this, simply remove the contents of var/cache in Magento’s webroot.

When you re-visit your Magento’s front or backend, the problem should vanish.

BTS_1610Fix.tar.gz (md5: 8316468f4e179cf2f512edaaf62a12db)

Updated 9th January 2012: It apparent that, attempting to login before applying this update with {{base_url}} set screws up the admin login cookies somehow. When you apply this patch, you’ll probably need to empty out your chosen browser’s cookie jar before attempting to login. You can tell if you need to or not by trying to login, and Magento coming back to you with a login screen, with no failed login message.

Updated 12th January 2012: Magento was released today. I can confirm that this problem still exists and has not yet been fixed (despite what the developers have written on one of the bug reports).

Updated 25th April 2012: I can confirm that this problem has been resolved in the latest version, released 24th April 2012.

89 Comments :, , , more...

Getting Configurable Product from Simple Product ID in Magento 1.5+

by Dan on Sep.19, 2011, under Magento, PHP

I recently stumbled across a hurdle which stopped some of my code from working. It was code that gets the configurable product associated with a given simple product. Many solutions out there call a “loadParentProductIds()” function within the Mage_Catalog_Model_Product class. However, as of Magento, they deprecated this method, simply by setting the data element (and returning) an empty array. So any calls to this function would return/yield no parents. Hm, how to get the parent product now?

Finally, I managed to find a workable solution. Check this out;

$simpleProductId = 465;
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
$product = Mage::getModel('catalog/product')->load($parentIds[0]);
echo $product->getId(); // ID = 462 (aka, Parent of 465)

There you have it. Short and sweet.

6 Comments :, , more...


A few highly recommended websites...