Magento header.phtml basic user account and basket code

<Keithblog />

Some useful shippets for including customer accound and a basic basket/cart product count in the header of Magento. This should be added to header.html in your template folder, athough the code will work anywhere in the Magento template system

Login and log out links

<ul>
   <?php if ($this->helper('customer')->isLoggedIn() ) { ?>
      <li><a href="/customer/account/logout/">Log out</a></li>
      <!-- <li><a href="/customer/account/create/">Register</a></li> -->
   <?php } else { ?>
      <li><a href="/customer/account/login/">Sign in</a></li>
      <li><a href="/customer/account/create/">Register</a></li>
   <?php } // logged in ?>
</ul>

Simple code to dispay cart count

<ul>
<?php
   $count = $this->helper('checkout/cart')->getSummaryCount();  //get total items in cart
   $total = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price
   if($count>1) {
      echo $this->__('<li><a href="/checkout/cart"><strong>Basket (%s Items)</strong></a></li>',$count);
   } else if ($count==1) {
      echo $this->__('<li><a href="/checkout/cart"><strong>Basket (1 Item)</a></li></strong>',$count);
   } else {
      echo $this->__('<li><a href="/checkout/cart"><strong>Basket (0 Items)</strong></a></li>',$count);
   }
   ?> 
</ul>
Tagged:

Related posts on keithgreer.uk

PHP: glob

Magento Code: Check an import directory for new product CSVs and process using a Magmi profile

PHP: header

PHP: str_replace

Magento Code: Include currency switcher in the header or footer with Foundation mark-up

Magento Code: Add a drop down attribute and display it on the product page in custom HTML

Magento Issue: Unable to sort configurable product attribute drop down options

WordPress Code: Completely disable comments using functions.php

MySQL TRUNCATE command: Quickly and easilty clear out the Magento database