Monday, October 17, 2011

"Image type and information need to be specified for each store view" Product Image upload problem in magento 1.6


Solution:

Install magento dull image uploader / No flash image uploader extension (Here). This will help to import images.

That’s all, go to admin panel in Magento admin panel and upload and import product successfully.

How to get products available stock quantity in magento?

Here is the code to get produts stock quantity. Place this code in your view.phtml file.
echo $qtyStock = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();

Thursday, October 6, 2011

How to remove validation on zip code in magento checkout page?

Login to your your magento admin panel then go to System -> Configuration->General. From Country option tab you can see there is an option "Postal code is optional for the following countries" Select the country which you want to Optional/Not validate . then click on save config to save your settings.



That's it you are done.

Tips to use home page url, custom page url and pass query string in Magento CMS Page

{{store url=""}} -> Used to get Store's home page URL.
Resulting in a URL like "http://yourstore.com/"

{{store url="contacts"}} -> Used to get contact us page URL.
Resulting in a URL like "http://yourstore.com/contacts/"

If you want to show custom URL Use direct_url
{{store direct_url="category/subcategory.html"}} -> Used to get custom URL.
Resulting in a URL like "http://yourstore.com/category/subcategory.html"

If you want to pass parameters in query string use _query
{{store direct_url="category/subcategory.html" _query="a=param_a&b=param_b"}} -> Used to Pass query string
Resulting in a URL like "http://yourstore.com/category/subcategory.html?a=param_a&b=param_b"

{{skin url='images/homepageimage.jpg'}} -> Used to get image url

Wednesday, October 5, 2011

How to prevent not logged in users from accessing magento site and force customer to login?

Step 1:
Create and put below content to the file named "redirect.phtml" and place under "/template/page/html/".
Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri());  //save requested URL for later redirection
if(!Mage::getSingleton('customer/session')->isLoggedIn()) {  // if not logged in
    header("Status: 301");
    header('Location: '.$this->getUrl('customer/account/login')) ;  // send to the login page
    exit; 
} 
Step 2:
Edit "page.xml" and place the code

after

Step 3:
Edit the below files "template/page/"
1. 1column.phtml
2. 2columns-left.phtml
3. 2columns-right.phtml
4. 3columns.phtml

and Insert the following line at the start of all the files.
echo $this->getChildHtml('auth-redirect')
Step 4:
Now Add exceptions for home, login and cms page.
Edit your "layout/customer.xml"
Add below code
<remove name="auth-redirect" />
under
<customer_account_login>
Also If you want users to be able to create an account, another good one to make public might be place code under
<customer_account_create>
in "layout/customer.xml"
If you want to make the home (front) page public, add the "remove" code to the 

<cms_index_index>
That's it you are done.

Export Magento categories with ID using php script

Copy the code below into a new file "categorywithid.php" and place this file in your root folder
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
Mage::app();

$category = Mage::getModel ( 'catalog/category' );
$tree = $category->getTreeModel ();
$tree->load ();

$ids = $tree->getCollection ()->getAllIds ();

if ($ids) {
 $file = "var/export/catwithid.csv";
 file_put_contents($file,"catId, catName\n");
 foreach ( $ids as $id ) {
   $string = $id . ', ' .$category->load($id)->getName() . "\n";
  file_put_contents($file,$string,FILE_APPEND);
 }
}
Hit Your browser like www.YourDomain.com/categorywithid.php Thats it. You are done. Get the csv file under "var/export/catwithid.csv".

Mass Products Stock levels Update in Magento

Step 1:
Create a CSV with a minimum of 3 columns, the SKU, qty and is_in_stock.
Then save it to "/app/var/import/updateStockLevels.csv".
For instance, we will use,
"sku","qty","is_in_stock"
"prod1","100","1"

