Thursday 28 June 2012

How to make active css class in magento

 Make a class in css like .mainmenu li.active a{ color:#f68e1e; }

<li class="home<?php if (Mage::helper('core/url')->getCurrentUrl() === Mage::helper('core/url')->getHomeUrl()):?> active<?php endif;?>"> <a href="<?php echo $this->getUrl('') ?>">  Home </a> </li>

     <li class="<?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'about-us') != false ) :?> active<?php endif;?>">
          <a href="<?php echo $this->getUrl('') . 'about-us' ?>"><?php echo $this->__('About Us')  ?></a>
    </li>

   <li class="<?php if (strpos(Mage::helper('core/url')->getCurrentUrl(),'product') != false ) :?> active<?php endif;?>">
          <a href="<?php echo $this->getUrl('') . 'product' ?>"><?php echo $this->__('Product')  ?></a>
    </li>



match Url
 $url1 = Mage::helper('core/url')->getCurrentUrl();

<li  class="<?php if ($url1 == 'http://www.knifedaddy.com/test/shop/brand.html/' ){ ?>active<?php } ?>">
<a href="<?php echo $this->getUrl('shop/brand.html')?>">Brand</a>
</li>

How to Call Newsletter in footer in Magento

To show Newsletter in footer go to app/design/frontend/default/YourTheme/layout/newsletter.xml and add the following lines in default

<reference name="footer">
<block type="newsletter/subscribe" name="footer.newsletter" 
template="newsletter/subscribe.phtml"/>
  </reference>

and add the following line in app/design/frontend/default/YourTheme/template/page/html/footer.phtml

<?php echo $this->getChildHtml('footer.newsletter'); ?>

Tuesday 26 June 2012

How To Export and Import Category in Magento

For export category  create a simple php file catgory.php in root Folder.
<?php
    ini_set("memory_limit","1000M");
    require_once "app/Mage.php";
    umask(0);
    Mage::app();
    $category = Mage::getModel ( 'catalog/category' );
    $tree = $category->getTreeModel ();
    $tree->load();
    $ids = $tree->getCollection()->getAllIds();
    if ($ids) {
    $string='';
    $heading = '"store","categories","cat_id","is_active","meta_title","meta_keywords","meta_description","include_in_menu","is_anchor","description",';
    foreach ($ids as $id) {
    if($id>0)//start if removeroot category and default category .
    {

    $cate_cre = Mage::getModel('catalog/category');

    $cate_cre->load($id);
    $treeurl='';
    $cate_cre1=Mage::getModel('catalog/category')->load($id);
    $treeurl=$cate_cre->getName();
    if($cate_cre1->getParentId()>0)
    {
    for($i=0; ;$i++)
    {
    if($cate_cre1->getParentId()>0)
    {
    $abc=Mage::getModel('catalog/category')->load($cate_cre1->getParentId());
    $pCat=$abc->getName();
    if($abc->getId()>1){
    $treeurl=$pCat.'/'.$treeurl;
    }
    $cate_cre1=$abc;
    }
    else{
    break;
    }
    }
    }
    $store = "default";
    $string .='"'.$store.'","'.$treeurl.'","'.$id.'","'.$cate_cre->getIsActive().'","'.$cate_cre->getMetaTitle().'","'.$cate_cre->getMetaKeywords().'","'.$cate_cre->getMetaDescription().'","'.$cate_cre->getIncludeInMenu().'","'.$cate_cre->getIsAnchor().'","'.$cate_cre->getDescription().'"';
    $string.="\n";
    }//endof if removeroot category and default category .
    }
    $csv_output = $heading ."\n".$string;
    $filename = "Categories";
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: csv" . date("Y-m-d") . ".csv");
    header( "Content-disposition: filename=".$filename.".csv");
    print $csv_output;
    }
    ?>

After run this file at browser .u got a csv file-

After the export category you must need to import the categories and  you want to import the categories with previous category structure.For that work i craeted a folder ImpCat folder at app\code\local\
first i craete  file at a file Category.php  at app\code\local\ImpCat\Catalog\Model\Convert\Adaptera\

<?php
    class ImpCat_Catalog_Model_Convert_Adapter_Category
     extends Mage_Eav_Model_Convert_Adapter_Entity
    {
     protected $_categoryCache = array();

     protected $_stores;

     /**
     * Category display modes
     */
     protected $_displayModes = array( 'PRODUCTS', 'PAGE', 'PRODUCTS_AND_PAGE');

     public function parse()
     {
     $batchModel = Mage::getSingleton('dataflow/batch');
     /* @var $batchModel Mage_Dataflow_Model_Batch */

     $batchImportModel = $batchModel->getBatchImportModel();
     $importIds = $batchImportModel->getIdCollection();

     foreach ($importIds as $importId) {
     //print '<pre>'.memory_get_usage().'</pre>';
     $batchImportModel->load($importId);
     $importData = $batchImportModel->getBatchData();

     $this->saveRow($importData);
     }
     }

     /**
     * Save category (import)
     *
     * @param array $importData
     * @throws Mage_Core_Exception
     * @return bool
     */
     public function saveRow(array $importData)
     {
     if (empty($importData['store'])) {
     if (!is_null($this->getBatchParams('store'))) {
     $store = $this->getStoreById($this->getBatchParams('store'));
     } else {
     $message = Mage::helper('catalog')->__('Skip import row, required field "%s" not defined', 'store');
     Mage::throwException($message);
     }
     } else {
     $store = $this->getStoreByCode($importData['store']);
     }

     if ($store === false) {
     $message = Mage::helper('catalog')->__('Skip import row, store "%s" field not exists', $importData['store']);
     Mage::throwException($message);
     }

     $rootId = $store->getRootCategoryId();
     if (!$rootId) {
     return array();
     }
     $rootPath = '1/'.$rootId;
     if (empty($this->_categoryCache[$store->getId()])) {
     $collection = Mage::getModel('catalog/category')->getCollection()
     ->setStore($store)
     ->addAttributeToSelect('name');
     $collection->getSelect()->where("path like '".$rootPath."/%'");

     foreach ($collection as $cat) {
     $pathArr = explode('/', $cat->getPath());
     $namePath = '';
     for ($i=2, $l=sizeof($pathArr); $i<$l; $i++) {
     $name = $collection->getItemById($pathArr[$i])->getName();
     $namePath .= (empty($namePath) ? '' : '/').trim($name);
     }
     $cat->setNamePath($namePath);
     }

     $cache = array();
     foreach ($collection as $cat) {
     $cache[strtolower($cat->getNamePath())] = $cat;
     $cat->unsNamePath();
     }
     $this->_categoryCache[$store->getId()] = $cache;
     }
     $cache =& $this->_categoryCache[$store->getId()];

     $importData['categories'] = preg_replace('#\s*/\s*#', '/', trim($importData['categories']));
     if (!empty($cache[$importData['categories']])) {
     return true;
     }

     $path = $rootPath;
     $namePath = '';

     $i = 1;
     $categories = explode('/', $importData['categories']);
     /*$IsActive = $importData['IsActive'];*/
      $IsActive = $importData['is_active'];
     $IsAnchor =$importData['is_anchor'];
      $Description =$importData['description'];
       $IncludeInMenu=$importData['include_in_menu'];
       $MetaTitle=$importData['meta_title'];
    
       $MetaKeywords=$importData['meta_keywords'];
       $MetaDescription=$importData['meta_description'];
       $Image=$importData['image'];
       $URlkey=$importData['url_key'];
    
     foreach ($categories as $catName) {
     $namePath .= (empty($namePath) ? '' : '/').strtolower($catName);
     if (empty($cache[$namePath])) {

     $dispMode = $this->_displayModes[2];
       $cat = Mage::getModel('catalog/category')
             ->setStoreId($store->getId())
             ->setPath($path)
             ->setName($catName)
             ->setIsActive($IsActive)
             ->setIsAnchor($IsAnchor)
             ->setDisplayMode($dispMode)->save();
       
         $cat = Mage::getModel('catalog/category')->load($cat->getId());
         $cat->setIncludeInMenu($IncludeInMenu);
         $cat->setDescription($Description);
         $cat->setMetaTitle($MetaTitle).
       $cat->setMetaKeywords($MetaKeywords);
       $cat->setMetaDescription($MetaDescription);
       $cat->save();
    
      $cat = Mage::getModel('catalog/category')->load($cat->getId());
      $data['meta_keywords']=$MetaKeywords;
      $data['meta_title']=$MetaTitle;
      $data['meta_keywords']=$MetaKeywords;
      $data['meta_description']=$MetaDescription;
      $data['url_key']= $URlkey;
      $cat->addData($data);
      $cat->save();
     $cache[$namePath] = $cat;
     }
     $catId = $cache[$namePath]->getId();
     $path .= '/'.$catId;
     $i++;
     }

    

     return true;
     }

     /**
     * Retrieve store object by code
     *
     * @param string $store
     * @return Mage_Core_Model_Store
     */
     public function getStoreByCode($store)
     {
     $this->_initStores();
     if (isset($this->_stores[$store])) {
     return $this->_stores[$store];
     }
     return false;
     }

     /**
     * Init stores
     *
     * @param none
     * @return void
     */
     protected function _initStores ()
     {
     if (is_null($this->_stores)) {
     $this->_stores = Mage::app()->getStores(true, true);
     foreach ($this->_stores as $code => $store) {
     $this->_storesIdCode[$store->getId()] = $code;
     }
     }
     }
    }

    ?>

There for need  config.xml file for configuration placed  at app\code\local\ImpCat\Catalog\etc\ -

<?xml version="1.0"?>
    <config>
     <global>
     <models>
     <catalog>
     <rewrite>
     <convert_adapter_category>ImpCat_Catalog_Model_Convert_Adapter_Category</convert_adapter_category>
     </rewrite>
     </catalog>
     </models>
     </global>
    </config>









Now craete  module controller file ImpCat_All.xml at app\etc\modules-

<?xml version="1.0"?>
    <config>
     <modules>
     <ImpCat_Catalog>
     <codePool>local</codePool>
     <active>true</active>
     </ImpCat_Catalog>
     </modules>
    </config>






then, create a  dataflow advanced profile into -admin/system/Import Export/Dataflow Advanced Profile and give the Profile Name is 'category import'and
its Actions XML  is-





<action type="dataflow/convert_adapter_io" method="load">
     <var name="type">file</var>
     <var name="path">var/import</var>
     <var name="filename"><![CDATA[Categories.csv]]></var>
     <var name="format"><![CDATA[csv]]></var>
    </action>
    <action type="dataflow/convert_parser_csv" method="parse">
     <var name="delimiter"><![CDATA[,]]></var>
     <var name="enclose"><![CDATA["]]></var>
     <var name="fieldnames">true</var>
     <var name="store"><![CDATA[0]]></var>
     <var name="number_of_records">1</var>
     <var name="decimal_separator"><![CDATA[.]]></var>
     <var name="adapter">catalog/convert_adapter_category</var>
     <var name="method">parse</var>
    </action>



after create import categoryextension you goes to admin system->permission->roles->Administrators ->Role Users

click on Save Role.Then Flush magento Cache.
Then downloaded  Categories.csv put Categories.csv into var/import/
and removed cat_id colums from csv and
remove first two rows

and remove all Default Category/ from categories colunn in Categories.csv.
Now you go to again- admin/system/Import Export/Dataflow Advanced Profile  run 'category import' profile>Run Profile>click 'Run Profile in Popup' import of category now start and automatically created category. Now you fill happy.Click here to download
click for csv

 http://www.bluehorse.in/Uploads/cat.rar

and click for extension  http://www.bluehorse.in/Uploads/ImpCat_All.rar
and
http://www.bluehorse.in/Uploads/ImpCat.rar





Monday 25 June 2012

How to set up tax rules for sales within Canada in Magento

Entering the Tax Rates for Retail Sales in Canada

The tax rates used in this example are listed below. DISCLAIMER: the rates and tax rules may not be correct or up to date and are listed here to demonstrate how different rates can be implemented in Magento. Do not use these rates without verifying with the proper authorities that they are correct.

Location Rate Note
GST (Canada-wide) 5% Applied to products and shipping all over Canada.
HST (New Brunswick) 13% Includes GST
HST (Nova Scotia) 13% Includes GST
HST (Newfoundland) 13% Includes GST
PST (Ontario) 8% Added to GST
PST (British Columbia) 7% Added to GST
PST (Manitoba) 7% Added to GST
PST (Saskatchewan) 5% Added to GST
PST (Prince Edward Island) 10% Compounded with GST
TVQ (Quebec) 7.5% Compounded with GST
* Tax rates for the territories are not included here, and to my knowledge Alberta does not have any retail sales tax.
The first step is to set up the tax rates within Magento.
Go to Sales > Tax > Manage Tax Zones & Rates. Click Add New Tax Rate and fill out the relevant information. Enter the name of the tax in the Tax Identifier. This name will appear on the customer’s invoice. Leave the Zip/Postal Code field with a “*”. For the rate field you can enter integers to represent the percentage of the tax. For example, entering 7 will set the rate to 7%.
After you entered all the rates for each province the Manage Tax Zones & Rates main screen should look like this.

Tax Rates for Canada
Tax Rates for Canada

Setting up the Tax Rules

Now that we have defined the tax rates for each province we need to give Magento some more information about how to use the rates:
•    Taxes (as defined below) are applied to all products and shipping charges for all customers.
•    GST is applied to all products sold to any province except NB, NS, and NF where HST is applied
•    For Ontario, BC, Manitoba and Saskatchewan, apply GST to the amount before taxes and apply PST to the amount before taxes and add them up for the grand total.
•    For PEI and Quebec apply the GST to the amount before taxes and then apply PST/TVQ to the (amount before taxes + GST)
To set up the tax rules open up Sales > Tax > Manage Tax Rules and click Add New Tax Rule. In the Tax Rate field you will see all the rates that were added in the previous step.

Setting up GST and HST

Let’s add the GST for all provinces and the HST for the relevant provinces for taxable goods and shipping (as far as I know shipping is provided as a service and can be marked up and is therefore taxable in Canada – don’t take my word for it).
Name: Retail Customer-Taxable Goods-Canada  (can be anything you like)
Customer Tax class: Retail Customer
Product Tax class: Select both Taxable Goods and Shipping by pressing down Ctrl and clicking on the two items.
Tax Rate: Select GST and the HST tax rates (for NB, NS, NF)
Priority: Set this to 1. This field will be explained later.
Sort Order: Set to 1.
Save the tax rule and let’s see if this worked. Go to your store and add an item in the cart. When the shopping cart page is displayed you should see an Estimate Shipping and Tax box. Select Canada, Newfoundland and click Get a Quote.

Testing Magento Tax Setup
Testing Magento Tax Setup
You should now see a little + to the left of ‘Tax’ in the grand total box. Click that to open up the tax details.
Note: If you’re not seeing the tax details, it may be because the store is configured to hide the tax details. To fix that go to System > Configuration > Tax : Display  and set Display Full Tax Summary to “Yes”.
If you select a province like Ontario or British Columbia you should see:
Subtotal with taxes
Subtotal with taxes
This is incorrect because for these provinces we need to apply the PST to the subtotal and add it with the GST to determine the ‘Grand Total’.

Adding non-compounded provincial sales taxes to the GST

As listed in the table at the beginning of the post, the PST for Ontario, British Columbia, Manitoba and Saskatchewan must be added to the GST, but unlike compounded taxes like the TVQ and the PST in Prince Edward Island, the PST must be applied to the original subtotal and then added to the GST.
To do that we need to add individual tax rules for the tax for each province as follows.
Magento Partial Tax Rules
Magento Partial Tax Rules
By setting the Priority field to 1 we are telling Magento to add the tax with other taxes with the same priority (like the GST tax defined with the rule Retail Customer-Taxable Goods-Canada).
Try out these new settings.

Adding compounded provincial sales taxes to GST

In PEI and Quebec the provincial tax is applied to the amount = subtotal + GST applied to the subtotal. To define this compounded tax rule we need to tinker with the Priority field and set this field to 2 (since our GST tax rule has priority 1).
The final tax rule table will look like this:
Magento Full Tax Rules
Magento Full Tax Rules

Troubleshooting

If the taxes changing as you select different provinces in the estimator you may want to check the ‘Tax Based On’ field in System > Configuration > Tax : Calculation . Make sure it is not set to ‘Shipping Origin’.

Saturday 23 June 2012

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

Thursday 21 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.

Multi-Site, Multi-Domain Setup in magento

Tutorial: Multi-Site, Multi-Domain Setup

 

One of Magento’s greatest strengths is its capabilities for scaling to support multi-store and multi-language retailing all from the same backend. In this tutorial, we will be showing you how to take advantage of Magento’s scalability by creating multiple websites with unique domain names sharing the same product catalog. (***NOTE: Each store can also be configured to offer a unique product catalog as well.)

For this example, we’ll be attempting to set up domain1.com, domain2.com and domain3.com.

Generally, Magento is installed into the folder /var/www/http, as per the Magento Installation Guide, and you can find more information related to the initial setup and configuration of any Magento installation there.  We aren’t going to through an full blown installation right now though, and for our purposes, we are going to presume that the Magento instance has already been installed in the server.

We’ll be dividing the process into steps based on the areas of configuration we will need to deal with–namely, Categories, Store Configuration in Magento Admin, Store Configuration in the Server.


1: Categories


First, will need to create our Categories.  Since all three websites will be sharing the same catalog, we will be using the default root Category in Catalog -> Categories -> Manage Categories and will be creating our categories under that root category (i.e. Clothing, Electronics, etc.).

image

These categories (Clothing, Electronics) should be set as both “Is Active” from the General Information tab and “Is Anchor” from the Display Settings tab for them to appear on the frontend of your Magento shop.  (***NOTE: If the websites will not be sharing the same catalog, a Root Category must be created for each website.  Thus, if there are 3 websites, there will be 3 Root Categories with subcategories under them.)


2: Store Configuration in the Magento Admin


1. Now that we have created our Categories, it’s time to create our websites by going to System -> Manage Stores and clicking the “Create Website” button.


  • Name – domain name of our new website
  • Code – a parameter that will be used in configuring the Apache web server to point to that particular domain name

image

2. Once the website has been created, we’ll create the store corresponding to this website by clicking on the “Create Store” button in System -> Manage Stores.


  • Website – website to which this store will be associated
  • Name – the same as the website name
  • Root Category – the root category that will be used for this store. (Refer to Step 1 for Details)

image

3. Then, we create the store view which is the interface that the customer will be able to access on the frontend.  Click the “Create Store View” button in System -> Manage Stores.


  • Store – store to which this view will be associated
  • Name – name of this store view (i.e. English Version, German Version, etc.)
  • Code – code for this store view
  • Status – if enabled, this store view will be accessible from our frontend, otherwise, it will not be accessible

  • image
    4. After the Store has been created, we need to configure the Unsecure Base URL and Secure Base URL under System -> Configuration -> General -> Web.  Before we set their respective base URLs, we first need to ensure that the configuration scope is set to the domain1.com website to define which site we are working on.
    image

    Then, we modify the base URLs for both Unsecure:

    image

    and Secure:

    image

    with the corresponding domain name by unchecking the ”Use default [STORE VIEW]” checkbox and then save the configuration.

    5. Now we just repeat Steps 2-4 for the other two websites, domain2.com and domain3.com by replacing the fields with their respective information.


    3: Store Configuration in the Server


    1. Now we re-configure the Apache configuration file, httpd.conf, for all domains to set the DocumentRoot to our Magento directory.  In this case, the directory is /var/www/http

    <VirtualHost *:80>
        ServerAdmin webmaster@domain1.com
        DocumentRoot /var/www/http
        ServerName domain0.com
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerAdmin webmaster@domain2.com
        DocumentRoot /var/www/http
        ServerName domain1.com
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerAdmin webmaster@domain3.com
        DocumentRoot /var/www/http
        ServerName domai2.com
    </VirtualHost>
    

    2. Edit the .htaccess file at /var/www/http/.htaccess and add the following lines below:



    SetEnvIf Host www\.domain1\.com MAGE_RUN_CODE=domain1_com
    SetEnvIf Host www\.domain1\.com MAGE_RUN_TYPE=website
    SetEnvIf Host ^domain1\.com MAGE_RUN_CODE=domain1_com
    SetEnvIf Host ^domain1\.com MAGE_RUN_TYPE=website
    
    SetEnvIf Host www\.domain2\.com MAGE_RUN_CODE=domain2_com
    SetEnvIf Host www\.domain2\.com MAGE_RUN_TYPE=website
    SetEnvIf Host ^domain2\.com MAGE_RUN_CODE=domain2_com
    SetEnvIf Host ^domain2\.com MAGE_RUN_TYPE=website
    
    SetEnvIf Host www\.domain3\.com MAGE_RUN_CODE=domain3_com
    SetEnvIf Host www\.domain3\.com MAGE_RUN_TYPE=website
    SetEnvIf Host ^domain3\.com MAGE_RUN_CODE=domain3_com
    SetEnvIf Host ^domain3\.com MAGE_RUN_TYPE=website
    

    3. Restart Apache Server

    If you are on a Red Hat based distribution, you’ll be able to type service apache restart.  For other distributions, you’ll want to type apachectl restart.  (***NOTE: The second option here is different than “apachectl graceful” which will run a graceful restart and reload configuration files, without terminating current connections.  We don’t have any visitors to our site yet, so it’s okay to do a “apachectl restart”.)

    4: We’re Ready to Go!


    After we’ve complete all of these steps we should now see all 3 domains in our backend:

    image

    All that’s left now is to add products to the catalog and give each site a custom theme if we wish to do so.  Many people are taking advantage of Magento’s powerful multi-store functionality, whether it’s to set up stores with multiple languages, different catalogs and even the same catalogs (as in our example) with different front ends as a marketing vehicle.  No matter which you decide to use Magento’s powerful features for, we hope this post will provide a good starting point to help you get there!

Wednesday 20 June 2012

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();
    
}

Tuesday 19 June 2012

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 get total price of items in your Magento cart

 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));
