Engine23

Development

Magento - Create a CSV of all categories

In case you need to export to a csv all the categories in your site, here is the code.

The csv just has the ID of the category, the Name of the category and the url key


$categories = Mage::getModel("catalog/category")->getCollection()
 ->addAttributeToSelect('name')
 ->addAttributeToSelect('url_key');

fputcsv($file,array('Category ID', 'Name', 'URL Key'));

// id, name, url-key
foreach($categories as $_category)
{
 fputcsv($file,array($_category->getData('entity_id'), $_category->getData('name'), $_category->getData('url_key')));

}
fclose($file);

Magento - Admin form not saving new columns

If you modify an admin form, lets say you add a column to the database for another field.  If you start to test, but the form is not saving the new fields, and it appears that Magneto is ignoring your new columns, well....it is.

Long story short, there is a function called

protected function _prepareDataForTable(Varien_Object $object, $table)

Found In :

Read more

Adminhtml Grid appears twice

If you create a custom adminhtml grid and you get the resulting data 2x after you use a column header or filter, the problem is with the xml.

The solution is to remove part of the xml.  The red text (output="toHtml") on the nested block is the code you need to remove

***** BAD XML that is showing the block twice *****
<
adminhtml_flat_entry_grid>
<block type="core/text_list" name="root" output="toHtml">
<block type="engine23_blog/adminhtml_flat_entry_grid" name="blog_ajax_grid" output="toHtml"/>
</block>
</adminhtml_flat_entry_grid>

**** Correct XML to remove the extra block when filters/sorting is used ****

Read more

MySQL result set for MIN and MAX that do not equal one another

I needed to get a mysql query where the MIN and MAX were set, but I could exclude any that the same.  I struggled a bit to figure out the proper syntax but my friend Tom B. from Gallup helped me out ( Thank you sir, that is one digital drop for you! ).  For those of you who may need to get this in the future...or maybe future me in a few weeks after I forget the syntax....here it is:

 SELECT SQL_CALC_FOUND_ROWS MIN(`entity_id`) as minResult, MAX(`entity_id`) as maxResult, `oms_id` FROM `customer_entity` WHERE `oms_id` IS NOT NULL GROUP BY `oms_id` HAVING minResult != maxResult 

Magento Grand Slam

I recently posted this on LinkedIn and felt this was also a good place for this.  

Magento Certified Grand Slam Badge

Well, I just passed the 4th and final certification exam that Magento offers.  I just did a quick search and there are a total of 6 of us in the United States, and 35 world wide who decided to take all 4 exams.  After this year of studying and preparing, its a very good thing for any Magento developer to strive to do.  It forces you to fully understand the platform as whole.

 

Read more

Finding the right Magento event observer - Checkout

There are many many events that fire during checkout.

In particular there is a need to do something special once a checkout has occurred.  Choosing the right one can be tough.  In 1.9 and 1.14 you can use 

checkout_submit_all_after

This may be in earlier versions, but this one is only fired 1 time and allows for good details about the quote/order

NGINX remove index.php from url

When you use nginx, just like apache, by default the Magento URL has index.php. That is fine for Magento development, but very ugly and not search engine optimized. So, the fix, just like apache is a pretty simple one. I am not too sure if there are any implications to this version of removing it, but it seems to work. In you nginx configuration file, you need to add 1 line of code:

server { 
....
rewrite ^/index.php/(.*) /$1 permanent;
....
}

****UPDATE****

This may not work 100% as much as I had hoped. In the Magneto admin it was not allowing my caches to be cleared. You may need to turn on SEO Urls and maybe do some other tweaks to get this to work properly. If I can find an awesome solution I will be sure to update this.

Read more