Category: Programming Quickies
Back in they day, I ran a Tumblr blog named Magento Quickies where I’d post shorter, less in-depth posts about my travels through Magento’s source code. This Programming Quickies categories is the successor to that Tumblr blog. You’ll find all the old Magento Quickies content here, as well as new short posts about programming in general.
This section has its own RSS feed, the old Magento Quickies feed should should be redirecting, and we’re cross posting notifications for new posts over to magento-quickies.tumblr.com. In other words, you shouldn’t need to know any of this, but the duct tape that keeps the internet held together isn’t aging well, so your mileage may vary.
Below you'll find all the Programming Quickies articles on the site, followed by a chronological listing of the same. You may also browse the 7 series directly via the following links. Pestle, Four Steps to Async Iterators, Checking in on OpenMage and Magento in 2020, Text Encoding and Unicode, Shopware's Development Environment, A Sentimental Gen-X Programmer Culls his Tech Books, and, Containers, Containers, Containers.
Wherein I attempt to explain the theme fallback system to a Magento newbie on Stack Overflow
Wherein I attempt to explain the theme fallback system to a Magento newbie on Stack Overflow
astormOne Line Observers
I’ve started creating single line observers like this <?php class Mycompany_Mymodule_Model_Observer { public function someMethod($observer) { Mage::helper('mycompany_mymodule/observer') ->someMethod($observer->getCustomer()); } } The logic is punted to a helper class. This way the helper receives only the objects it needs [...]
astormController _redirects are Not Immediate
Magento Version: 1.5.1 If you’ve spent anytime with the Magento core controllers, you’re probably aware you can kick off an HTTP redirect with something like $this->_redirect('catalogsearch/term/popular/'); There’s two things about this you should be aware of. The _redirect method does not automatically halt [...]
astormYour local.xml Layout File Might not Win
When explaining the local.xml Layout file, you’ll hear Magento veterans (myself included) explain that local.xml is loaded last, so the updates there always “win”. This is true, to an extent, but there’s one big caveat to keep in mind. Layout Update XML Fragments are loaded and applied in order, by handle. That [...]
astormSQL Headquarters
There’s more sophisticated ways of logging and profiling SQL in Magento these days, but sometimes it’s still easier and quicker to drop down to the abstract Zend adapter and log your queries with a few discrete calls to Mage::Log Almost every INSERT, UPDATE, SELECT, and DELETE goes through the methods in [...]
astormCheckItOut @andkorolyov, in response to my question “Hey magento people, are there are any extensions (free/paid) that add Ajax features to the checkout page?”
astormWe have an extension that uses Ajax to change what shipping rates are shown in a weekly date/time grid @webshopapps, in response to my question “Hey magento people, are there are any extensions (free/paid) that add Ajax features to the checkout page?”
astormSome people in the Magento Community are getting antsy about the eBay acknowledgment. As with anything that’s out of my control, it’s a hope for the best, plan for the worst situation.
astormPHP Patterns in Magento
In many programming languages, especially the less strictly typed ones, a common coding pattern starts to emerge. $thing = $this->getSomeThing(); if($thing) { //do something with the thing } Without a compiler to catch methods returning what they shouldn’t, a developer is forced to sanity check return values from methods before [...]
astormMagento Custom Form Validation
Magento’s form validation seems scary at first, but using it is actually quite easy. First, create for your form. <form action="<?php echo $this->getUrl('/some/route/thing');?>" id="theForm"> <input type="text" name="foo" id="foo" /> </form> Next, run this bit of javascript to turn your plain old form [...]
astormSafari Keeps Showing “Please Enable Cookies” Page
Lots of kind souls helped me out on Twitter with this one. Some versions of Safari are stricter about setting cookies than others. Also, Magento sets the full cookie domain and path as well, which is where weird cookie bugs can lie. If you’re having trouble setting your session Magento (i.e. “Please Enable Cookies, you [...]
astormEditing Email Templates
Magento Version: 1.5.0.1 I’m not sure when this feature was added. It’s there in 1.5.0.1 and might be in previous version. The phtml template file for your system emails are located in app/locale/en_US/template/email/ However, you don’t want to edit these files. Instead, go to System -> Transactional Emails This UI [...]
astorm404 Debugging
Magento Version: 1.4.2 I’ve found that most of my route based 404 problems in Magento can be traced a misnamed controller file and/or class. Adding some debugging to the standard router’s _validateControllerClassName method often point to the problem. In 1.4.2 you can find this file here.
astormsales_model_service_quote_submit_before, sales_model_service_quote_submit_success, sales_model_service_quote_submit_after. All of these are in Sales/Model/Service/Quote.php in submitOrder() method. Zoran Lazarevski, when asked What event(s) are you using to “do something” after checkout/order-creation, regardless of method?
astormsales_model_service_quote_submit_before, sales_model_service_quote_submit_success, sales_model_service_quote_submit_after. All of these are in Sales/Model/Service/Quote.php in submitOrder() method. Zoran Lazarevski, when asked What event(s) are you using to “do something” after checkout/order-creation, regardless of method?
astormI use the event ‘checkout_submit_all_after’. Yes the order has been saved by the time this event is fired. Jason Evans, when asked What event(s) are you using to “do something” after checkout/order-creation, regardless of method?
astormThere is no sure method except sales_order_save_after, but generally I tend to use sales_model_service_quote_submit_after. It covers opc, api and adminhtml (but not multiaddress). sales_convert_quote_address_to_order covers all, but I don’t like it. Vinai Kopp, when asked What event(s) are you using to “do something” [...]
astorm