Step 2:
Copy the code below into a new file "updateStock.php" and place this file in your root folder
define('MAGENTO', realpath(dirname(__FILE__)));
 require_once MAGENTO . '/app/Mage.php';
 umask(0); $count = 0;
 Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
 
 $file = fopen(MAGENTO . '/var/import/updateStockLevels.csv', 'r');
 while (($line = fgetcsv($file)) !== FALSE) {
   if ($count == 0) {
   foreach ($line as $key=>$value) {
   $cols[$value] = $key;
   }
 }
 
 $count++;
 if ($count == 1) continue;
 
 #Convert the lines to cols
 if ($count > 0) {
   foreach($cols as $col=>$value) {
   unset(${$col});
   ${$col} = $line[$value];
   }
 }
 
 // Check if SKU exists
 $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
 if ( $product ) {
   $productId = $product->getId();
   $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
   $stockItemId = $stockItem->getId();
   $stock = array();
   if (!$stockItemId) {
     $stockItem->setData('product_id', $product->getId());
     $stockItem->setData('stock_id', 1);
     } else {
       $stock = $stockItem->getData();
   }
 
   foreach($cols as $col=>$value) {
   $stock[$col] = $line[$value];
   }
 
   foreach($stock as $field => $value) {
   $stockItem->setData($field, $value?$value:0);
   }
 
 $stockItem->save();
 unset($stockItem); unset($product);
 }
 echo "
Stock updated $sku"; 
}
 fclose($file);

Step 3:
Run the php script in  Your browser like "www.YourDomain.com/updateStock.php".
Thats it. You are done.

How to remove right column sidebar from product view page in Magento?

Edit your theme's "/layout/catalog.xml" file. Find the below lines.

  
      
        
      
You can set your template to 1column like this:
 
or use "<remove name="right"/>" code to remove right sidebar.


  
  
    
      
        
      
After making changes dont forget to refresh the cache. That's it. You are done.

How to remove the Discount Code / Coupon Code box in Magento My cart page?

Solution 1:
Edit your theme's "/layout/checkout.xml" file. Find and Comment the below lines.

Solution 2:
Add new local.xml file under your theme's layout folder.

   
      
   
 
Here, You no need to search for any template or layout file. This code will do the trick. After making changes dont forget to refresh the cache. That's it. You are done.

How to remove the Estimate Shipping and Tax box in Magento My cart page?

Solution 1:
Edit your theme's "/layout/checkout.xml" file. Find and Comment the below lines.

Solution 2:
Add new "local.xml" file under your theme's layout folder.

   
      
   
 
Here, You no need to search for any template or layout file. This code will do the trick. After making changes dont forget to refresh the cache. That's it. You are done.

How to Remove Add to Compare link in magento product view page?

Edit your theme's "templae/catalog/product/view/addto.phtml" file. Find and Comment the below lines.
<?php
    $_compareUrl = $this->helper('catalog/product_compare')->getAddUrl($_product);
?>
<?php if($_compareUrl) : ?>
    <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?> 

Move or Remove Callouts on the left or right sidebar in magento

Edit your theme's "/layout/catalog.xml" file. Fine the below lines.


    

        images/media/col_left_callout.jpg

        Our customer service is available 24/7. Call us at (555) 555-0123.

        checkout/cart

    


If you want to remove callout from left sidebar just comment those lines. Suppose you want to show that callout in your right sidebar just change reference name="left" to reference name="right". Likewise you can do it for right sidebar callout.
Remove Your cache and check. Thats it you are done.

How to enable template path hints in magento admin panel?

1. Admin > System > Configuration
2. Switch your "Current Configuration Scope" to your store (’Main Website’ on a stock build)
3. Click on the Developer Tab (bottom left) and find the Debug area
4. Template Path Hints: Yes (also might want to add Block Names to hints)

How to remove a block from just one page cart, cms or product page?

For page specific layout updates, either you can use backend layout updates sections(category, product, cms pages) or the following code in the "app/etc/local.xml"

    

for instance, use this code to remove the sidebar cart from the product view page.

     

How to remove parent category path from sub category in magento URL?

Step 1:
Edit "/app/code/core/Mage/Catalog/Model/Url.php"
Around line 805 comment the below lines:
//if (null === $parentPath) {
//    $parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == '/') {
    $parentPath = '';
//}
Step 2:
Now re-index Catalog URL Rewrites in Index Management. That's it you are done.