Oct 10, 2011
kalpesh

Magento: Get checkout cart total details | Subtotal/Grandtotal/Discount/Tax

In Magento, if you want to get shopping cart totals details anywhere across the site, you can do so by following piece of code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(); //total items in cart
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = round($totals["subtotal"]->getValue()); //Subtotal value
$grandtotal = round($totals["grand_total"]->getValue()); //Grandtotal value
if(isset($totals['discount']) && $totals['discount']->getValue()) {
    $discount = round($totals['discount']->getValue()); //Discount value if applied
} else {
    $discount = '';
}
if(isset($totals['tax']) && $totals['tax']->getValue()) {
    $tax = round($totals['tax']->getValue()); //Tax value if present
} else {
    $tax = '';
}
Sep 18, 2011
kalpesh

Upgrading Android 2.2 (Froyo) to Gingerbread (2.3.4) – Samsung Galaxy Fit S5670

If you have purchased Samsung galaxy fit S5670 mobile phone, you must have noticed that it has very short battery life. Also you may have experienced sudden switch off of your mobile and weird behavior. This is due to some bugs in Android OS version 2.2 (froyo).

To fix this, you will have to upgrade your android OS from 2.2 to 2.3.4 version which will increase your battery life to some extent. Before proceeding backup all your important data (contacts, messages, etc..) so that if something goes wrong in between, you are on your safer side. So here are the steps to follow:

1. Download ODIN Multi-downloader v4.38 – 444 KB
2. Download Gingerbread Firmware – 113 MB
3. Turn off you samsung mobile phone Continue reading »

Jul 10, 2011
kalpesh

Magento: Show only specific attributes in layered navigation

In Magento, if you have lots of attributes (e.g. Type, Size, Price, Color, etc.) defined for categories, all are shown in the layered navigation on the left side. This may be sometimes annoying as they may break the website design. It is possible to disable the desired attributes from displaying on frontend.

The solution is, go to:

– Magento Backend -> Catalog Tab -> Attributes -> Manage Attributes
– Click the attributes you do not want to display in layered navigation
– Select NO where it says “Use in Layered Navigation”
– Save

Now all the attributes with Use in Layered Navation as Yes will only show in frontend Shopping options.

Jul 9, 2011
kalpesh

Magento: Can’t login/add items in Chrome and IE

Problem: In Chrome and IE, user as well as admin are unable to login as well as add items to cart. In Firefox, everything works fine.

Solution: This is due to the cookie problem, not in browser but in Magento itself. In Magento, by default cookie’s lifetime is set to 3600 (1 hour). But if the end users computer time runs ahead of server’s time, cookies will not get set for magento frontend as well as backend. For example, end user’s computer time is 1 hour forward than server’s time, that means the cookie (holding user’s session id) will expire as soon as user logs in or tries to add an item.

To solve this, set cookie’s lifetime to 86400 (1 day) instead of 1 hour and everything will work as expected. You can also set cookie lifetime to 0, so that cookie will only expire when the user’s browser is closed.

Go to: Magento backend -> Sytem -> Configuration -> Web -> Session and Cookie Management
Set cookie lifetime to 86400 and save. Everything will work as expected now.

Jun 19, 2011
kalpesh

Magento: Get customer details : customer id, name, email

Magento get the logged in customer details like customer id, name, email, etc. Check if customer is already logged in or not, if they are logged in then get all the data using customer session object and use it as per the requirement.

1
2
3
4
5
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData();
    Mage::log($customerData);
}

Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Array
(
    [entity_id] => 1
    [entity_type_id] => 1
    [attribute_set_id] => 0
    [website_id] => 1
    [email] => john.doe@example.com
    [group_id] => 1
    [increment_id] => 000000001
    [store_id] => 1
    [created_at] => 2007-08-30 23:23:13
    [updated_at] => 2008-08-08 12:28:24
    [is_active] => 1
    [firstname] => John
    [lastname] => Doe
    [password_hash] => 204948a4020ed1d0e4238db2277d5:eg
    [prefix] => 
    [middlename] => 
    [suffix] => 
    [taxvat] => 
    [default_billing] => 274
    [default_shipping] => 274
)

Getting customer details from the $customerData object:

1
2
3
4
5
$customerID = $customerData->getId(); //entity_id can be used as id
$name = $customerData->getFirstname() . ' ' . $customerData->getLastname();
$isActive = $customerData->getIsActive();
$email = $customerData->getEmail();
$incrId = $customerData->getIncrementId();

Similarly, we can get lastname, email, etc. ( [website_id] = getWebsiteId() )

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications