show manufacturer on Home Page


<?php
$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>

<?php foreach ($manufacturers as $manufacturer): ?>
<?php  $bid = $manufacturer[‘value’]; ?>
<?php /*?><li><a href=”<?php echo $currentUrl ?>?manufacturer=<?php echo $manufacturer[‘value’] ?>”><?php echo $manufacturer[‘label’] ?><?php echo $manufacturer[‘value’] ?></a></li><?php */?>

<?php
$products = Mage::getModel(‘catalog/product’)->getCollection();
$products->addAttributeToFilter(‘manufacturer’, array(‘in’ => array($bid)));
$products->addAttributeToSelect(‘*’);
$products->load(); ?>

<li><?php echo $manufacturer[‘label’] ?>(<?php echo $products->count() ?>) </li>

<ul class=”brand-products”>
<?php
$i = 0;
foreach($products as $_prod)
{
echo $_cat_name = $_prod->getCategory(); ?>

<li>
<a href=”<?php echo $_prod->getProductUrl() ?>” title=”<?php echo $this->stripTags($this->getImageLabel($_prod, ‘small_image’), null, true) ?>” class=”product_img_link”><img src=”<?php echo $this->helper(‘catalog/image’)->init($_prod, ‘small_image’)->resize(200); ?>” width=”200″ height=”200″ alt=”<?php echo $this->stripTags($this->getImageLabel($_prod, ‘small_image’), null, true) ?>” />
<a href=”<?php echo $_prod->getUrlPath() ?>”><?php echo $_prod->getName()?>
<?php echo $_cat_name; ?></a>
<span class=”price”><?php echo $_prod->getFormatedPrice()?></span>

</li>
<?php } ?>
</ul>

<?php endforeach; ?>
</ul>

<?php /*?><select class=”choose-sel” name=”computer_manufacturers” id=”brand_name” onchange=”submit();”>
<option value=”select”>choose your brand</option>
<?php foreach ($manufacturers as $manufacturer): ?>
<option value=”<?php echo $manufacturer[‘value’] ?>”><a href=”<?php echo $currentUrl ?>?manufacturer=<?php echo $manufacturer[‘value’] ?>”><?php echo $manufacturer[‘label’] ?></a></option>
<?php endforeach; ?>
</select><?php */?>

<?php /*?><?php
$bid = 5; // the brand / manufacturer ID

$products = Mage::getModel(‘catalog/product’)->getCollection();
$products->addAttributeToFilter(‘manufacturer’, array(‘in’ => array($bid)));
$products->addAttributeToSelect(‘*’);
$products->load();
echo $products->count() ?>

<ul class=”brand-products”>
<?php
$i = 0;
foreach($products as $_prod)
{
echo $_cat_name = $_prod->getCategory(); ?>

<li>
<a href=”<?php echo $_prod->getProductUrl() ?>” title=”<?php echo $this->stripTags($this->getImageLabel($_prod, ‘small_image’), null, true) ?>” class=”product_img_link”><img src=”<?php echo $this->helper(‘catalog/image’)->init($_prod, ‘small_image’)->resize(200); ?>” width=”200″ height=”200″ alt=”<?php echo $this->stripTags($this->getImageLabel($_prod, ‘small_image’), null, true) ?>” />
<a href=”<?php echo $_prod->getUrlPath() ?>”><?php echo $_prod->getName()?>
<?php echo $_cat_name; ?></a>
<span class=”price”><?php echo $_prod->getFormatedPrice()?></span>

</li>
<?php } ?>
</ul><?php */?>

empty Attributes not displaying product detail page magento


open the file /app/design/frontend/default/[theme name]/template/catalog/product/view/attribute.phtml
<?php foreach ($_additional as $_data): ?>
    <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
    if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
    <?php } ?>
<?php endforeach; ?>

How to Add Date Picker in Magento Config Page


System.xml
<my_date translate="label comment">
 <label>Expire On</label>
 <frontend_type>text</frontend_type> <!-- Set the frontend type as Text -->
 <frontend_model>MODULE_NAME/adminhtml_system_config_date</frontend_model> <!-- Specify our custom model -->
 <sort_order>4</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 <comment>Set the expiry date for the Feature Tour</comment>
</my_date>


Create the new model file at the path:
appcodelocal<NAMESPACE><MODULE>BlockAdminhtmlSystemConfigDate.php

