Saturday, 23 June 2012

How To Setup Multiple Magento Stores

Adding Another Store In Magento

The first thing we need to do is setup our second store in Magento.
We're going to do a hypothetical here for the naming conventions, and assume we own shirts.com. Adjust the values accordingly for your own store.
  1. Login to the Magento admin.
  2. Go to the Catalog tab, and select Manage Categories.
  3. Click on the Add Root Category button on the left.
  4. On the right, for the Name, we'll enter Shoes.com. Set the dropdown to Yes for both Is Active and Is Anchor.
  5. Click the Save Category button.
  6. Go to the System tab and select Manage Stores.
  7. Click on the Create Website button.
  8. For the Name, we'll enter Shoes.com, and for the Code, we'll enter shoes. We'll use this value later, so don't forget this!
  9. Click the Save Website button.
  10. Click on the Create Store button.
  11. For the Website, select Shoes.com from the dropdown. For the Name, we'll enter Main Store. For the Root Category, select the Shoes.com from the dropdown.
  12. Click on the Save Store button.
  13. Click on the Create Store View button.
  14. For the Store, select Main Store from the dropdown, making sure it's for the Shoes.com website. For the Name, we'll enter English. For the Code, we'll enter shoes_en. For the Status, select Enabled from the dropdown.
  15. Click the Save Store View button.
  16. Go to the System tab and select Configuration.
  17. For the Current Configuration Scope (located on the top left), change the dropdown menu from Default Config to Shoes.com.
  18. Select Web from the sidebar on the left under the General heading.
  19. For both the Unsecure and Secure sections, uncheck the Use default box next to the Base URL item, and enter the URL for your store, e.g. http://www.shoes.com/. Don't forget the trailing slash!
  20. Click the Save Config button.
Now that we have our second store setup, you'll need to choose one of the following methods for actually setting up the store on the server-side so visitors can access it.
If the URL structure you've chosen will have different domains for each store, the parked domain method is the fastest and easiest method.

Parked Domain Method

