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!