Magento Snippets

Display product tax class

Description

Show the product tax class name

Code

$taxClassId = $_product->getTaxClassId();
$taxClass = Mage::getModel('tax/class')->load($taxClassId);
$taxClassName = $taxClass->getClassName();

Shop by brand

Description

Shop by brand, for example in the sidebar.

Code

$product = Mage::getModel('catalog/product');

$attributes = Mage::getResourceModel('eav/entity_attribute_collection')->setEntityTypeFilter($product->getResource()->getTypeId())->addFieldToFilter('attribute_code', 'manufacturer');

$attribute = $attributes->getFirstItem()->setEntity($product->getResource());

$manufacturers = $attribute->getSource()->getAllOptions(false); ?>

Upload files

Description

How to upload files in magento

Code

    if (isset($_FILES['logo']['name']) && $_FILES['logo']['name'] != '') {  
        try {  
            $uploader = new Varien_File_Uploader('logo');  
            $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));  
            $uploader->setAllowRenameFiles(false);  
            $uploader->setFilesDispersion(false);  
            $path = Mage::getBaseDir('media') . DS;  
            // $path = Mage::getBaseDir('media') . DS . 'logo' . DS;  
            $logoName = $_FILES['logo']['name'];  
            $uploader->save($path, $logoName);  
        
        } catch (Exception $e) {  
        
        }  
    }  

Skin URL

Description

Skin URL

Code

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

Hersteller anzeigen

Description

Hersteller anzeigen

Code

echo $_product->getAttributeText('manufacturer');

How to check for https

Description

How to check for https

Code

if (!Mage::app()->getStore()->isCurrentlySecure()) { ... }

Sending transactional emails

Description

Sending transactional emails

Code

$email = Mage::getModel('core/email_template');

$email->sendTransactional(
    'some_email_template',                                                 // template
    array('name' => 'Your Company', 'email' => 'contact@yourcompany.com'), // sender details
    'joe@joebloggs.com',                                                   // recipient email
    'Joe Bloggs',                                                          // recipient name
    array('customerName' => 'Joe Bloggs'),                                 // merge vars
    Mage::app()->getStore()->getStoreId()                                  // store id
);

Display store contact name and email

Description

Display store contact name and email

Code

// General Contact
$name =  Mage::getStoreConfig('trans_email/ident_general/name'); 
$email = Mage::getStoreConfig('trans_email/ident_general/email');

// Sales Representative
$name =  Mage::getStoreConfig('trans_email/ident_sales/name'); 
$email = Mage::getStoreConfig('trans_email/ident_sales/email');

// Customer Support
$name =  Mage::getStoreConfig('trans_email/ident_support/name'); 
$email = Mage::getStoreConfig('trans_email/ident_support/email');

// Custom Email 1
$name =  Mage::getStoreConfig('trans_email/ident_custom1/name'); 
$email = Mage::getStoreConfig('trans_email/ident_custom1/email');

// Custom Email 2
$name =  Mage::getStoreConfig('trans_email/ident_custom2/name'); 
$email = Mage::getStoreConfig('trans_email/ident_custom2/email');

Changing the admin theme

Description

Changing the admin theme in local xml

Code


    
        
            
                 
                     yourtheme
                 
            
        
    

Adding a css class to body tag

Description

Adding a class via layout XML

Code


    my_class_name