A place to log my programming solutions.

17
May 10

Magento Custom Module Block, Controller, Model, etc. Not Working

Just a little tip. When you’re frustrated as to why Magento isn’t loading your Company/Module/Block/*, Company/Module/Model/*, Company/Module/controllers/*, etc. files for some strange reason:

Make sure the file permissions are set correctly.

(0777 might be too generous, but we don’t have time to figure these things out for sure).

This happened to me today. Turns out my IDE (NuSphere’s PhpEd, an excellent PHP IDE by the way) has a setting for default folder/file permissions when creating new files. Insufficient file permissions were manifesting themselves as “Invalid block type …” errors. I’m sure it could be responsible for other quirkiness when doing custom work.

13
May 10

You Know You’re Deep in Magento When..

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*

30
Mar 10

Magento – Accept Payments via Authorize.net

Use this resource “How to Set Up Authorize.net Payment Gateway” at Redstage’s Magento Blog for more information on how to set up the Authorize.net payment module in Magento. The article shows where to get the API and Transaction Keys, as well as where to enter them into Magento.

As with most payment gateways, the steps involved are a matter of:

  1. Gathering the appropriate information (provided by the gateway service)
  2. Enter the information into the Magento Admin Panel
  3. Activate the payment module

Full procedure

27
Mar 10

Magento – Add Custom Category Attributes

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:

  1. Create a new row in the eav_attribute table, one that mimics a category’s meta-description attribute with everything being the same except for a unique identifier and a label.
  2. Create a new row in the eav_entity_attribute table, to provide a sort order for your newly created attribute, following in the format footsteps of the existing rows.

For the fully detailed procedure, see Create Custom Category Attributes with phpMyAdmin

12
Mar 10

Magento – Resetting Admin Password

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.

9
Mar 10

Google Chrome – Goodbye Firefox

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)

firefox-memory-leak

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?

8
Mar 10

Magento – Set Product Dropdown and Multiselect Values Programmatically

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
  2. Load the collection of that attribute’s values
  3. Make your choices (different for Dropdown and Multiselect)
  4. Save the product

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.

7
Mar 10

ConstantContact Send Welcome Email When Creating a New Contact via API

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.

6
Mar 10

Refresh Magento Cache Programmatically

When writing processes to automate some of Magento’s normally laborious tasks, perhaps for a product-import script, a mass attribute update script, category import, or inventory adjustment, keep in mind that you may have to refresh some kind of cache — especially when working with attributes. If you are encountering quirks or inconsistencies with your data, try these:

  • Rebuild Catalog Index
    Mage::getSingleton('catalog/index')->rebuild();
  • Rebuild Flat Catalog Product
    Mage::getResourceModel('catalog/product_flat_indexer')->rebuild();
  • Inventory Stock
    Mage::getSingleton('cataloginventory/stock_status')->rebuild();

For more cache refreshes, such as:

  • Catalog Rewrites
  • Layered Navigation Indices
  • Product Image
  • Search Index

… please refer to the source of this knowledge http://www.magentocommerce.com/boards/viewthread/43238/#t156277

About NVNCBL and Myself

Contact Me