?>

how to show login or logout in magento

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

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; ?>

Friday 15 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') ?> 

There is one thing different here though. If your Attribute Code is “shirt_size”, then you would use getShirtSize(). Remove the underscores and capitalize the first letter of each word. It is picky that way. if you use getshirtsize(), it won’t work.
If you are using a dropdown or a multiple select, you have to call it a little differently:

<?php echo $_product->getAttributeText('shirt_size') ?>
 
 
<?php $_product->getResource()->getAttribute('contrast_ratio')
    ->getFrontend()->getValue($_product); ?>

Note : contrast_ratio is your dropdown attribute code


Thursday 14 June 2012

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:


 

 

 


 

 

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>

Display random products from category on homepage in magento

first make a file and path is-->app\design\frontend\default\default\template\catalog\random.phtml
 paste below given code:

 <?php
$chosen_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = $this->getLoadedProductCollection();
$number_of_products = $this->getNumProducts();
if (sizeof($_productCollection) < $number_of_products) {
    $number_of_products = sizeof($_productCollection);
}
$displayed_products = array();
foreach ($_productCollection as $_product) {
    $displayed_products[] = $_product;
}
$random_products = array();
if (sizeof($_productCollection) > 1) {
    $random_products = array_rand($displayed_products, $number_of_products);
} else {
    $random_products = array('0');
}
?>
<?php if(!$_productCollection->getSize()):?>
<div class="note-msg">
    <?=$this->__('There are no products matching the selection.')?>
