Saturday, January 7, 2012

Magento: create category attribute

Create Category attribute magento from code.
<?php
    define('MAGENTO', realpath(dirname(__FILE__)));
  
 require_once MAGENTO . '/app/Mage.php';
    Mage::app();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$setup->addAttribute('catalog_category', 'sliderurl',  array(
    'group'    => 'General',
    'type'     => 'varchar',
    'label'    => 'Slider Url',
    'input'    => 'text',
    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible'           => 1,
    'required'          => 0,
    'user_defined'      => 1,
    'default'           => '#'
));

?>

Thursday, January 5, 2012

Magento most viewed products

Magento most viewed products
http://blog.chapagain.com.np/magento-how-to-get-most-viewed-products/

Magento Layered Navigation in Drop-Down

Magento Layered Navigation in Drop-Down

It is very simple.
We just need to replace the contents of file
/app/design/frontend/default/your-magento-template/template/catalog/layer/filter.phtml
with

<select onchange="setLocation(this.value)">
  <option value=""><?php echo 'Choose an Option...' ?></option>
<?php foreach ($this->getItems() as $_item): ?>
    <option
        <?php if ($_item->getCount() > 0): ?>
        value="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?>
        <?php else: echo '>' . $_item->getLabel() ?>
        <?php endif; ?>
        (<?php echo $_item->getCount() ?>)
    </option>
<?php endforeach ?>
</select>
and you are done.

Wednesday, January 4, 2012

Search magento function

Search magento function 
http://magento-php-xref.tech-resolved.com/nav.html?_functions/index.html
http://magento.itx-technologies.com/nav.php?app/code/core/Mage/Adminhtml/Block/Report/Product/Viewed/Grid.php.source.php

Magento : Add custom image attribute to category

 Magento : Add custom image attribute to category

Just copy paste the below code in header.phtml and run yourmagento once, your attribute will be created and you can see in backend under manage category. After you are done remove this code again.

 ------------------------------------------------------------------------------------------
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$setup->addAttribute('catalog_category', 'sliderimage', array(
    'group'         => 'General',
    'input'         => 'image',
    'type'          => 'varchar',
    'label'         => 'Slider Image',
    'backend'       => 'catalog/category_attribute_backend_image',
    'visible'       => 1,
    'required'        => 0,
    'user_defined' => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
------------------------------------------------------------------------------------------

Tuesday, January 3, 2012

Magento Admin tutorial video part-1

 Magento Admin tutorial video part-1
<iframe src="http://player.vimeo.com/video/2486600?title=0&amp;byline=0&amp;portrait=0" width="400" height="206" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe><p><a href="http://vimeo.com/2486600">Magento - a quick review of the admin area</a> from <a href="http://vimeo.com/stastic">Shayne Sanderson</a> on <a href="http://vimeo.com">Vimeo</a>.</p>

Monday, January 2, 2012

Export Categories Magento

 <?php
  //Export Categories Magento
//Upload this file in root and access from url.
//Exported file will be stored in var/import

    define('MAGENTO', realpath(dirname(__FILE__)));
    require_once MAGENTO . '/app/Mage.php';
    Mage::app();

    $category = Mage::getModel ( 'catalog/category' );
    $tree = $category->getTreeModel ();
    $tree->load ();

    $ids = $tree->getCollection ()->getAllIds ();

    if ($ids) {
        $file = "var/import/catwithid.csv";
        file_put_contents($file,"catId, catName\n");
        foreach ( $ids as $id ) {
          $string = $id . ', ' .$category->load($id)->getName() . "\n";
            file_put_contents($file,$string,FILE_APPEND);
        }
    }
   
    ?>