Import Not Working Until You Save
This is because you've missed out _product_websites
, for which all products should have a value of base
Importing Images
Ok so to import images you first need these columns:
-
_media_attribute_id
- the attribute_id ofmedia_gallery
(see below) -
_media_image
- the path of the image, i.e./some_image.jpg
-
_media_lable
- the image label, i.e. "My nice image" -
_media_position
- the position, 1, 2 etc -
_media_is_disabled
- whether the image is excluded from the gallery or not
You do the whole weird multi-line thing to import multiple images. Every image
you use (whether it's in the gallery, or being used for the image
, small_image
or `thumbn...
Full Module Configuration Reference
<!-- # Module Initialisation
app/etc/modules/Namespace_ModuleName.xml -->
<config>
<modules>
<Namespace_ModuleName>
<active>true</active>
<codePool>local</codePool>
</Namespace_ModuleName>
</modules>
</config>
<!-- # Module Configuration
app/code/local/Namespace/ModuleName/etc/config.xml -->
<config>
<modules>
<Nmespace_ModuleName>
<version>0.0.1</version>
</Nmespace_ModuleName>
...
Config Helper Rewrite Definition
<config>
<global>
<helpers>
<catalog>
<rewrite>
<data>Namespace_Module_Helper_Catalog_Data</data>
</rewrite>
</catalog>
</helpers>
</global>
</config>
Config Block rewrite Definition
<config>
<global>
<blocks>
<catalog>
<rewrite>
<product>Namespace_Module_Block_Catalog_Product</product>
</rewrite>
</catalog>
</blocks>
</global>
</config>
Helper Block Definition
<config>
<global>
<helpers>
<namespace_module>
<class>Namespace_Module_Helper</class>
</namespace_module>
</helpers>
</global>
</config>
Pretty Debug Output
Yeh it's not Magento, but this might help some people:
Zend_Debug::dump()
Basically it's var_dump but with <pre>
tags, no biggie but it's nice to use.
Return Store Variables (Phone Number, Address, E-Mail etc)
Name:
Mage::getStoreConfig('general/store_information/name')
Phone number:
Mage::getStoreConfig('general/store_information/phone')
Address:
Mage::getStoreConfig('general/store_information/address')
E-Mail:
Mage::getStoreConfig('trans_email/ident_general/email')
Get Category Children
public function getCategories()
{
if (!$this->categories) {
$categoryId = $this->getData('parent_category_id');
$parentCategory = Mage::getModel('catalog/category')->load($categoryId);
$categoryCollection = $parentCategory->getCollection();
$categoryCollection->addAttributeToSelect('url_key')
->addAttributeToSelect('name')
->addAttributeToSelect('image')
->addAttributeToFilter('is_active', 1)
->addAttributeToFilte...
Get and Resize Category Images
public function getCategoryImage(Mage_Catalog_Model_Category $category, $width = 250, $height = 250)
{
// return when no image exists
if (!$category->getImage()) {
return false;
}
// return when the original image doesn't exist
$imagePath = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category'
. DS . $category->getImage();
if (!file_exists($imagePath)) {
return false;
}
// resize the image if needed
$rszImagePat...
Boilerplate Resource Model Collection Class (Before CE 1.6 / EE 1.11)
/**
* Yourcompany.com
*
* PHP Version 5
*
* @category Namespace
* @package Namespace_Module
* @author Your Name <your.name@yourcompany.com>
* @copyright 2012 yourcompany.com
* @license http://www.yourcompany.com/license.txt Your license
* @link N/A
*/
/**
* Something resource collection model
*
* @category Namespace
* @package Namespace_Module
* @author Your Name <your.name@yourcompany.com>
* @license http://www.yourcompany.com/lice...
Boilerplate Resource Model Class (Before CE 1.6 / EE 1.11)
/**
* Yourcompany.com
*
* PHP Version 5
*
* @category Namespace
* @package Namespace_Module
* @author Your Name <your.name@yourcompany.com>
* @copyright 2012 yourcompany.com
* @license http://www.yourcompany.com/license.txt Your license
* @link N/A
*/
/**
* Something resource model
*
* @category Namespace
* @package Namespace_Module
* @author Your Name <your.name@yourcompany.com>
* @license http://www.yourcompany.com/license.txt You...
Admin - Creating A Basic Grid And Edit Form
Much easier to show how this is done by showing you some code examples, so please see the link attached.
Admin Form Field Types
The various types are:
- text
- textarea
- multiline
- select
- multiselect
- radio
- checkbox
- password
- time
- note
- label
- link
- image
- file
- date
- submit
See the link for detailed usage information
Translating Javascript Strings
Use this syntax:
Translator.translate('Some phrase');
I believe you also have to make the translation available to the Translate class in this manner:
<script type="text/javascript">
Translator.add('You should take care of this confirmation message!','<?php echo Mage::helper('yourmodule')->__('You should take care of this confirmation message!')?>');
</script>
Fetching All Attributes For An Entity From The DB In One Query
Using the database to inspect EAV-based entity types can be a real pain in the ass, so here are a bunch of queries that let you inspect some popular EAV entity types easily. This practice can be applied to any EAV entity type, however as there are about 25 of them, I decided to just list the popular ones, enjoy.
Output example (shortened):
|----------------------------------+----------+----------+---------------------|
| attribute_code | type | store_id | value |
|----------------------------------+-----...
Add All Attributes To A Collection
$attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
$collection->addAttributeToSelect($attributes);
Add A Tab To The Admin Product Screen
Declare an admin layout XML file for your module in your config.xml
:
<config>
<adminhtml>
<layout>
<updates>
<your_module>
<file>your-module.xml</file>
</your_module>
</updates>
</layout>
</adminhtml>
</config>
Create the layout XML in /app/design/adminhtml/default/default/layout/your-module.xml
:
<?xml version="1.0"?>
<layout>
<adminhtml_catalog_product_edit>
<refer...
Add A Tab To The Admin Product Screen
Adding A Tab To The Product Screen
-
Declare an admin layout XML file for your module in your config.xml:
-
Create the layout XML in /app/design/adminhtml/default/default/layout/your-module.xml:
Magento Multi Database Guide
Handy link to a very useful PDF which details how to handle multiple databases in Magento.
Raw Database Queries
The attached link describes everything fantastically, just go there.
Custom Cache Type Definition
Adding this XML will cause an additional entry to appear in the Magento Cache Management screen.
<global>
<cache>
<types>
<your_cache_type module="your_module" translate="label description">
<label>Your Custom Cache Label</label>
<description>Description of cache type.</description>
<tags>YOUR_CACHE_TAG</tags>
</your_cache_type>
</types>
</cache>
</global>
![](http://mikewhitby.co.uk/makandra-track.g...
Messages and Global Messages Blocks
Both use the same block, as we can see in page.xml
:
<block type="core/messages" name="global_messages" as="global_messages"/>
<block type="core/messages" name="messages" as="messages"/>
When you add a message, you add it to the session, rather than to either of the
messages blocks, so the code below causes the Mage_Customer_Model_Session object
to have an error logged to it:
Mage::getSingleton('customer/session')->addError('Please enter all required information');
At this point neither message blocks know anything about the...