</div>
<?php else:?>

<div class="main-binder">
  <div class="cms-box">
  <div class="category-title">
      <h2>Random Products</h2>
  </div>  
  <div class="category-products">
    <table id="products-grid-table" class="products-grid">
    <?php
    $k=0;
    for ($i=0; $i < $number_of_products; $i++): ?>
    <?php if ($k == 0) { ?>
            <tr class="first odd">
        <?php } if($k==3)    { $k=0;  ?>
            </tr><tr class="first odd even">
        <?php } ?>
            <td id="td_<?php echo ($k+1); ?>" <?php if($k==3){ ?>class="last"<? } ?> >
        <div class="cms-box">
              <div id="cont_<?php echo ($k+1); ?>">
              <div class="product-name-block">               
                  <?php
                  $pname=$this->htmlEscape($displayed_products[$random_products[$i]]->getName());
                  ?>
                  <h3 class="product-name">                
                  <a href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>" title="<?php echo $pname; ?>">
                    <?php if(strlen($pname) > 28) {echo substr($pname,0,25)."...";}else {echo $pname;}?>
                    </a></h3>
                </div>
                <div class="image-box">               
                <a class="product-image" href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>"> <img src="<?php echo $this->helper('catalog/image')->init($displayed_products[$random_products[$i]], 'small_image')->resize(140);?>" alt="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>" title="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>"/> </a>
                </div>

                <div class="cms-price-box" style=" text-align:center;">
                    <span class="regular-price" id="product-price-37">                      
                        <span class="price" ><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->
     getCurrentCurrencyCode())->getSymbol().$displayed_products[$random_products[$i]]->getPrice(); ?></span>
                    </span>                    
                </div>
                <div class="button-row" style="text-align:center;">
                            <button onclick="setLocation('<?php echo $displayed_products[$random_products[$i]]->getProductUrl();?>')" class="button" type="button"><span><span><span>Details</span></span></span></button>                                                                                                                          
                    <button onclick="setLocation('<?php echo $this->getUrl('')."/checkout/cart/add?product=".$displayed_products[$random_products[$i]]->getId()."&qty=1"  ?>')" class="button"><span><?php echo $this->__('Add to Cart') ?></span></button>
                </div>
              </div>
        </div></td>  

<?php $k++; ?>
<?php endfor;?>
</tr>
      </table>   
    </div>
  </div>
</div>      
<?php endif;?>

  
paste below Xml code in whre you want random product(like home page,any one page)


{{block type="catalog/product_list" category_id="59" num_products="4" template="catalog/random.phtml"}}



Friday 8 June 2012

Order Delete in magento

 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;
    }
}