<?php
class Arvtour_Tour_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field
{
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $date = new Varien_Data_Form_Element_Date;
        $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);

        $data = array(
            'name'      => $element->getName(),
            'html_id'   => $element->getId(),
            'image'     => $this->getSkinUrl('images/grid-cal.gif'),
        );
        $date->setData($data);
        $date->setValue($element->getValue(), $format);
        $date->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
        $date->setForm($element->getForm());

        return $date->getElementHtml();
    }
}

contact form upload file in magento


As i know this is not a good way, but really a fast hack if you want to attach a file with contact us form.

1. Edit your form.phtml under ‘/app/design/frontend/[your-interface]/[your-theme]/template/contacts/form.phtm ‘ and add ‘enctype=”multipart/form-data”‘

1
<form action="<?php echo $this->getFormAction(); ?>" id="contactForm" method="post" enctype="multipart/form-data">

add file upload field

1
<input name="attachment" id="attachment" class="input-text" type="file" />

Now edit your contacts controller ‘\app\code\core\Mage\Contacts\controllers\IndexController.php’
first find near line 91-93

1
2
3
if ($error) {
       throw new Exception();
}

Add this after this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$fileName = '';
               if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') {
                   try {
                       $fileName       = $_FILES['attachment']['name'];
                       $fileExt        = strtolower(substr(strrchr($fileName, ".") ,1));
                       $fileNamewoe    = rtrim($fileName, $fileExt);
                       $fileName       = preg_replace('/\s+', '', $fileNamewoe) . time() . '.' . $fileExt;
                       $uploader       = new Varien_File_Uploader('attachment');
                       $uploader->setAllowedExtensions(array('zip', 'jpg','pdf', 'rar', 'png', 'eps', 'ai'));
                       $uploader->setAllowRenameFiles(false);
                       $uploader->setFilesDispersion(false);
                       $path = Mage::getBaseDir('media') . DS . 'contacts';
                       if(!is_dir($path)){
                           mkdir($path, 0777, true);
                       }
                       $uploader->save($path . DS, $fileName );
                   } catch (Exception $e) {
                       $error = true;
                   }
               }

And after

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

Add this

1
2
3
4
5
6
$attachmentFilePath = Mage::getBaseDir('media'). DS . 'contacts' . DS . $fileName;
               if(file_exists($attachmentFilePath)){
                   $fileContents = file_get_contents($attachmentFilePath);
                   $attachment   = $mailTemplate->getMail()->createAttachment($fileContents);
                   $attachment->filename = $fileName;
               }

That’s it, enjoy email attachement

Display Image Category above 2 columns left page


The category banner (image) comes from template/catalog/category/view.phtml like this

if ($_imgUrl = $_category->getImageUrl()) { $_imgHtml = '<div class="category-image-container"><div class="category-image-container-inner"><p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p></div></div>'; $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image'); } first comment this

Then in template/page/2columns-left.phtml between<div class="main"> and <div class="col-left"><?php echo $this->getChildHtml('left') ?></div>

write the category banner code

<?php   
        $_category  = Mage::registry('current_category');
        if($_category){
         $_helper    = Mage::helper('catalog/output');

            $_imgHtml   = '';
            if ($_imgUrl = $_category->getImageUrl()) {
           echo   $_imgHtml = '<div class="category-image-container1"><div class="category-image-container-inner"><p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p></div></div>';
                $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
            }
        }
        ?>

This will show the category banner above the left column and the content.

How to remove index.php URLs in Magento


1) Login to admin section by using the URL

http://domain.com/index.php/admin

2) then go to “System >>  Configuration >>Web >> Search Engines Optimization”
Use Web Server Rewrites : YES

3) Go to “System >>  Configuration >>Web >>Secure”

Use secure URL Frontend: YES

4)Then create the .htaccess file under your the magento installed folder.

If the magento installed under document root ( /home/username/public_html) then add follogig rules into .htaccess file

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

and If the magento installed under /shop or directory then add the following rules into ” /home/username/public_html/shop/.htaccess ” file.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
</IfModule>

Unable to process payment. Please contact the merchant as the shipping address provided by the merchant is invalid, and the merchant has requested that your order must be shipped to that address.


In Magento Community 1.7.0.2 you need to copy the file:
/app/code/core/Mage/Paypal/Model/Api/standard.php

to:
/app/code/local/Mage/Paypal/Model/Api/standard.php

and change line 238 from:
$request[‘address_override’] = 1;

to:
$request[‘address_override’] = 0;