
Black on the rocks
You know you’re deep in Magento when you have a file an Abstract.php open. Or in a Mysql4 folder.
Or when one of your eyes starts twitching.
*sigh*
A client wanted to add a description to each of his product categories, such that the first built-in description would be above the product listing, and the second description would be below the product listing. Rather than have them create static blocks for every category, it was obvious that I’d have to create a new category attribute.
Fortunately, I stumbled upon one possible solution. The method doesn’t involve creating a full-blown module, rather, just a few database modifications using phpMyAdmin.
Summarized, the process comes down to:
For the fully detailed procedure, see Create Custom Category Attributes with phpMyAdmin
Handy if you (or a client) is locked out, here’s how to reset the admin password, posted on Redstage’s Magento Blog.
Basically, the procedure involves going into the database, finding the appropriate row that contains the password, and assigning the new password using MD5.
I’ve become fed up with Firefox’s memory leak problem. Most of us have seen the browser occupying upwards of 1GB, but even today’s offense of just 461MB (5 tabs open) was the final nail in the coffin. Taking recommendations from co-workers and friends, I installed Google Chrome. It’s lightning fast. The transition process was smooth and painless — bookmarks, browsing history, and saved passwords were all migrated. I’m excited to see how the browser integrates with Google’s online services (e.g. bookmark sync)
Don’t get me wrong, I love Firefox and once touted it as the best thing to happen to the Internet since broadband came out. Too bad the rest of my system slows to the point where I’m experiencing issues with basic keyboard and mouse input. I know I’ll have to come back to Firefox every now and then because of the developer toolbar, but it’s no longer my default browser. Did I mention that Chrome is fast?
Here’s how to programmatically, meaning through code, set a product’s attribute value when the attribute is of type Dropdown or Multiselect. For dropdown, we’ll be interested in setting only a single value. And obviously for multiselect, we’ll be interested in setting multiple values.
With Text attributes such as Name and Description, you can do something like:
$product->setName( 'My Sweet Shirt' ); $product->setDescription( 'This shirt will make you look good, thus impressing girls.' );
Unfortunately, this won’t work for attributes whose values are predefined. Instead of cursing Magento, think of it as a data-integrity/validation measure.
Anyway, assuming you already have a $product object, our overall process will be to:
1. Load an attribute object for the attribute you want to work on
$attribute = Mage::getModel('eav/entity_attribute'); $attribute->loadByCode( 4, 'color' );
2. Load the collection of that attribute’s values
$values = array(); $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection') ->setAttributeFilter( $attribute->getId() ) ->setStoreFilter( Mage_Core_Model_App::ADMIN_STORE_ID, false) ->load(); foreach ($valuesCollection as $item) { $values[$item->getValue()] = $item->getId(); }
3. Make your choice – DROPDOWN
$product->setColor( $values['Blue'] ); // just do whatever you need to code 'Blue' instead of hard-coding it
3. Make your choices – MULTISELECT
$product->addData( array( 'color' => $values['Blue'] .','. $values['Red'] .','. $values['Black'] // just putting together a comma-separated list of values ) );
4. Save the product
$product->save();
This builds off the solution posted by member “icvu” here: http://www.magentocommerce.com/boards/main.php/viewthread/69925/ — specifically the addData() part.
Thanks, and have fun setting attribute values.
Using the ConstantContact mailing list, I was having trouble getting the welcome email to send after creating a new contact through the API. I had tried checking the “Autoresponder” box in the admin panel, but still no welcome email. The solution is to have:
var $actionBy = 'ACTION_BY_CONTACT';
in cc_class.php (provided via the “PHP Sample Forms” zip file). By default, this value is:
var $actionBy = 'ACTION_BY_CUSTOMER'
instead, which does not trigger the welcome email.