Attributes

$attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
$collection->addAttributeToSelect($attributes);

$entityTypeId = Mage::getModel('catalog/product')
->getResource()
->getEntityType()
->getId();
$attributeSet = Mage::getModel('eav/entity_attribute_set')
->setEntityTypeId($entityTypeId)
->setAttributeSetName('test_set');
$attributeSet->validate();
$attributeSet->save(); $attributeSet->initFromSkeleton($skeletonID)->save();

You need to save before you do initFromSekeleton().

<config>
  <frontend>
    <product>
      <collection>
        <attributes>
          <some_attribute/>
        </attributes>
      </collection>
    </product>
  </frontend>
</config>

$_product->getAttributeText('brand');

Potentially confusing due to the 3 methods you could use, all of which are in Mage_Catalog_Model_Product:

public function getUrlPath($category=null)
public function getUrlInStore($params = array())
public function getProductUrl($useSid = null)

The best way to explain is to simply show the results of several calls. Given a product whose URL key is coffee-table-set on the domain of http://domain.com the results are:

$product->getUrlPath();
'coffee-table-set'

$product->getUrlPath($category);
'tables/coffee-table-set'

// you cannot stop this method adding ___store to the URL, even by setting _store_to_url to false
$product->getUrlInStore();
'http://domain.com/tables/coffee-table-set?___store=default'

// you cannot stop this method adding ___store to the URL, even by setting _store_to_url to false
// note - see the "using _ignore_category" section below for an arguable bug with using this param
$product->getUrlInStore(array('_ignore_category' => true));
'http://domain.com/coffee-table-set?___store=default'

$product->getProductUrl();
'http://domain.com/tables/coffee-table-set'

$product->getProductUrl(true);
'http://domain.com/tables/coffee-table-set'

Using _ignore_category

The short version - I would not use this param, and instead use Mage::getUrl($product->getUrlPath())

If you first fetch a products URL which includes the category, and then use the same product instance to attempt to fetch a non-category URL, you will instead both times get a URL which contains the category, see the below code:

The issue lies with the request_path key on the $product model, which the Mage_Catalog_Model_Product_Url::getUrl() sets, to act as a cached value for an otherwise intensive process of resolving a URL rewrite to a product within a category.

To resolve this, unset request_path first, as below:

$product->unsRequestPath();
$product->getUrlInStore(array('_ignore_category' => true));
'http://domain.com/coffee-table-set?___store=default'

class Namespace_Module_Model_Select extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
/**
* Retrieve Full Option values array
*
* @param bool $withEmpty Add empty option to array
* @param bool $defaultValues
*
* @return array
*/
public function getAllOptions($withEmpty = true)
{
if (!$this->_options) {
$options = array();
$options[] = array(
'value' => '0',
'label' => 'Option 1',
);
$options[] = array(
'value' => '1',
'label' => 'Option 2',
);
$this->_options = $options;
}
$options = $this->_options;
if ($withEmpty) {
array_unshift($options, array(
'value' => '',
'label' => '-- Please Select --',
));
}
return $options;
}
}

Used when you want to use a select or multiselect dropdown box on an EAV entity, such as products or categories.

$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'attribute_name')) {
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'attribute_name', array(
// TABLE.COLUMN: DESCRIPTION:
'label' => 'Label', // eav_attribute.frontend_label admin input label
'group' => 'General', // (not a column) tab in product edit screen
'sort_order' => 0, // eav_entity_attribute.sort_order sort order in group
'backend' => 'module/class_name', // eav_attribute.backend_model backend class (module/class_name format)
'type' => 'varchar', // eav_attribute.backend_type backend storage type (varchar, text etc)
'frontend' => 'module/class_name', // eav_attribute.frontend_model admin class (module/class_name format)
'note' => null, // eav_attribute.note admin input note (shows below input)
'default' => null, // eav_attribute.default_value admin input default value
'wysiwyg_enabled' => false, // catalog_eav_attribute.is_wysiwyg_enabled (products only) admin input wysiwyg enabled
'input' => 'input_name', // eav_attribute.frontend_input admin input type (select, text, textarea etc)
'input_renderer' => 'module/class_name', // catalog_eav_attribute.frontend_input_renderer (products only) admin input renderer (otherwise input is used to resolve renderer)
'source' => null, // eav_attribute.source_model admin input source model (for selects) (module/class_name format)
'required' => true, // eav_attribute.is_required required in admin
'user_defined' => false, // eav_attribute.is_user_defined editable in admin attributes section, false for not
'unique' => false, // eav_attribute.is_unique unique value required
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global (products only) scope
'visible' => true, // catalog_eav_attribute.is_visible (products only) visible on admin, setting to false stops import of this attribute
'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front (products only) visible on frontend (store) attribute table
'used_in_product_listing' => false, // catalog_eav_attribute.used_in_product_listing (products only) made available in product listing
'searchable' => false, // catalog_eav_attribute.is_searchable (products only) searchable via basic search
'visible_in_advanced_search' => false, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via advanced search
'filterable' => false, // catalog_eav_attribute.is_filterable (products only) use in layered nav
'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search (products only) use in search results layered nav
'comparable' => false, // catalog_eav_attribute.is_comparable (products only) comparable on frontend
'is_html_allowed_on_front' => true, // catalog_eav_attribute.is_visible_on_front (products only) seems obvious, but also see visible
'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to (products only) which product types to apply to
'is_configurable' => false, // catalog_eav_attribute.is_configurable (products only) used for configurable products or not
'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by (products only) available in the 'sort by' menu
'position' => 0, // catalog_eav_attribute.position (products only) position in layered naviagtion
'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules (products only) available for use in promo rules
));
}

