How to add polls in magento page

You need to edit app/design/frontend/default/default/layout/poll.xml

<reference name="right">
        <block type="poll/activePoll" name="right.poll">
            <action method="setPollTemplate"><template>poll/active.phtml</template><type>poll</type></action>
            <action method="setPollTemplate"><template>poll/result.phtml</template><type>results</type></action>
        </block>
</reference>

Change referance name as per your requirement. Hope this helps..

 

, ,

Leave a comment

How to get child category of current category

Try with this code,

$this->getCurrentCategory()->getChildrenCategories();

Leave a comment

Get customer email on success page + magento

Use thi code

<?php
   $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
   echo $order->getCustomerEmail();
?>

Leave a comment

How to display product attribute on product page + magento

Add the following code to your catalog/product/view.phtml or catalog/product/list.html template files:

echo $_product->getAttributeText(‘your_attribute_code’);

Just change out ‘your_attribute_code’ with your attribute code and you’re done.

, , , ,

Leave a comment

How to add static block in sidebar + magento

Use this below code

 

<layout version="0.1.0">
    <default>
        <reference name="right">
            <block type="cms/block" name="your-block-identifier" before="-">
                <action method="setBlockId"><block_id>your-block-identifier</block_id></action>
            </block>
        </reference>
    </default>
</layout>

 

Leave a comment

How to add a lightbox effect in Magento product image switcher?

