Monday, September 12, 2011

How to add extra field in review form in magento

I have added 3 extra field in review form
just go to the frontend\base\default\template\review/form.phtml
add three field as other text field.
now go to app\code\core\Mage\Review\Model\Mysql4\Review.php
protected function _afterSave(Mage_Core_Model_Abstract $object)
{

$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'email' => $object->getEmail(), //this field add by sourav
'fname' => $object->getFname(), //this field add by sourav
'lname' => $object->getLname(), //this field add by sourav
);
now add email,fname,lname in the review_detail table in the database
also go to app\code\core\Mage\Adminhtml\Block\Review\Edit\Form.php also add

$fieldset->addField('fname', 'text', array( //this field add by sourav
'label' => Mage::helper('review')->__('First Name'),
'required' => true,
'name' => 'fname'
));

$fieldset->addField('lname', 'text', array( //this field add by sourav
'label' => Mage::helper('review')->__('Last Name'),
'required' => true,
'name' => 'lname'
));

$fieldset->addField('email', 'text', array( //this field add by sourav
'label' => Mage::helper('review')->__('Email'),
'required' => true,
'name' => 'email'
));

before
$fieldset->addField('nickname', 'text', array(
'label' => Mage::helper('review')->__('Nickname'),
'required' => true,
'name' => 'nickname'
));

Tuesday, August 23, 2011

Show product video in magento product details page

Here’s the sequence of steps we’re going to take:
1. Create a product attribute for the video code.

Log in to your Magento Admin Panel. Navigate to Catalog > Attributes > Manage Attributes. Click on the “Add New Attribute” button found close to the top-right hand corner of the screen. The first tab that’s open is the *Properties* tab. You are presented with lots of textboxes and dropdowns.

- Attribute Code: video
- Scope: Global
- Catalog Input Type of Store Owner: Text Area
- Default Value: [leave blank]
- Unique Value: No
- Values Required: No
- Input Validation for Store Owner: None
- Apply To: All Product Types

- Use in quick search: No
- Use in advanced search: No
- Comparable on Front-end: No
- Use in Layered Navigation: No
- Use in Search Results Layered Navigation: No
- Use for Price Rule Conditions: No
- Position: 0
- Enable WYSIWYG: Yes
- Allow HTML-tags on Front-end: Yes
- Visible on Product View Page on Front-end: No
- Used in product listing: No
- Used for sorting in product listing: No

--------------------------------------------------------
Then navigate to the *Manage Label / Options* tab. You only have to fill in the "Admin" value, and for this use "Video". This can be changed later if you need to.
Click the "Save Attribute" button to save the attribute.


2. Assign the newly created attribute to an attribute set (likely Default)

While still in the Admin Panel, navigate to Catalog > Attributes > Manage Attribute Sets. From the right-hand column, labeled "Unassigned Attributes", drag our new video attribute to the "General" group found in the middle column.
Click "Save Attribute Set" button to save the attribute set.

3. Now create a video.phtml And save the file as /app/design/frontend/[your-package]/[your-theme]/template/catalog/product/view/

