Follow by Email

Tuesday, December 13, 2011

I want to show two specific categories on all other category pages, so I wrote this in the end of /template/catalog/product/list.phtml

I used this code:
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getName(); ?>
<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getId(); ?>

Friday, November 11, 2011

Delete all product from cart

I have add a function in the app\code\core\Mage\Checkout\controllers\CartController.php


if you call this it will delete all item in the cart.


the url should be http://www.yoursite.com/index.php/checkout/cart/deleteall/


public function deleteallAction()
    
{
        $cartHelper 
Mage::helper('checkout/cart');
        
$items $cartHelper->getCart()->getItems();       
        foreach (
$items as $item)
        
{
                $itemId 
$item->getItemId();
                
$cartHelper->getCart()->removeItem($itemId)->save();
        
}
        $this
->_redirectReferer(Mage::getUrl('*/*'));
    
}

Wednesday, November 9, 2011

Get all product name

foreach(Mage::getModel(‘catalog/product’)->getCollection()->getData() as $product)
{
echo Mage::getModel(‘catalog/product’)->load($product['entity_id'])->getName();
}

Saturday, October 29, 2011

Magento order id Increment

I had a problem that when i insert old order in to my new magento site it showing in the admin but when new order come then order id make some problem. like i had 185 order which order id was 100000421 and when new order comes then order id become 100000024.
That was a problem to me. then i go to the database find the table "eav_entity_store" and change increment_last_id in to 100000422. after doing that new order come with order id 100000422.

Tuesday, October 25, 2011

If you’re working with Magento Commerce you’ll most likely want to remove index.php from the URL when you go live

go to :
1) System
2) Configuration
3) Web:
secure:
Use secure URL Frontend: YES

4) edit:
http://mysite.com/.htaccess

############################################
## you can put here your magento root folder
## path relative to web root

RewriteBase /

Wednesday, September 28, 2011

How to get product image in magento

If you have the product collection object like
$collection = Mage::getModel('catalog/product')->getCollection();

Now you can get product sku using $_product->getSku()
if you can't get image path with
echo $this->helper('catalog/image')->init($_product,'small_image')->resize(135);
or $_product->getImageUrl()

then you can add a little code
$model = Mage::getModel('catalog/product');
$prod = $model->loadByAttribute('sku', $_product->getSku());
Now you can get product url with this
$prod->getImageUrl();

Tuesday, September 13, 2011

Send mail from magento

$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail('Youe Email');
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject('Mail Subject');
$mail->setFromEmail('Sender Mail Id');
$mail->setFromName("Msg to Show on Subject");
$mail->setType('html');// YOu can use Html or text as Mail format
$mail->send();
?>

also you can use

$emailTemplate  = Mage::getModel('core/email_template')->load(1);   //1 is Transactional Emails id
$emailTemplate->setSenderEmail('sapnandu@gmail.com');
$emailTemplate->setSenderName('Sapnandu');
$emailTemplate->send('sourav.m@gsl.in','John', '');

look on
http://stackoverflow.com/questions/5595202/sending-e-mail-programmatically-in-magento-is-failing

Monday, September 12, 2011

How to add Product review in product page

$storeId = Mage::app()->getStore()->getId();

$summaryData = Mage::getModel('review/review')->getCollection()->addStoreFilter($storeId)->addStatusFilter('approved')->addEntityFilter('product', $_product->getId())->setDateOrder();
foreach ($summaryData as $_review){
echo $_review->getTitle(). ' Review by '.$_review->getNickname().'
'.$_review->getDetail();
}

?>

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";
}
}
?>


Thursday, July 21, 2011

Wednesday, July 13, 2011

How to show all product in a category page

In the magento 1.5 if you want to see all the product in a category in the same page then go to the
app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php
find this line near line 228
// we need to set pagination only if passed value integer and more that 0
$limit = (int)$this->getLimit();

now chenge it
$limit = 0;

and it will work.

Saturday, July 9, 2011

Create New category via soap api

In magento 1.5 it's very easy to create a category via soap api

$proxy = new SoapClient('http://magentosite/api/soap/?wsdl');

$sessionId = $proxy->login('apiuser', 'apikey');

$newCategoryId = $proxy->call($sessionId,'category.create',array(3,array('name'=>'New openerp','is_active'=>1,'include_in_menu'=>2,'available_sort_by'=>'position','default_sort_by'=>'position')) );

//where 3 is the parent category

Friday, July 8, 2011

How to get newsletter block in the footer

I am using magento 1.5+. To get the newsletter block in footer open
app\design\frontend\base\default\layout\page.xml
and pest this code

after this line
the block will come
have fun...

Thursday, July 7, 2011

How to add group in register form

in magento 1.5+ go to the
app\design\frontend\base\default\template\customer\form\register.phtml
add following code in the page

<div class="input-box">

<label for="group_id" class="required"><?php echo $this->__('Group') ?><em>*</em></label><br/>

<select name="group_id" id="group_id" title="<?php echo $this->__('Group') ?>" class="validate-group required-entry input-text" />

<?php $groups = Mage::helper('customer')->getGroups()->toOptionArray(); ?>

<?php foreach($groups as $group){ ?>

<option value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option>

<?php } ?>

</select>

<br /><p class="required" style="float:left;">Retailer group require admin authentication </p>

</div>


also change some code in app\code\core\Mage\Customer\controllers\AccountController.php

now replace $customer->getGroupId(); with

if($this->getRequest()->getPost('group_id'))
{
$customer->setGroupId($this->getRequest()->getPost('group_id'));
}
else
{
$customer->getGroupId();
}

How to Setup a Multiple Currency Magento


How to Setup a Dual Currency Magento Shop


Login as admin and select System->Configuration, then select ’Currency Setup’ from GENERAL section,
then select Base currency, Default display currency, allowed currencies (press Control Key and Click the needed currencies) and ’Save Config’


how_to1


Now come to "System->Manage Currencies’ menu


how_to2


Click in Import currencies to load the exchange rate(s).


how_to3


You are done. Visit the frontend and reload (you may need to refresh your cache) to see the drop down added to your product pages.


how_to4

Wednesday, February 2, 2011

How to bring ihe new product in the home page in magento

i am using
{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

in my home cms

At last I found the solution

{{block type="catalog/product_new" name="home.catalog.product.new" alias="product_homepage" template="catalog/product/new.phtml"}}

this code is work fine but I had some misunderstanding. I have solve it to go

Catalog > Manage Products edit or add a product go to the general -> Set Product as New from Date and set a updated date then you can see the new product in your home page.