Saturday 13 September 2014

Magento : get customer login status


<?PHP

//get customer login status ?>

<?php $myStatus = Mage::getSingleton('customer/session')->isLoggedIn() ?>

<?php if($myStatus): ?>

<li><a href="/customer/account/index" title="Customer Register">My account</a> |</li>
<li><?php echo $this->getLayout()->getBlock('header')->getWelcome() ?></li>

<?php else: ?>

<li><a href="/customer/account/index" title="Customer Register">My account</a></li>
<li><a href="/customer/account/create" title="Customer Register">Register</a></li>

<?php endif ?>

?>

Friday 12 September 2014

Magento : Custom Sort-By Price say High-To-Low and Low-To-High

Step 1 : Edit toolbar.phtml inside the folder
        app/design/frontend/yourpackage/yourtheme/template/catalog/product/list/toolbar.phtml


Step 2 : You will find the default Magento <select> </select> option over there. If you open this file in notepad++ go to line No.90.

Step 3 : You can either comment out that section and create a new one or just add your option in there to make it working too.

<select onchange="setLocation(this.value)">
            <!-- <?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
                <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
                    <?php echo $this->__($_order) ?>
                </option>
            <?php endforeach; ?> -->
</select>

Step 4 : Then put this code between <select> </select>

<option value="<?php echo $this->getOrderUrl('price', 'asc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'asc'): ?> selected=”selected”<?php endif; ?>>Price : Low To High</option>
<option value="<?php echo $this->getOrderUrl('price', 'desc') ?>"<?php if($this->isOrderCurrent('price') && $this->getCurrentDirection() == 'desc'): ?> selected=”selected”<?php endif; ?>>Price : High To Low</option>


Step 5 : You have Done!

Output :

Magento: How To Remove The "Position" Sort Option

Step 1 : Edit toolbar.phtml inside the folder
        app/design/frontend/yourpackage/yourtheme/template/catalog/product/list/toolbar.phtml


 Step 2 : And Find this code if you open this file in notepad++ go to line No.91.

 <?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
   <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
        <?php echo $this->__($_order) ?>
   </option>
  <?php endforeach; ?>
Then Replacing this code
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
    <?php if ($_order != 'Position') : // Remove "Position" from the sort option list ?>
        <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
            <?php echo $_order ?>
        </option>
    <?php endif; // End for removing "Position" sort option ?>
<?php endforeach; ?> 
Step 3 : Done!

Saturday 16 August 2014

Magento : DISABLE MAGENTO CHECKOUT WITH MULTIPLE ADDRESSES


So this is not one of those options which exists where you would expect to find it (checkout options, right?).

Here’s how we disable the “Checkout with Multiple Addresses” link.

1. Log in to Magento’s Admin Panel.
2. Navigate to System > Configuration > Sales > Shipping Settings.
3. Expand the Options header.
4. Set the option “Allow Shipping to Multiple Addresses” to “No”.
5. Done.


Happy checkouts!

Friday 21 February 2014

Magento : Show Any Category on Home Page

Create a homcategory.phtml inside a
app/design/frontend/your_themes/default/template/catalog/category

copy this code in the .phtml file

<?php 
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
$i=1;

$_category=Mage::getModel('catalog/category')->load($this->getCategoryId());
    $thumburl = Mage::getBaseUrl('web').'media/catalog/category/'.$_category->getThumbnail(); 
?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?> ">
<img  src="<?php echo $thumburl; ?>" alt="thumb" height="125" width="115" />
<span class="thumb_title">
<?php echo html_entity_decode($_category->getName()) ?>
</span>
</a>
</li>

<?php if ($i==7):
break;
endif;
$i++;
?>

After doing this Login in magento admin,

Go to CMS > static block - and create a static block

Block Title : Your BLock Name (as you like)

Identifier : your_block_id (as you like)

Status : Enabled / Disbaled .

Click to Show/ hide Editor and copy and past this content in content block

<div class="product_category">
<ul id="style_block">
{{block type="core/template" category_id="3" template="catalog/category/homcategory.phtml"}}
{{block type="core/template" category_id="7" template="catalog/category/homcategory.phtml"}}
</ul>
<h4>Choose from a variety of shirt styles</h4>
</div>

Note :- ( category_id="3") as you show a category in your home page.

after that save block.

And go to the CMS > Pages select a Home Page

and select a Content Tab, Click to Show/ hide Editor

{{block type="cms/block" block_id="your_block_id"}}

and paste this code.

that Done!

Output Look like this...

Refresh your home page and you see the list Category by as your choose....

Wednesday 19 February 2014

Magento : Add Image in Magento Admin Product Grid

Step 1:
  First you need to copy the core block to local. Copy Grid.php from       app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php to
  app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php


Here you'll find a method named _prepareColumns(), add the below code within this method
 If yoy edit in Notepad++ go to the line number 145.
       

$this->addColumn('product_image', array(
              'header'    => Mage::helper('catalog')->__('Image'),
              'align'     =>'left',
              'index'     => 'entity_id',
              'width'     => '100px',
              'renderer'  => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Image'
        ));


Step 2: 
    Now create the renderer file named Image.php in the following path
    app/code/local/Mage/Adminhtml/Block/Catalog/Product/Renderer/Image.php
    Here add the below code..
   
class Mage_Adminhtml_Block_Catalog_Product_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
    {
        public function render(Varien_Object $row)
        {
            $_product = Mage::getModel('catalog/product')->load($row->getEntityId());
            if($_product->getImage() != 'no_selection'){
                  $image = "<img src='".Mage::helper('catalog/image')->init($_product, 'image')->resize(100)."' title='".$_product->getName()."' />";
            }
            return $image;
        }

    }

Tuesday 28 January 2014

Magento: Difference between Mage::getSingleton() and Mage::getModel()

You may be in thinking sometime what is the difference between magento getSingleton and getModel method so here is a explanation of the difference The Mage::getModel(‘module/model’) create a instance of model object each time method is got called this approach is resource consuming require separate memory for each object instance.

1. Mage::getModel('catalog/product'), it will create new instance of the object product each time.

2. e.g.
$obj1 = Mage::getModel('catalog/product');
$obj2 = Mage::getModel('catalog/product');
Then $obj1 is a one instance of product and $obj is another instance of product.


While Mage::getSingleton(‘catalog/product’) will create reference of an existing object if any reference is not exists then this method will create an instance using Mage::getModel() and returns reference to it.
So, if
$obj1 = Mage::getSingleton(‘catalog/product’);
$obj2 = Mage::getSingleton(‘catalog/product’);

Then $obj1 and $obj2 both refer to the same instance of product.

Saturday 25 January 2014

Fixed: PHP Warning - POST Content Length exceeds the limit in XAMPP

When upload a any database file ex:filename.sql, I get this error: "PHP Warning: POST Content-Length of xxx bytes exceeds the limit of 8388608 bytes in Unknown on line 0". This is because you exceeded the limit of uploading files. 

1. Edit your server folder php/php.ini

You have find post_max_size and upload_max_filesize, then change the default number to 30M or what ever you want.

if you edit php.ini file in notepad++ 
so please press a crtl+g and to line number 770.
where is place post_max_size = 8M and replace a post_max_size = 30M

and again press a crtl+g and to line number 922.
upload_max_filesize = 2M and replace a upload_max_filesize = 30M


After changing your php.ini file close, 
Restart your web server (for local hosting) or try to upload your file again.