Categories

public function getCategoryImage(Mage_Catalog_Model_Category $category, $width = 350, $height = 350)
{
// 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
$rszImagePath = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category'
. DS . 'cache' . DS . $width . 'x' . $height . DS
. $category->getImage();
if (!file_exists($rszImagePath)) {
$image = new Varien_Image($imagePath);
$image->resize($width, $height);
$image->save($rszImagePath);
}
// return the image URL
return Mage::getBaseUrl('media') . '/catalog/category/cache/' . $width . 'x'
. $height . '/' . $category->getImage();
}

Category object from getChildrenCategories() has a limited amount of data, you will need to load the entire object with: $category->load($category->getId())

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)
->addAttributeToFilter('include_in_menu', 1)
->addIdFilter($parentCategory->getChildren())
->setOrder('position', Varien_Db_Select::SQL_ASC)
->joinUrlRewrite();
$this->categories = $categoryCollection;
}
return $this->categories;
}

Mage::registry('current_category');

$category->setIsActive(false);
or
$category->setIsActive(0);

$cat = Mage::getModel('catalog/category')->load(1);

$coll = Mage::getResourceModel('catalog/product_collection');
$coll->addCategoryFilter($cat);

Load category:

$Category=Mage::getModel('catalog/category')->load($cat);

OR:

$Category=Mage::registry('current_category');

And then get:

$name=$Category->getName();
$url=$Category->getUrl();
$image=$Category->getImageUrl();

Controller

<config>
  <frontend>
    <routers>
      <checkout>
        <args>
          <modules>
            <your_module before="Mage_Checkout">Your_Module</your_module>
          </modules>
        </args>
      </checkout>
    </routers>
  </frontend>
</config>

In an action controllers preDispatch() method you can stop dispatch by calling the following:

$this->setFlag('', self::FLAG_NO_DISPATCH, true);

If you were listening via an observer, the code would look like this:

public function someObserver(Varien_Event_Observer $observer)
{
$action = $observer->getEvent()->getControllerAction();
$action->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
}

Product

Mage::registry('current_product');

It's using setStockItem() from Mage_CatalogInventory_Model_Stock_Item::assignProduct() via the catalog_product_load_after event.

$product->getStockItem()->getQty();

Collection of in-stock products, or products which do not have stock management enabled on them

$productCollection = Mage::getResourceModel('catalog/product_collection');
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($productCollection);

3 methods you could use, all of which are in Mage_Catalog_Model_Product:

public function getUrlPath($category=null)
public function getUrlInStore($params = array())
public function getProductUrl($useSid = null)

Product whose URL key is "my-product" on the domain of http://domain.com the results are:

$product->getUrlPath();
    'my-product'
$product->getUrlPath($category);
    'category/my-product'
// you cannot stop this method adding ___store to the URL, even by setting _store_to_url to false
$product->getUrlInStore();
    'http://domain.com/category/my-product?___store=default'
// you cannot stop this method adding ___store to the URL, even by setting _store_to_url to false
// note - see the "using _ignore_category" section below for an arguable bug with using this param
$product->getUrlInStore(array('_ignore_category' => true));
    'http://domain.com/my-product?___store=default'
$product->getProductUrl();
    'http://domain.com/category/my-product'
$product->getProductUrl(true);
    'http://domain.com/category/my-product'

The short version - I would not use this param, and instead use Mage::getUrl($product->getUrlPath())

Breadcrumbs

Via code:

$crumbs = Mage::app()->getLayout->getBlock('breadcrumbs');
$crumbs->addCrumb('home', array(
    'label' => 'Home',
    'title' => 'Go to Home Page',
    'link' => Mage::getUrl('')
));

Via Layout XML:

<reference name="breadcrumbs">

    <action method="addCrumb">

        <crumbname>Home</crumbname>

            <crumbinfo>

                <label>Home</label>

                <title>Go to Home Page</title>

                <link>/</link>

            </crumbinfo>

        </action>

</reference>

<action method="addCrumb" translate="crumbinfo.label crumbinfo.title" module="cms">
    <crumbname>Home</crumbname>
        <crumbinfo>
            <label>Home</label>
            <title>Home</title>
            <link>/</link>
     </crumbinfo>