For this method, we'll pretend we own shirts.com and shoes.com. The shirts.com domain is our primary domain, and Magento is already installed on it. Here's how we would set this up for the shoes.com domain:
  1. Login to cPanel for your domain and click on the Parked Domains icon.
  2. In the input field, enter the domain name that you'll be setting up as a second store, e.g. shoes.com.
  3. Click on the Add Domain button.
  4. Open up the index.php file for Magento and look for this line (it's the last line of the file):
    Mage::run($mageRunCode, $mageRunType);
    …and right before this, we're going to add the following code:
    switch($_SERVER['HTTP_HOST']) {
     case 'shoes.com':
     case 'www.shoes.com':
      $mageRunCode = 'shoes';
      $mageRunType = 'website';
     break;
    }
    If you have more than two stores, you will need to add additional cases to the above code block, e.g.:
    switch($_SERVER['HTTP_HOST']) {
     case 'shoes.com':
     case 'www.shoes.com':
      $mageRunCode = 'shoes';
      $mageRunType = 'website';
     break;
     case 'hats.com':
     case 'www.hats.com':
      $mageRunCode = 'hats';
      $mageRunType = 'website';
     break;
    }

Addon Domain Method

This is the same scenario as above, except it takes a little longer to setup. This method might be more useful to you if, for example, you wanted to have a blog on one domain, but not on the other. You couldn't do that with a parked domain. Here's how we would set this up for the shoes.com domain:
  1. Login to cPanel for your domain, and click on the Addon Domains icon.
  2. For the New Domain Name, we'll enter shoes.com. cPanel will automatically fill in the next two fields, so remove public_html/ from the Document Root field, leaving us with just shoes.com. This step isn't required, but for organizational purposes, it makes more sense.
  3. Set a password for this domain and click on the Add Domain button.
  4. Login to your site via SSH, and go to the directory that we previously set in the Document Root field above when adding our domain. In our case, we would do the following:
    cd shoes.com/
  5. Copy the index.php and .htaccess file from the directory where Magento is installed, which would be in our root web directory:
    cp ../public_html/index.php ../public_html/.htaccess .
  6. Open up the index.php file that we just copied over and replace the following line of code:
    $mageFilename = 'app/Mage.php';
    …with the following:
    $mageFilename = '../public_html/app/Mage.php';
  7. With the index.php file still open, look for this line (it's the last line of the file):
    Mage::run($mageRunCode, $mageRunType);
    …and right before this, we're going to add the following code:
    $mageRunCode = 'shoes';
    $mageRunType = 'website';
  8. Lastly, we need to create symbolic links to point to a few directories:
    ln -s ../public_html/app ./app
    ln -s ../public_html/errors ./errors
    ln -s ../public_html/includes ./includes
    ln -s ../public_html/js ./js
    ln -s ../public_html/lib ./lib
    ln -s ../public_html/media ./media
    ln -s ../public_html/skin ./skin
    ln -s ../public_html/var ./var

Subdomain Method

For this method, we'll pretend we own mall.com, and it's setup as a portal that links to the various shops within the mall. Magento will be installed on the mall.com domain, and all of the shops will be in subdomains, e.g.:
  • shoes.mall.com
  • shirts.mall.com
Here's how we would set this up for the shoes subdomain:
  1. Login to cPanel for your domain, and click on the Subdomains icon.
  2. For the Subdomain, we'll enter shoes. cPanel will automatically fill in the next field, so remove public_html/ from the Document Root field, leaving us with just shoes. This step isn't required, but for organizational purposes, it makes more sense.
  3. Click the Create button.
  4. Login to your site via SSH, and go to the directory that we previously set in the Document Root field above when creating our subdomain. In our case, we would do the following:
    cd shoes/
  5. Copy the index.php and .htaccess file from the directory where Magento is installed, which would be in our root web directory:
    cp ../public_html/index.php ../public_html/.htaccess .
  6. Open up the index.php file that we just copied over and replace the following line of code:
    $mageFilename = 'app/Mage.php';
    …with the following:
    $mageFilename = '../public_html/app/Mage.php';
  7. With the index.php file still open, look for this line (it's the last line of the file):
    Mage::run($mageRunCode, $mageRunType);
    …and right before this, we're going to add the following code:
    $mageRunCode = 'shoes';
    $mageRunType = 'website';
  8. Lastly, we need to create symbolic links to point to a few directories:
    ln -s ../public_html/app ./app
    ln -s ../public_html/errors ./errors
    ln -s ../public_html/includes ./includes
    ln -s ../public_html/js ./js
    ln -s ../public_html/lib ./lib
    ln -s ../public_html/media ./media
    ln -s ../public_html/skin ./skin
    ln -s ../public_html/var ./var

Subdirectory Method

This is the same scenario as above, except all of the shops will be in subdirectories, e.g.:
  • mall.com/shoes
  • mall.com/shirts
Here's how we would set this up for the shoes subdirectory:
  1. Login to your site via SSH, and create a subdirectory where your second store will be:
    cd public_html
    mkdir shoes/
    cd shoes/
  2. Copy the index.php and .htaccess file from the directory where Magento is installed, which would be in our root web directory:
    cp ../public_html/index.php ../public_html/.htaccess .
  3. Open up the index.php file that we just copied over and replace the following line of code:
    $mageFilename = 'app/Mage.php';
    …with the following:
    $mageFilename = '../public_html/app/Mage.php';
  4. With the index.php file still open, look for this line (it's the last line of the file):
    Mage::run($mageRunCode, $mageRunType);
    …and right before this, we're going to add the following code:
    $mageRunCode = 'shoes';
    $mageRunType = 'website';

Managing Multiple Stores

It's very important to remember that now that you have multiple stores to manage from one admin panel, that you make sure you're changing the configuration for the appropriate store.
In the SystemConfiguration section, if you leave the dropdown menu for Current Configuration Scope set to Default Config, it will globally change the values for all of your stores, assuming you haven't removed the checkmark next to Use default throughout the configuration sections.
You can change the configuration values globally, for each website, and for individual store views.

Secure Checkout For Each Store

For those of you in dedicated hosting environments, you can follow either the addon or parked domain method from above, and edit the httpd.conf file to give the addon or parked domain a dedicated IP address.
However, this is not advised. Your changes will most likely be overwritten with a control panel upgrade, Apache or PHP rebuild, or even simple maintenance.
Your best bet would be to setup each store as a separate account, which can be done in WHM if you have access to it, or in the case of our Split-Dedicated product, something we will be able to set up for you.
Once you have all of your domains setup as individual accounts, you would follow steps 5, 7 and 8 for the addon domain method, except you're going to use absolute paths instead of relative paths for the symbolic links, e.g.:
ln -s /home/username/public_html/app ./app
ln -s /home/username/public_html/errors ./errors
ln -s /home/username/public_html/includes ./includes
ln -s /home/username/public_html/js ./js
ln -s /home/username/public_html/lib ./lib
ln -s /home/username/public_html/media ./media
ln -s /home/username/public_html/skin ./skin
ln -s /home/username/public_html/var ./var
Lastly, in order for the above to work, you will need suEXEC disabled. This won't be a problem in a dedicated hosting environment, since you don't have to worry about other people being able to access your files.
This is just one of the many advantages of running your online business in a more secure and flexible hosting environment like this. If you're on our Split-Dedicated product, this is something we'll have to disable for you.

How To Creating a Configurable Product in Magento

Creating a Configurable Product

There are a few steps involved:

  1. Create the attributes that will be configurable by the user - for our example they will be Size and Color
  2. Create the attribute set that will be assigned to the variant products - for our example, we’ll call it “T-shirt”
  3. Create the individual variant products
  4. Create the configurable product, and add the “T-shirt” attribute set
  5. Add the individual variants to this configurable product

Creating Attributes

Below are screenshots of how the configurable attribute “Size” is set up.
Attribute Properties
image
Notice the “Catalog Input Type” is set to dropdown - this is required for the attribute to be compatible with configurable products.  The Scope is also set to Global. When both of these settings are configured in this manner, the Use To Create Configurable Product dropdown will appear. This must be set to Yes. Required is also set to “Yes”.  In order for a Simple Product to be associated to a Configurable Product, it must have a value for all configurable attributes, so making it required ensures that you will remember to add a value for this attribute for all Simple Products.
Labels/Options
image
Note how the size options and their sort order have been entered above.
The attribute “Color” will be set up exactly the same, with only the Labels/Options page changed.  It will look as follows with these 4 colors:
image

Creating the attribute set

Now we’re ready to create an attribute set called “T-shirt” to start using for this product.  Go to “Catalog -> Attributes -> Manage Attribute Sets” and press “Add New Set”.
In our example, the name is “T-shirt” and we’re basing it on the default set:
image
Continue to the next page.  Drag the two attributes into a new group which I called “Selectable Options”:
image
If any of that’s confusing, be sure to read the section called ”How do I create an attribute set?”.

Creating the simple products

Now that we created the attribute set, we’re ready to start entering the data for the simple products that will be part of the configurable product.

  1. Navigate to “Catalog -> Manage Products”.  Press “New Product”
  2. Create a Simple Product based on the “T-shirt” attribute set

  3. image
  4. Fill in all the required information, and make sure to fill in options for the “Selectable Options” tab, as shown below:

  5. image
  6. After you’re done, press “Save Product”

Now, repeat these steps for every combination of options your super product will contain. Since this example had 3 sizes and 4 colors, you would create the 12 options individually. You can create duplicates of the first product you create to vastly speed up this process.
You should have a product list similar to this one when you’re done (of course, titles and SKUs can be whatever you choose, this example just uses the attributes in the title and sku):
image After you’re done, you’re ready for the next and final step!

Creating the Configurable Product


  1. After making all the variants, navigate to “Catalog -> Manage Products”
  2. Press “New Product
  3. Select ‘Configurable’ based on the T-shirt attribute set

  4. image
  5. The next screen lets you pick which attributes you want to associate.  It picks attributes from the set that are Input Type: Dropdown, Scope: Global, and Use To Create Configurable Product: Yes

  6. image
  7. Select both “Size” and “Color” and press “Continue”
  8. The next page is the regular create product page, with the addition of the “Associated Products” tab at the bottom. The general tab used for the sample product looks like this:

  9. image
  10. Finally, let’s take a look at the “Associated Products” tab:  If you push “Reset Filter”, you’ll see all products associated to the T-shirt Attribute Set that have options for the Size and Color attributes.  If you check one (or all) you’ll see the “Associated Products Attributes Configuration” above the list.  This is where you decide the sort order of the selectable attributes (click and drag an attribute to change) and also any price adjustments that selecting a specific attribute will have on the configurable product.  For example:  If you wanted the Magento shirt to be $5.00 more, you just have to enter “5” in the text field.  Price adjustments can be either percentage based or a fixed amount.  For our example, the Large size is 10% more, and the Magento shirt is $5.00 more.

  11. image In the above image you’ll notice an option called Attribute Name.  This is the text that will display in the front-end for this product.  In the example, “Select Color” and “Select Size” are the desired text for the front-end.
    Above this, you will see a button called Create Empty. This allows you to create a Simple Product in a pop-up window that will automatically be associated to this Configurable Product. It is very useful if you have forgotten to create all of your Simple Products prior to beginning the Configurable Product creation phase.
    When you’re done with all this, associate the product with a store and front-end category, and you’ll be able to find it in the front-end.  You’re done!

    Front-end

    Here’s a section from the front-end for this configurable product, done and ready to use:
    image

Wednesday, 20 June 2012

How to get Dropdown Attribute value

In Magento it is possible to access a product’s attributes with a simple getter method. Let’s get the attribute test:

<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?> 

This works as long as test is an attribute of type ‘text’. If the attribute is a dropdown, the method will just return the id of the selected option. To get the dropdown text, you need to call another method:--

<?php echo  $_product->getAttributeText('yourattributecode')?> 



Blank Attribute not show in magento

For some odd reason, the Magento developers decided that an empty attribute should NOT be empty, but rather "No" or "N/A", depending on its type. This is not just annoying, but in some cases can display wrong information which means confused visitors and potentially lost sales.


Open the file /app/design/frontend/default/[theme name]/template/catalog/product/view/attribute.phtml in an editor and find the following lines:


<?php foreach ($_additional as $_data): ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
<?php endforeach; ?>
Replace these lines with this:
 
<?php foreach ($_additional as $_data): ?>
    <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
    if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
    <?php } ?>
<?php endforeach; ?>

how to show login or logout in magento

1.  login or logout in magento.

 <?php

$loggedIn = $this->helper("customer")->isLoggedIn();
if($loggedIn == 1)
{
echo "<a href=\"".Mage::getBaseUrl()."customer/account/logout/\" />Log out</a>";
 }
else{ echo "<a href=\"".Mage::getBaseUrl()."customer/account/\" />Log in</a>"; }
?>




 2. login or logout in magento.

<?php
if ($this->helper('customer')->isLoggedIn() )
{
echo '<a href="<?php echo $this->getUrl('customer/account/login/');?>">Login</a>';
}
else
{
echo '<a href="<?php echo $this->getUrl('customer/account/logout/');?>">Logout</a>';
}
?>

how to show total prize and item in cart in magnto

 show total prize with total item in cart

<?php    
  $count = $this->helper('checkout/cart')->getSummaryCount();  //get total items in cart
  $total = $this->helper('checkout/cart')->getQuote()->getGrandTotal(); //get total price
  if($count==0)
  {
    echo $this->__('Items: %s',$count);
  }
  if($count==1)
  {
    echo $this->__(' Item: %s',$count);
  }
  if($count>1)
  {
    echo $this->__(' Items: %s',$count);
  }
  echo $this->__(' Total: %s', $this->helper('core')->formatPrice($total, false));
?>

only show total prize in cart

<?php
$grandTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
echo $text .= $this->__(' Total: %s', $this->helper('core')->formatPrice($grandTotal, false));
?>

remove Category name in shop by(left side) in magento

Open the file app\design\frontend\base\default\template\catalog\navigation\left.phtml in an editor and find the following lines:


  <dl id="narrow-by-list2">
            <dt><?php echo $this->__('Category') ?></dt>
            <dd>
                <ol>
                <?php foreach ($_categories as $_category): ?>
                    <?php if($_category->getIsActive()): ?>
                    <li>
                        <a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)
                    </li>
                    <?php endif; ?>
                <?php endforeach ?>
                </ol>
            </dd>
        </dl>

Replace these lines with this:

<dl id="narrow-by-list">
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
 <?php if($_filter->getItemsCount()): ?>
<?php if($_filter->getName() != "Category"){ ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd>
<?php echo $_filter->getHtml() ?>
</dd>
<?php } endif; ?>
<?php endforeach; ?>
</dl> 

How to set default all product in magento

Open the file  app/code/core/Mage/Page/Block/Html/Pager.php
in an editor and find the following lines:

public function getLimit()
    {
        if ($this->_limit !== null) {
            return $this->_limit;
        }
        $limits = $this->getAvailableLimit();
        if ($limit = $this->getRequest()->getParam($this->getLimitVarName())) {
            if (isset($limits[$limit])) {
                return $limit;
            }
        }
        $limits = array_keys($limits);
 
Replace these lines with this:

public function getLimit()

    {
        
//always show all
        
return 'all';
        
$limits $this->getAvailableLimit();
        if (
$limit $this->getRequest()->getParam($this->getLimitVarName())) {
            
if (isset($limits[$limit])) {
                
return $limit;
            
}
        }
        $limits 
array_keys($limits);
        return 
$limits[0];
    
}



Open the file app\code\core\Mage\Catalog\Block\Product\List/Toolbar.php in an editor and find the following lines:

 public function getAvailableLimit()
    {
        $currentMode = $this->getCurrentMode();
        if (in_array($currentMode, array('list', 'grid'))) {
            return $this->_getAvailableLimit($currentMode);
        } else {
            return $this->_defaultAvailableLimit;
        }
    }
 

Replace these lines with this:
 
 public function getAvailableLimit()
    {
        
if ($this->getCurrentMode() == 'list'{
            
return array(
 'all'=>__('All'),5=>5,10=>10,15=>15,20=>20,25=>25);
        
}
        
elseif ($this->getCurrentMode() == 'grid'{
            
return array(
'all'=>__('All'),9=>9,15=>15,30=>30,);
        
}
        
return parent::getAvailableLimit();

Friday, 15 June 2012

Magento: Getting product attributes values and labels


1.$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'attribute_id');
2.foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
3.$attributeArray[$option['value']] = $option['label'];
4.}

---------------------------------------------------------------------------------
01.$attributes = Mage::getModel('catalogsearch/advanced')->getAttributes();02.$attributeArray=array();03.foreach($attributes as $a){04.if($a->getAttributeCode() == 'desired_attribute_code'){05.foreach($a->getSource()->getAllOptions(false) as $option){06.$attributeArray[$option['value']] = $option['label'];07.}08.}09.}
---------------------------------------------------------------------------------
1.$attributeId = Mage::getResourceModel('eav/entity_attribute')2.->getIdByCode('catalog_product','attribute_code_here');3.$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);4.$attributeOptions = $attribute ->getSource()->getAllOptions();
---------------------------------------------------------------------------------1.//Referenced from /app/code/core/Mage/Eav/Model/Config/php @ line 443
2.$_product->getResource()->getAttribute('club_type')->getFrontend()->getValue($_product)
------------------------------------------------------------------------
1.//2.$attributesInfo = Mage::getResourceModel('eav/entity_attribute_collection')3.->setEntityTypeFilter({entityType})4.->setCodeFilter($attributes)5.->addSetInfo()6.->getData();

Thursday, 14 June 2012

How to call static block in magento


=> Login in into your magento admin panel.
=> Navigate to CMS->Static blocks
=> Click Add new block
=> Give your block title (Title: A descriptive name to identify this block)
=> Give your block identifier (Identifier: The identifer will allow you to call this block from your template files or using the Magento markup tags. Typically this would be programmer friendly name with no spaces or punctuation ie “my_block_identifier” rather than “My block’s identifer!”)
=> Set status enabled (Status: Here you can enable or disable a block.)
=> Entere your block content field (Content: As well as standard HTML you can also include special Magento markup tags in the block content. You can find information about these tags on the markup tags wiki page.)
=> Click Save Block or Save and Continue Edit to save your settings.

How to call image in static block

{{skin url='images/media/about_us_img.jpg'}}

How to creating a link to another page within your site

{{store direct_url='mypage.html'}}

How to call staic block any XML file

<reference name="left">
    <block type="cms/block" name="sample_block" before="-">
        <action method="setBlockId"><block_id>sample_block</block_id></action>
    </block>
</reference>


How to call staick block in your template or .phtml files

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('my_static_block_name')->toHtml() ?>

How to call static block in CMS->Pages

{{block type="cms/block" block_id="your_block_id"}}

Magento - Display only 'root category' in top menu


 <?php

  $root_category = Mage::getModel('catalog/category')->load(3); // Put your root category ID here.
  $subcategories = $root_category->getChildren();
  foreach(explode(',',$subcategories) as $subcategory) {
        $category = Mage::getModel('catalog/category')->load($subcategory);
        echo '<a href="'.$category->getURL() .'" />'.$category->getName().'</a><br/>';
  }

  ?>

Display Categories and SubCategories in Magento


Display Top Level Categories Only 

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories $_helper->getStoreCategories() ?>
<?php if (count($_categories) > 0): ?>
    <ul>
        <?php foreach($_categories as $_category): ?>
            <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php echo $_category->getName() ?>
                </a>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>
*******************************************************************************

Display Top Level Categories and ALL Subcategories 

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
    <ul>
        <?php foreach($_categories as $_category): ?>
            <li>
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
                    <?php echo $_category->getName() ?>
                </a>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                <?php $_subcategories $_category->getChildrenCategories() ?>
                <?php if (count($_subcategories) > 0): ?>
                    <ul>
                        <?php foreach($_subcategories as $_subcategory): ?>
                            <li>
                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                    <?php echo $_subcategory->getName() ?>
                                </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

Order Delete in magnto by php code


 First a make a folder in Root Directory folder is order-->delete.php

 run this Browser look like http://www.your project name/order/delete.php
  <?php
require_once('../app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
 $collection = Mage::getResourceModel('sales/order_collection')
            ->addAttributeToSelect('*')
            ->setPageSize(5000)          
            ->addFieldToFilter('status', 'canceled')->load();

foreach ($collection as $col) {
  Mage::log($col->getIncrementId() . ' order deleted ');
    try {
         $col->delete();
    } catch (Exception $e) {
        throw $e;
    }
}

How to change the currency selector with flag in magento

1. You need to prepare a flag list (images). 
2. Upload flag list to root/media/flag directory 
3. Rename flags to currency’s code (EX: US Dollar -> usd.jpg, Euro -> eur.jpg, Hong Kong Dollar -> hkd.jpg...) 
4. In the template file: app/design/frontend/default/your_theme/template/directory/currency.phtml (or app/design/frontend/base/default/template/directory/currency.phtml), change code to:

<ul>
  
<?php foreach ($this->getCurrencies() as $_code => $_name): ?>
  
<li>
          <
a href="<?php echo $this->getSwitchCurrencyUrl($_code) ?>" onclick="setLocation(this.value);">
                   <
img src="<?php echo Mage::getBaseUrl('media').'flag/'.$_code.'.jpg'; ?>" title="<?php echo $_name ?> - <?php echo $_code ?>" alt="<?php echo $_name ?> - <?php echo $_code ?>" width="20" height="20" />
        </
a>
      </
li>
         
        
<?php endforeach; ?>
        
</ul>

how to disable Common Elements Turn Off (and On) Via the Admin Panel


Header:--

 

ADMIN: System → Configuration → Design tab → Header panel. Edit or delete the contents of the "Welcome Text" field.

 

Footer:--

 

Remove/edit the CMS-based links (About us | Customer Service)
ADMIN: CMS → Static Blocks. Disable or modify the "footer_links" block. 
Remove Site Map link (and site map itself)
ADMIN: System→Configuration→Catalog tab→SEO panel. Set “Autogenerated Site Map” to "Disable." 
Remove Popular Search Terms link (and search terms page)
ADMIN: System→Configuration→Catalog tab→SEO panel. Set “Popular Search Terms” to "Disable." 
Remove Contact us link (and contact form)
ADMIN: System → Configuration → Contacts tab. Set "Enable Contact Us" field to "No." 
Remove RSS link and functionality
ADMIN: System→Configuration→RSS Feeds tab→RSS Config panel. Set “Enable RSS” to "Disable." 
Remove/edit the Copyright notice
ADMIN: System → Configuration → Design tab → Footer panel. Edit or delete the contents of the "Copyright" field. 
Remove "Keep Magento healthy" message
This message is hard-coded in the current theme's template/page/html/footer.phtml file and can be edited there. As a temporary workaround, you can hide this message using CSS. Go to ADMIN: System → Configuration → Design tab → Footer panel. In the "Miscellaneous HTML" field insert the following CSS statement: <style>p.bugs {display: none;}</style>

Newsletter:--

ADMIN: System → Configuration → Advanced tab. Set “Mage_Newsletter” to "Disable."

Cart Sidebar:--

ADMIN: System → Configuration → Checkout tab → Shopping Cart Sidebar panel. Set “Display Shopping Cart Sidebar” to “No.”

 

COMMON ELEMENTS YOU CAN TURN OFF VIA THE LAYOUT FILES

 

Compare Products sidebar:--

Sidebar block
Set in base/default/ layout/catalog.xml 
Product and category page links
The “Add to compare” link on the product page is set in template/catalog/product/add-to.phtml and needs to be removed separately. As a temporary workaround, you can hide this message using CSS. Go to ADMIN: System → Configuration → Design tab → Footer panel. In the "Miscellaneous HTML" field insert the following CSS statement: <style>p.link-compare {display: none;}</style>

Recently Viewed Products sidebar:--

Set in base/default/layout/report.xml

 

Recently Compared Products sidebar:--

Set in base/default/layout/report.xml:

Wednesday, 13 June 2012

Magento: Get store information

 Get store data
    Mage::app()->getStore();

    Store Id
    Mage::app()->getStore()->getStoreId();

    Store code
    Mage::app()->getStore()->getCode();

    Website Id
    Mage::app()->getStore()->getWebsiteId();

    Store Name
    Mage::app()->getStore()->getName();

    Is Active
    Mage::app()->getStore()->getIsActive();

    Store Home Url
    Mage::app()->getStore()->getHomeUrl();

Display all products in root category in magento

<?php
$root_category = Mage::getModel('catalog/category')->load(8); // Put your root category ID here.
$subcategories = $root_category->getChildren();
foreach(explode(',',$subcategories) as $subcategory) {
$category = Mage::getModel('catalog/category')->load($subcategory);
$product_id_1_12345=$category->getid();
  
$catid = $product_id_1_12345;
$category = new Mage_Catalog_Model_Category();
$category->load($catid); // this is your special offers category id!
$collection = $category->getProductCollection();
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
$collection->getSelect()->order('rand()');
$collection->addStoreFilter();
$numProducts = 20;
$collection->setPage(1, $numProducts)->load();

foreach($collection as $product):
$product = Mage::getModel('catalog/product')->load($product->getId()); 

$product_url258=$product->getProductUrl();
$custom_product_url=str_replace('http://192.168.1.49/mukesh/coach1/default/','',$product_url258);
$main1=$url_s_1.$custom_product_url;
$yes_no=$product->getCoach_featured();
?>
  <?php echo $product->getName(); ?>
  <?php echo $product->getProductUrl(); ?>
  <?php  echo $product->getPrice()?>


<?php
endforeach;
}
?>

Tuesday, 5 June 2012

Magento - Display only 'root category' in top menu


 <?php

  $root_category = Mage::getModel('catalog/category')->load(3); // Put your root category ID here.
  $subcategories = $root_category->getChildren();
  foreach(explode(',',$subcategories) as $subcategory) {
        $category = Mage::getModel('catalog/category')->load($subcategory);
        echo '<a href="'.$category->getURL() .'" />'.$category->getName().'</a><br/>';
  }

  ?>