Tuesday, July 19, 2011

How do I use more than two decimal places for prices?

To get 4 decimals accurancy for all prices in magento.
In /lib/Zend/Currency.php line 74
'precision' => 4,
Override in app/code/locale the Mage core files and make some changes :
Mage/Core/Model/Store.php line 790
public function roundPrice($price)
    {
        return round($price, 4);
    }
Mage/Directory/Model/Currency.php line 197
public function format($price, $options=array(), $includeContainer = true, $addBrackets = false)
    {
        return $this->formatPrecision($price, 4, $options, $includeContainer, $addBrackets);
    }
Hope that helps !

Monday, July 18, 2011

Which Ecommerce shopping cart software to use?

I am a real fan of Open Source software, and there are some great projects around, however up till now the e-commerce category has missed out. Nearly all of the open-source e-commerce systems I have checked out are just big piles of spaghetti code, that not only make development and maintenance of online shops a headache, I consider them to be grave security risks.

Magento has actually been designed - that has got to count for something! While with other projects I wince when I look under the hood, with Magento I am being pleasantly surprised by each new aspect I look at. In fact, I think there is a lot I can learn from this well implemented system. It is now only a preview release, and it is already light-years ahead.

Magento is a professional product, and you see that in both the development cycle and the quality of the code. In the forums the Magento team (at least so far) has been professional and responsive, not paranoid and elitist (osC) or whiny (Zen Cart). And Magento has features every store needs, which ZC just doesn’t. (osC doesn’t either, but then development essentially stopped on osC years ago . . . at least development that makes it to the public). ZC misses some core functionality that I can’t continue to live without and don’t feel like programming myself. I’m tired of wading through hacked-up code; it makes my hands itch to fix it, but I’m definitely not reinventing the wheel. Magento is a breath of fresh air there; the code has a solid, well-programmed feel and from what I can tell, it’s modular in a way ZC never will be (because osC wasn’t).

Magento is waaaaay easier to install than Zen Cart and osC (or at least it was for me). CharliesBooks is right in that an installation guide covering possible stumbling blocks (such as having mod_rewrite enabled, and how on earth you fix that if you’re *not* a technical person) is vital for software that caters to a general public. From what I’ve seen, Magento has every intention of providing that kind of assistance to its users; it’s just early in the game.

Magento has better functionality and the GUI look professional even with the default theme, like everyone else said create a better overall user experience and be the pioneer in using Magento.

How to get attribute name and value in Magento?

Here is the code to get attribute code and value for any product
Let as assume the attribute code is "my_attribute"
/**
 * get attribute collection
 */
$attribute = $_product->getResource()->getAttribute('my_attribute');
/**
 * get attribute type
 */
$attribute->getAttributeType();
/**
 * get attribute Label
 */
$attribute->getFrontendLabel();
/**
 * get attribute default value
 */
$attribute->getDefaultValue();
/**
 * check if the attribute is visible
 */
$attribute->getIsVisible();
/**
 * check if the attribute is required
 */
$attribute->getIsRequired();
/**
 * get attribute value
 */
$attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getMyAttribute();

Here is the code to fetch value from a select box attribute
$attributeValue = Mage::getModel('catalog/product')
                            ->load($_product->getId())
                            ->getAttributeText('my_attribute');

Add a Image Slider Banner in Magento Home page

We can Implement from Admin->CMS->Pages->Home Page


Magento Ban or lock the user

- Create a custom customer attribute of boolean type say: is_banned_customer
- Then set the value of is_banned_customer = 1 if that customer retries more than a threshold times.
- Then during login in check for that custom attribute as:
Mage_Customer_AccountController::loginPostAction()
public function loginPostAction()
    {
        if ($this->_getSession()->isLoggedIn()) {
            $this->_redirect('*/*/');
            return;
        }
        $session = $this->_getSession();

        if ($this->getRequest()->isPost()) {
            $login = $this->getRequest()->getPost('login');
            if (!empty($login['username']) && !empty($login['password'])) {
                try {
                    $session->login($login['username'], $login['password']);

                    /* check if user is banned::start */
                    if($session->getCustomer()->getIsBannedCustomer()){
                        //logout and redirect to info page or any page you like
                        $session->logout();
                        $this->_redirect('*/*/');
                        return;
                    }
                    /* check if user is banned::end */

                    if ($session->getCustomer()->getIsJustConfirmed()) {
                        $this->_welcomeCustomer($session->getCustomer(), true);
                    }
                } catch (Mage_Core_Exception $e) { 

How to get attributes on front end?

$_product->getData(’attribute_code’); 

Friday, July 1, 2011

Get customer groupid in magento

$groupid = Mage::getSingleton('customer/session')->getCustomerGroupId();