I had a problem where I had to update all of the categories in a Magento store to change the CMS block to “Sub Category Listing” because they had been created without a CMS block selected. Doing this through the UI would have been painful as there were over 300 categories that had to be updated.
The solution was relatively simple, thanks to a quick PHP script. I put this in the webroot as updatecategories.php:
<?phpob_end_flush();echo"Started ".date("d/m/y h:i:s")."\r\n";require_once'/app/Mage.php';umask(0);
Mage::app()->setCurrentStore( Mage_Core_Model_App::ADMIN_STORE_ID);$categories= Mage::getModel('catalog/category')->getCollection();echo"Processing ".count($categories)." categories\r\n";foreach($categoriesas$category){// 6 is the ID for "Sub Category Listing"$category->setData('landing_page',6)->save();echo".";}echo"\r\n";echo"Finished ".date("d/m/y h:i:s")."\r\n";?>
I then ran the script (e.g. php updatecategories.php) and after about 30 seconds all categories were changed. You could probably point your web browser at the file as well to achieve the same effect. This will give you a starting point if you need to do anything else to the category, e.g. change the description, name, image etc.
Magento | bob | April 15, 2011 9:59 am | Comments Off
Recently I’ve been coming across more interesting links to do with HTML5 and CSS3.
The first thing you want to know is can I use these two new technologies. Luckily that is where caniuse.com comes in handy. It is a great resource for looking at what web browsers are compatible with the newer standards.
So is HTML5 worth it? The website www.html5rocks.com will show you some of the great features it has and also let you play with them in the playground.
So you want to start writing in HTML5? You’ll need some good starting points. Boilerplates are a great way to start from a good place. The resources over at html5boilerplate.com can help you get that start.
CSS3, HTML5 | aaron | March 14, 2011 2:48 pm | Comments Off
As of Magento 1.4.2.0 the customer model now implements eav from attributes, and a new customer form model. For anyone who has existing custom attributes, or are thinking of making some this will pose new issues in accessing and saving this data.
To implement a custom customer attribute, the sql/[module]_setup install file needs to add the new attribute and then add this attribute to several forms (those that deal with a customer). See below, but these are customer_account_edit, customer_account_create, adminhtml_customer and checkout_register.
Here is an example of an existing custom attributes to add a customer type field: sql/[module]_setup/mysql4-install-0.1.0.php (for example)
function createCustomAttributes(){$attribs=array('customer'=>array('customer_type'=>array('type'=>'varchar','label'=>'Customer Type','sort_order'=>5,'required'=>0),));$setup=new Mage_Eav_Model_Entity_Setup('core_setup');foreach($attribsas$entityName=>$attributes){foreach($attributesas$attributeName=>$attributeData){$setup->addAttribute($entityName,$attributeName,$attributeData);}}}
createCustomAttributes();
This code will add the customer attribute ‘customer_type’ to the eav attribute table. Now comes the important difference introduced in Magento 1.4.2.0:
//add attributes to new forms model attributes$eavConfig= Mage::getSingleton('eav/config');$attributeArray=array('customer_type');//I handle this in an array incase several attributes need adding, depending on your needs.foreach($attributeArrayas$attrib){$attribute=$eavConfig->getAttribute('customer',$attrib);$attribute->setData('used_in_forms',array('customer_account_edit','customer_account_create','adminhtml_customer','checkout_register'));$attribute->save();}
This will add a field to all of the customer forms, and also the onepage checkout if using the user chooses to create a new account during checkout method! (although the latter will require adding to the template… in the format: name=”billing[customer_type]” as the other forms use the form model to generate the HTML fields)
If you are using the registration page, the attribute also needs to be added to the sales_flat_quote table: (in the same file..
$installer->getConnection()->addColumn($installer->getTable('sales_flat_quote'),'customer_type','text NULL DEFAULT NULL AFTER `customer_taxvat`');
I’ve been working on a complex PHP CLI script lately and in order to debug something I’ve been putting var_dump() and die commands at the appropriate place. This is annoying.
Packages like xdebug provide the ability to put a breakpoint in, but this requires you to configure your environment appropriately and use an IDE that can listen and step through the script. Also, I’ve seen people having trouble using xdebug with PHP CLI – I haven’t tried it myself.
So, anyway my hacky solution was to roll the following code at the point I wanted to debug. I had the variable scope at my disposal, so I could issue my own var_dump(), echo and variable assignment commands, before then entering “break;” to get out of the loop (I had to put an exception in for “break;” because the break is run in the eval command and it won’t break out of it without an error).
// Helper line so I can find and remove this code later:echo"\n".__FILE__.':'.__LINE__.' breakpoint'. PHP_EOL;while(true){$cmd= readline("debug> ");if($cmd=='break;'){break;}eval($cmd);}
You may want to wrap this in some logic test so that it only fires when certain criteria are met.
So you’ve heard about Ubuntu and you’ve been interested but when you found out that it (can) completely replace your current operating system you thought better of it. After all, the last thing you want to happen when you try a piece of new software is for you to lose everything.
Enter Wubi. Wubi is a small installer program (about 1MB) that will install Ubuntu on your Windows computer (Mac and Linux versions are coming) that will install the whole operating system into a “container file” on your existing Windows hard drive. What this means for you is that there’s virtually no risk installing Ubuntu as if you don’t like it or if you want to go back to how things were you simply remove the Wubi application through the Windows control panel.
How it works:
Wubi asks you where you want to install Ubuntu and how much disk space you want to give it
Wubi then downloads an Ubuntu 10.04 ISO file
The ISO file is unpacked into the container file along with grub (the boot loader that comes with Ubuntu)
The Windows startup options are modified to include booting into Ubuntu as an option.
Your PC restarts and the installation completes.
The performance of Ubuntu running in a container file is good – there will be overheads far greater than running native file systems like ext4 directly on the disk but as a no-risk introduction to Ubuntu for the Windows user, this is a great start.
As far as I know, the only thing that DOESN’T work in Ubuntu installed using this method is the hibernate support. Attempting to hibernating your Ubuntu desktop environment simply results in the screen being locked requiring your password to continue (presumably the hibernation failed).
Check out this YouTube video of Shawn Powers from Linux Journal installing Wubi (4:24s).
Recently I’ve been introduced to the Grid plugin in Compiz – this is a fantastic little plugin that snaps your windows to predefined positions on the screen. After using it for the last couple of weeks I can’t imagine going back to not using it.
To get access to it you will need to install the compiz settings manager, and load Compiz’s “Fusion Plugins Extra”:
Tick the box to enable it and click “Close” (bottom left)
Now try using Ctrl-Alt and numbers on your keypad. CA-9 will snap a window into the top right corner (press it a few more times to get different sizes) and CA-8 will make it snap to the top half of the screen (the number is the position on the screen, you’ll get the gist of it).