</action>

URL's

In PHTML-files:

Mage::getBaseUrl();

In CMS-pages or Static Blocks:<>

{{store url=""}}

In PHTML-files:

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

(A) Unsecure Skin Url :

$this->getSkinUrl('images/imagename.jpg');

(B) Secure Skin Url:

$this->getSkinUrl('images/imagename.gif', array('_secure'=>true));

In CMS-pages or Static Blocks:<>

{{skin url='images/imagename.jpg'}}

In PHTML-files :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

In CMS-pages or Static Blocks:

{{media url='/imagename.jpg'}}

In PHTML-files :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

In PHTML-files :

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

In CMS-pages or Static Blocks:

{{store url='mypage.html'}}

In PHTML-files :

$current_url = Mage::helper('core/url')->getCurrentUrl();

In PHTML-files :

$home_url = Mage::helper('core/url')->getHomeUrl();

Config Definition

<config>
  <global>
    <models>
      <namespace_module>
        <class>Namespace_Module_Model</class>
        <resourceModel>namespace_module_resource</resourceModel>
      </namespace_module>
      <namespace_module_resource>
        <class>Namespace_Module_Model_Resource</class>
        <entities>
          <some_entity>
            <table>namespace_module_some_entity</table>
          </some_entity>
        </entities>
      </namespace_module_resource>
    </models>
  </global>
</config>

EAV:

<config>
  <global>
    <resources>
      <namespace_module_setup>
        <setup>
          <module>Namespace_Module</module>
          <class>Mage_Eav_Model_Entity_Setup</class>
        </setup>
      </namespace_module_setup>
    </resources>
  </global>
</config>

FLAT:

<config>
  <global>
    <resources>
      <namespace_module_setup>
        <setup>
          <module>Namespace_Module</module>
          <class>Mage_Core_Model_Resource_Setup</class>
        </setup>
      </namespace_module_setup>
    </resources>
  </global>
</config>

<config>
  <global>
    <blocks>
      <namespace_module>
        <class>Namespace_Module_Block</class>
      </namespace_module>
    </blocks>
  </global>
</config>

Frontend:

<config>
  <frontend>
    <events>
      <the_name_of_the_event_to_observe>
        <observers>
          <namespace_module>
            <class>namespace_module/observer</class>
            <method>someMethod</method>
          </namespace_module>
        </observers>
      </the_name_of_the_event_to_observe>
    </events>
  </frontend>
</config>

------------------------------------------------------------------------------

Admin:

namespace_module/observer someMethod

------------------------------------------------------------------------------

Global (before area has been initialized):

<config>
  <global>
    <events>
      <the_name_of_the_event_to_observe>
        <observers>
          <namespace_module>
            <class>namespace_module/observer</class>
            <method>someMethod</method>
          </namespace_module>
        </observers>
      </the_name_of_the_event_to_observe>
    </events>
  </global>
</config>

<config>
  <crontab>
    <jobs>
      <cron_job_name>
        <schedule>
          <cron_expr>* * * * *</cron_expr>
        </schedule>
        <run>
          <model>your_module/model::batchTransactions</model>
        </run>
      </cron_job_name>
    </jobs>
  </crontab>
</config>

Frontend:

<config>
  <frontend>
    <layout>
      <updates>
        <namespace_module>
          <file>namespace-module.xml</file>
        </namespace_module>
      </updates>
    </layout>
  </frontend>
</config>

-------------------------------------------------------------------

Admin:

<config>
  <adminhtml>
    <layout>
      <updates>
        <namespace_module>
          <file>namespace-module.xml</file>
        </namespace_module>
      </updates>
    </layout>
  </adminhtml>
</config>

Data Base

SET FOREIGN_KEY_CHECKS=0;
TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;
SET FOREIGN_KEY_CHECKS=1;

Reindex

Reindex Via Code

An example of code qhich allows you to reindex:

$indexer = Mage::getSingleton('index/indexer');
$process = $indexer->getProcessByCode('catalog_product_price');
$process->reindexEverything();

The following are indexer codes which you can use instead of the catalog_product_price index above:

catalog_product_attribute     Product Attributes
catalog_product_price Product Prices
catalog_url Catalog URL Rewrites
catalog_product_flat Product Flat Data
catalog_category_flat Category Flat Data
catalog_category_product Category Products
catalogsearch_fulltext Catalog Search Index
cataloginventory_stock Stock Status
tag_summary Tag Aggregation Data

Reindex Via SSH

So if you have SSH-Access use the following codes:

//reindex all indexes:
php -f /shell/indexer.php reindexall

//reindex specific index:
php indexer.php --reindex catalog_product_attribute

Reindex Via Cron

/usr/bin/php /home/domainpath/shell/indexer.php --reindexall

General example:
/usr/local/bin/php /home/username/public_html/path/to/cron/script

Domain-specific example:
/usr/local/bin/ea-php99 /home/username/domain_path/path/to/cron/script