Pages

Thursday, May 10, 2012

Display product list Randomly and limited numbers in Magento HomePage

Create new file product_list.phtml and copy content from list.phtml to product_list.phtml, log in to your magento admin go to cms -> pages -> home page
paste step1 to contact area. click save.

step 1.

{{block type="catalog/product_list_random"  category_id="4" template="catalog/product/product_list.phtml"}}

now open product_list.phtml use the code below to display 4 products at once

step 2.
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
    if ($_productCollection->count()):
    $_productCollection = $_productCollection->getItems();

    $i = 0;
             foreach ($_productCollection as $_product):
        if ($i < 4):
                             // Product Data With CSS
        endif;
    $i++;
     endforeach;
    endif;

?>
 Now you can show your index page product list randomly with 3 limited number products.

Comment it and share it.

Wednesday, May 9, 2012

Replace default email logo in welcome email Magento

You can create a new theme and place it there. This isn't as difficult as it sounds because of the way themes fall back onto defaults in Magento. If Magento can't find something in your theme, it will fall back onto the base theme by looking in the default folder.

For example, in a store that you maintain, you uploaded your own version of the e-mail logo image in
/skin/frontend/{package}/{my-theme-name}/images/logo_email.gif
and in the Administration panel, you went to System > Configuration > Design > Themes and set Default to {your-theme-name}.

Why does this work?
In the e-mail templates, Magento specifies the src of the logo image as {{skin url="images/logo_email.gif" _area='frontend'}}. This is Magento template gibberish for "find the images/logo_email.gif in the frontend area of the current theme." So Magento looks in for /frontend/{package}/{your-theme-name}/images/logo_email.gif, finds it, and uses that path when dishing out the HTML.

If you delete your image, it doesn't break! Instead, although Magento would still first search in your theme directory as described above, it would discover that it doesn't exist and fall back onto the one in /frontend/{package}/default/images/logo_email.gif.

Good luck, and hope this helps!

Tuesday, May 8, 2012

Magento Backend user edit in account information checkboxes values show and update code

You have to customize in couple of file for showing checked value and update those checkboxes in magento backend Account Information page.

for showing checked value
app/code/core/Mage/Adminhtml/controllers/CustomerController.php

and for update checkboxes value
app/code/core/Mage/Adminhtml/Block/Widget/form.php


          else if ($inputType == 'checkbox') {
                    $customer11 = Mage::registry('current_customer');
                    if($customer11->getData($attribute->getAttributeCode()) == '1' || $customer11->getData($attribute->getAttributeCode()) != '')
                        $element->setChecked('1');
                    else if($customer11->getData($attribute->getAttributeCode()) == '0' || $customer11->getData($attribute->getAttributeCode()) == '')
                        $element->setChecked('0');
                }

set this codition in function _setFieldset in form.php file for showing your checkbox is checked or not in backend Account infomation page in magento.


            $emailprefs = array(
                'ATTRIBUTECODE1','ATTRIBUTECODE2','ATTRIBUTECODE3',...,
            );
            // Prepare customer saving data
            if (isset($data['account'])) {
                foreach($emailprefs as $pref){
                    $data['account'][$pref] = isset($data['account'][$pref]) ? 1 : 0;
                }
               
                if (isset($data['account']['email'])) {
                    $data['account']['email'] = trim($data['account']['email']);
                }
                $customer->addData($data['account']);
            }

Put this code in function saveAction() in CustomerController.php page for updating your checkboxes values in backend Account infomation page in magento. Replace 'ATTRIBUTECODE' with your checkboxes attribute codes.

Magento update checkboxes in frontend edit registration page code


app\code\core\Mage\Customer\controllers\AccountController.php
 
             /**
             * we would like to preserver the existing group id
             */
            if ($this->_getSession()->getCustomerGroupId()) {
                $customer->setGroupId($this->_getSession()->getCustomerGroupId());
            }

            /**
             * Custom coding for Promoted Update & Rented Update by Leo
             */
            if ($this->getRequest()->getParam('ATTRIBUTE_CODE')) {
                $customer->setATTRIBUTE_CODE(1);
            } else {
                $customer->setATTRIBUTE_CODE(0);
            }
            /**
             * End
             */

From this customizing user can update checkboxes values from edit registration page frontside in Magento if user has checkbox fields in registration of his magento site. Replace 'ATTRIBUTE_CODE' with your checkbox attribute code.

Thursday, May 3, 2012

Find number of total checkboxes in form or page Javascript

var formobj = document.getElementById('FORM_ID');
var counter = 0;
for (var j = 0; j < formobj.elements.length; j++)
{
    if (formobj.elements[j].type == "checkbox")
    {
        if (formobj.elements[j].checked)
        {
            counter++;
        }
    } 
}

alert('Total Checked = ' + counter);
 
This javascript is using to find number of total checkboxes in form or page and also 
user can find from all checkboxes how many is checked. In this 'FORM_ID' is the id 
of <form>.