Design elements, playground and code snippets for Magento eCommerce System

Mage::Snipp in a snippet database for web designers and web developers using magento ecommerce platform to realise and develop ecommerce projects.

Search snippets by keyword

Latest snippets

View all 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); ?>

<ul id="manufacturer_list">
<?php foreach ($manufacturers as $manufacturer): ?>
<li>
<a href="http://www.yourdomain.com/catalogsearch/advanced/result/?manufacturer[]=<?php echo $manufacturer['value'] ?>">
<?php echo $manufacturer['label'] ?>
</a>
</li>
<?php endforeach; ?>
</ul>

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()) { ... }