2/28/2011

How to get Magento Format Price with default currency symbol

Whenever we fetch all data of a product by using either product sku or by using product id, Price also we need . But if we fetch product price then it display price as number format without any currency . So if you want to fetch price like magento price format then you have to pass your price variable in the following code then you can get the dynamic currency also.

Let you got your price by

$price = $_Pdetails->getPrice();
// To fetch price like magento format price write
$magento_style_price = Mage::helper('core')->currency($price);

How to get product details using product sku in magento

If you know your product SKU you can get details of that products, e.g- you can get Product Id, Product Name, Product Description, Product Price etc.
To get details fo the product by sku please write the below code

$products = Mage::getModel('catalog/product')
$_Pdetails = $product->loadByAttribute('sku', 'product-sku');

or

$_Pdetails =
Mage::getModel('catalog/product')->loadByAttribute('sku','product-sku');

echo $_Pdetails->getName();
echo $_Pdetails->getDescription();
echo $_Pdetails->getPrice();
echo $_Pdetails->getProductUrl();

2/21/2011

How to get absolute path of base directory in magento

While uploading a file in magento It's necessary to write the absolute path of your magento path, otherwise it will not upload. you can get your site absolute path from php.ini file, You can place this path by hardcording but later if you think to move your site to another host then the path will be change, So to make your absolute path dynamic or get the proper path in which your magento Installed, write the following code

<?php echo Mage::getBaseDir('media') . DS ;?>

It will definately work,

2/18/2011

How to get access of magento core functions from outside the magento directory

This is the very important thing in magento while accessing data from outside of the magento, You also can use it to set cron job of any magento function, as cron job doen't work properly in magento.


require_once 'app/Mage.php'; // if your are not root folder then write the proper path like publichtml/magento/app/Mage.php
Mage::app('default');

Now you can create object of any classes and can access methods of those classes also.
Like the Below example

$obj = new Mage_Checkout_Model_Observer();
echo $obj->salesQuoteSaveAfter();

2/17/2011

Fix for Magento Admin Login not working on Localhost

When you want to install magento in your local machine by either wamp server or by Xamp server then you will face a problem, while logging into magento admin panel, after successfull install.
Here are the fix to logging into magento.This fix work above Magento version 1.4.1
Go to the location app/code/core/Mage/Core/Model/Session/Abstract/ and open Varien.php then go to line number 86. There you will find the below code. if (!$cookieParams['httponly']) {
unset($cookieParams['httponly']);
if (!$cookieParams['secure']) {
unset($cookieParams['secure']);
if (!$cookieParams['domain']) {
unset($cookieParams['domain']);
}
}
}
if (isset($cookieParams['domain'])) {
$cookieParams['domain'] = $cookie->getDomain();
}

Comment this code, then your code will look like this


/* if (!$cookieParams['httponly']) {
unset($cookieParams['httponly']);
if (!$cookieParams['secure']) {
unset($cookieParams['secure']);
if (!$cookieParams['domain']) {
unset($cookieParams['domain']);
}
}
}

if (isset($cookieParams['domain'])) {
$cookieParams['domain'] = $cookie->getDomain();
}*/

Save the file and Refresh your admin panel page and try to login once again , Now you will be able to login to your Admin Dashboard

2/15/2011

How to configure multiple websites with multiple domain in a single magento

This is One of Magento's best and popular features of magento which allows to run Multiple website with multiple domain name in a single magento.To conigure multiple website or multiple domain Follow the below process.

Create 2 or more website, Store and storeview from System-> Manage Stores

See the below screenshot

Now go to System->Configuration->Web
From Current Configuration Scope: Select your first website i.e website1. Then from Unsecure tab change your Base URL from {{base_url}} to your domain name (e.g http://www.n2ndevelopers.com/)
Do the same for Website2 and website3 by selecting website2 and website3 From Current Configuration Scope:
Below 3 screenshot shows how to do this








Now open your magento Index.php file which you will found in your magento rrot folder. open it and comment the below code

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::run($mageRunCode, $mageRunType);

And paste the below code

switch($_SERVER['HTTP_HOST']) {
case 'website1.com':
Mage::run('website1', 'website');
/* website1 is the code you wrote in the admin when created the website */
break;
case 'website2.com':
Mage::run('website2', 'website');
break;
case 'website3.com':
Mage::run('website3', 'website');
break;
default:
Mage::run();
break;
}

and Enjoy

How to get all product details or product Id's with respect to individual or each store view in magento

To get all product Id's with respect to each store view, write the below code. $storeId    = Mage::app()->getStore()->getId();
$product    = Mage::getModel('catalog/product');
$products   = $product->getCollection()->addStoreFilter($storeId)->getData();
This will fetch all product details of current store. If u change store it will show different product