<?php $_product = $this->getProduct(); ?>
<?php $video = $_product->getData('video'); ?>
<?php if( $video !='' ){ ?>
<h2>Product Video</h2>
<div class="products">
<?php //echo( Mage::getBaseDir('media').'\\'. $video); ?>
<?php if( file_exists( Mage::getBaseDir('media').'\\'. $video) )
{
?>
<div id="mediaspace">&nbsp;</div>
<script src="http://code.jquery.com/jquery-1.6.1.js"></script>
<script>
$( document ).ready( function(){
$.getScript( '<?php echo $this->getSkinUrl('videos/mediaplayer/swfobject.js'); ?>', function(){
var so = new SWFObject('<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); ?>
/frontend/default/default/videos/mediaplayer/player.swf','ply','470','320','9','#ffffff');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.addParam('wmode','opaque');
so.addVariable('file','<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA). $video; ?>');
so.write('mediaspace');
} );
} );
</script>
<?php } ?>
</div>
<?php } ?>


4. Open up /app/design/frontend/[your-package]/[your-theme]/layout/catalog.xml and add this line:
<block type="catalog/product_view" name="product_video" as="product_video" template="catalog/product/view/video.phtml"/>
under
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
this block.

5. catalog/product/view.phtml

Open up /app/design/frontend/[your-package]/[your-theme]/catalog/product/view.phtml and add this line:
getChildHtml('product_video'); ?>
6. Obtain and upload a copy of the free JWPlayer

Download the player from: http://www.longtailvideo.com/players/jw-flv-player/
After you download the ZIP file, extract and upload the files using an FTP client to: /skin/frontend/[your-package]/[your-theme]/videos/*
With the FTP client, rename the “mediaplayer-viral” folder to "mediaplayer"

7. now just write your video file location like:- wysiwyg/product1.flv

Friday, August 5, 2011

Currency drop down selector in header, Magento

Step 1

You will need to create a new directory, named “directory” and create a new file called “currency-top.phtml“:


/app/design/frontend/template/default/YOUR-TEMPLATE-NAME/template/directory/currency-top.phtml and write the following code in it :-


<?php if($this->getCurrencyCount()>1): ?>

<div class="box language-switcher" style="margin-left:15px">

<label for="select-language">Your Currency: </label>

<select name="currency" onchange="changeCurrency(this)">

<?php foreach ($this->getCurrencies() as $_code => $_name): ?>

<option value="<?php echo $_code ?>"<?php if($_code==$this->getCurrentCurrencyCode()): ?> selected="selected"<?php endif; ?>>

<?php echo $_name ?> - <?php echo $_code ?>

</option>

<?php endforeach; ?>

</select>

</div>

<script type="text/javascript">

//<![CDATA[

function changeCurrency(sObject){

if(sObject.value){

setLocation('<?php echo $this->helper('directory/url')->getSwitchCurrencyUrl() ?>currency/'+sObject.value);

}

}

//]]>

</script>

<?php endif; ?>




Step 2


/app/design/frontend/template/default/YOUR-TEMPLATE-NAME/layout/page.xml


Add currency_top block after store_language block inside header block of page.xml present around line #66 :-


<block type="page/html_header" name="header" as="header">

<block type="page/template_links" name="top.links" as="topLinks"/>

<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>

<block type="directory/currency" name="currency_top" template="directory/currency-top.phtml"/>

<block type="core/text_list" name="top.menu" as="topMenu"/>

</block>




Step 3:


Add getChildHtml(‘currency_top’) below getChildHtml(’store_language’) in


/app/design/frontend/template/default/YOUR-TEMPLATE-NAME/template/page/html/header.phtml like below :-


<?php echo $this->getChildHtml('store_language') ?>

<?php echo $this->getChildHtml('currency_top') ?>

Friday, July 29, 2011

Show subcategory in a category page

If you're comfortable editing your theme, this code snippet will bring you a list of all sub-categories of the current category (from the session, so this should work anywhere in your theme). I typically use this in app/design/frontend/default/*theme_name*/template/catalog/category/view.phtml

<?php
$_category  
= $this->getCurrentCategory();
$collection
= Mage::getModel('catalog/category')->getCategories($_category->entity_id);
$helper    
= Mage::helper('catalog/category');
?>

<ul>
   
<?foreach ($collection as $cat):?>
               
<?php if($_category->getIsActive()):?>
               
<?php
                     $cur_category
= Mage::getModel('catalog/category')->load($cat->getId());
                     $_img
= $cur_category->getImageUrl();  
               
?>
               
<li>
                                <a href="
<?php echo $helper->getCategoryUrl($cat);?>">
                                     <img src="
<?php echo $_img?>" title="$cat->getName()"/>
                                     
<cite><?php echo $cat->getName();?></cite>
                               
</a>
                       
</li>
               
<?php endif?>
   
<?php endforeach;?>
</ul>

Wednesday, July 27, 2011

Magento form validation from js

I have work on Contact us page in magento. I have add some extra field in the contact us page.like Country, Subject etc.
If you want to make the field mandatory then must give the id name same with name and add class="input-text required-entry" then the field automatically validate from the js file.

Monday, July 25, 2011

Change category page layout

Generally category page in magento lies in 3 columns. if you want to change it then you have to do a simple thing. just go to the "catalog.xml" in your "layout" folder and add the following code

<reference name="root">

<action method="setTemplate"><template>page/2columns-left.phtml</template> </action>

</reference>

in the line 81 under
<catalog_category_default translate="label">

<label>Catalog Category (Non-Anchor)</label>

Friday, July 22, 2011

Magento: Display Categories in Sidebar

Magento: Display Categories in Sidebar


It seems my posts lately are always in relation to solving a problem or answering a question for someone else. If you’re looking for a way to display categories in the sidebar, change category display, or create a category menu then this post is probably for you.


Creating the Block


The first thing you need to do is create a block in your layout. Navigate to /app/design/frontend/default/default/layout/catalog.xml


The first thing in your layout is a definition of the default layout noted by the comment “Default layout, loads most of the pages” depending on where you want to put your category nav (right sidebar, left sidebar, footer, etc) you’ll need to define the block a little differently. I’m going to do it with the left sidebar so you see what’s going on.





<reference name="left"> 
<block type="catalog/navigation" name="catalog.leftnav"
template="catalog/navigation/left_nav.phtml" />
</reference>



Okay, so what i did was locate the left sidebar which is referenced simply as “left” inside those tags i define my block type and template. The next thing you’ll want to do is create that template file, note that i defined it within /app/design/frontend/default/default/template/catalog/navigation/left_nav.phtml so i will need to create that file.


Creating the Template


Once I’ve created the file, it’s time to put in my code to populate my links automatically of all my categories:




<h2>Browse</h2>
<div class="block">
<ul id="nav_category" class="nav_category">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>
</div>
<?php echo $this->getChildHtml('topLeftLinks') ?>



If you want to take this a step further, you can target subcategories based on current page with this little script





<?php  $obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li class="current"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";
foreach ($obj->getCurrentChildCategories() as $subcat)
{
echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
}
echo "</ul>\n</li>\n";
} else {
echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>\n";
}
}
?>