I have integrated a thickbox in my magento just by using in an tag..

 <?php     $_product = $this->getProduct();     $_helper = $this->helper('catalog/output');     $_gallery = $this->getGalleryImages();     $_resize = 350; ?> <style type="text/css">     .product-img-box .more-views li.slide-current a{ border:2px solid #aaa; }     .product-img-box .product-image-zoom img { cursor: pointer; }     #slide-loader{ visibility:hidden; position:absolute; top:auto; left:auto; right:2px; bottom:2px; width: 25px; height: 25px; } </style> <script type="text/javascript"> function slide(url,num,gallery){     if (typeof slide.loading == 'undefined') slide.loading = false;     if(slide.loading) return false;     var loader = new Image();     $(loader).observe('load', function(){         $('slide-loader').setStyle({'visibility':'hidden'});         $$('div.more-views li').each(function(el,i){             (i==num) ? el.addClassName('slide-current') : el.removeClassName('slide-current');         });         var dummy = new Element('img', { src: url }).setOpacity(0);         new Insertion.After('image', dummy);         new Effect.Opacity(dummy, { duration:.5, from:0, to:1.0 });         new Effect.Opacity($('image'), { duration:.5, from:1.0, to:0,              afterFinish: function(){                 $('image').writeAttribute('src',url).setOpacity(1).observe('click',function(e){                     Event.stop(e);                     popWin(gallery, 'gallery', 'width=300,height=300,left=50,top=50,location=no,status=yes,scrollbars=yes,resizable=yes');                     return false;                  })                 dummy.remove();                 slide.loading = false;              }         });     });     $('slide-loader').setStyle({'visibility':'visible'});     loader.src=url;     slide.loading = true; return false; } </script> <p class="product-image-zoom">     <?php         $_img = '<a href="'.$this->helper('catalog/image')->init($_product, 'image').'" title="'.$this->htmlEscape($this->getImageLabel()).'"><img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" /></a>';         echo $_helper->productAttribute($_product, $_img, 'image')     ?>     <img id="slide-loader" src="<?php echo $this->getSkinUrl('images/lightbox/loading.gif') ?>" /> </p> <!-- <p id="track_hint"><?php echo $this->__('Click on above image to view full picture') ?></p> --> <?php if (count($_gallery) > 0): ?> <div class="more-views">     <h4><?php echo $this->__('More Views') ?></h4>     <ul>     <?php foreach ($_gallery as $_image): ?>         <li>             <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(65); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>         </li>     <?php endforeach; ?>     </ul> </div> <?php endif; ?> 

Leave a comment

Create Custom Category Attribute

Step 1: Creating A New Attribute

magento_add_attributeFirst off, we need to create a new attribute. Simply do so in the Admin under Catalog > Attributes > Manage Attributes. I’ll call my attribute category_test but you can call it anything you like. Keep in mind that it must be unique and can’t contain spaces or non alphanumeric characters. Set the Scope to what you need. If you have a multi-store setup and want it to be different for each store, leave it at Store View. Otherwise set it to Website or Global depending on your needs. Set Apply To to All Product Types. Specify all the Attribute Properties but set all Frontend Properties except Allow HTML Tags on Frontend to “No”.

Specify at least the Admin label under the Manage Label / Options tab. This is what will be displayed as the title in the backend as well as each store view on the frontend.

magento_add_attribute_label

Please note that you will not be able to make any changes to this attribute through the backend after you continue with step 2. Double check to make sure your settings are correct.

Save the attribute and write down the attribute_id. You can find the attribute’s id by hovering over the row in the grid and reading it from the link which is displayed in the tool tip. My attribute_id is 954. (Yours will be different, of course)

Step 2: Looking Up the Correct Attribute Entity Type ID, Attribute Set ID and Attribute Group ID In the Database

First we need to open the Magento database in a database management tool, like phpMyAdmin, and open the table eav_entity_type. Search for the row containing catalog_category in the field entity_type_code and write down the entity_type_id.

SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_category';

In my case it is 9. Yours will most likely be different, depending on what version of Magento you started your store with.

Now open the table eav_entity_attribute and find a row that has the entity_type_id set to the entity_type_id that we just looked up.

SELECT attribute_set_id, attribute_group_id FROM eav_entity_attribute WHERE entity_type_id = [YOUR entity_type_id here];

Write down the attribute_set_id and the attribute_group_id values. Look at several rows and make sure they contain the same attribute_group_id values, as you could have multiple category attribute groups in your setup.

My setup has three different attribute_group_id‘s: 7, 166 and 167. These group id’s are actually the tabs the attributes appear under when you edit a category. If you have several ID’s, pick the lowest attribute_group_id, as this is most likely the “General Information” tab. In my case this is 7.

Step 3: Changing the entity_type_id of the Attribute

Next open the table eav_attribute. Now that we know what entity_type_id our new attributes needs to have, we must change it to the entity_type_id we looked up above.

UPDATE eav_attribute SET entity_type_id = [YOUR entity_type_id] WHERE attribute_id = [YOUR attribute_id];

For me, the SQL statement looks like this:

UPDATE eav_attribute SET entity_type_id = 9 WHERE attribute_id = 954;

Step 4: Creating an Entry In the eav_entity_attribute Table

Now we need to create a new entry in the eav_entity_attribute table. To do so, use your database management tool’s editor or use the following SQL statement:

INSERT INTO eav_entity_attribute (entity_type_id, attribute_set_id, attribute_group_id, attribute_id, sort_order) VALUES ([YOUR entity_type_id], [YOUR attribute_set_id], [YOUR attribute_group_id], [YOUR attribute_id], 0);

Use the entity_type_id, attribute_set_id, attribute_group_id and attribute_id values you looked up earlier instead of the placeholders.

For my setup, the SQL statement looks like this:

INSERT INTO eav_entity_attribute (entity_type_id, attribute_set_id, attribute_group_id, attribute_id, sort_order) VALUES (9, 12, 7, 954, 0);

Step 5: Changing the Sort Order

Because we added this attribute to the database by hand, we need to set the proper sort order so it appears in the right place on the category edit page. Go to Catalog > Manage Categories and edit any category in the Admin and you will find the newly created attribute at the very first position. You can change the sort order for your attribute by changing the sort_order field in the eav_entity_attribute table. Keep in mind that the sort_order can have missing and duplicate values.

Displaying the Attribute On the Category View Page (Optional)

Now that we have our custom category attribute, we can display it on the category view page. First we check if the theme you are using already has the file /app/design/frontend/default/YOUR THEME NAME/template/catalog/category/view.phtml. If you can’t find the file you must copy it to your theme’s /template/catalog/category directory from /app/design/frontend/base/default/template/catalog/category/view.phtml.

Now open the file in your editor of choice and add these lines anywhere you want to display the attribute’s value:

<?php $_my_category_attribute = $_category->getData('category_test');    if($_my_category_attribute): echo $_my_category_attribute; endif; ?>

Of course you need to change ‘category_test‘ to whatever you set your attribute code to.

As allways, refresh your cache or disable it while you make changes to ensure you are actually looking at the real thing and not some phantom.

That’s it. If you have any trouble, post a comment and I’ll try to help you figure it all out.

Leave a comment

Display Brand Logo (attribute) of a product depending on the Brand Name

<!– ##### CODE TO SET THE BRAND LOGO USING BRAND NAME ##### –>
<div>
<?php $brandname = $_product->getbrand_name() ?>
<img src=”<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . “brandlogo/” .$brandname . “.png”; ?>” />
</div>

I just fetched the brand name and put it inside a variable and then fetched the image using Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)

reference:
http://www.magentocommerce.com/boards/viewthread/9701/
http://activecodeline.com/retrieving-url-paths-in-magento

Leave a comment