Pages

Sunday, August 11, 2013

Get Top 10 Products in Magento

$collection= Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)

->setOrder(‘ordered_qty’, ’desc’)
->setPageSize(10) ;
foreach($collection as $product)
{
$name=$product->getName();
$productId=$product->getId();
$price=$product->getPrice();
}

Get Customer Details Using Customer Session in Magento

$customer = Mage::getSingleton(‘customer/session’)->getCustomer();
$email = $customer->getEmail(); // To get Email Address of a customer.
$firstname = $customer->getFirstname(); // To get Firstname of a customer.
$lastname= $customer->getLastname(); // To get Lastname of a customer.
$id =$customer->getId(); // To get Customer Id
//Get Details Using Customer Id
$customer = Mage::getModel(‘customer/customer’)->load($id)->getData();

Get Current Category Id in Magento

$layer = Mage::getSingleton(‘catalog/layer’);
$_category = $layer->getCurrentCategory();
$currentCategoryId= $_category->getId();

How do I remove Grid view or List view from my Magento store?

System->Configuration->Catalog->Frontend
You can change the List Mode.

Remove other shipping if Free shipping available in magento

//To get the subtotal in shipping method (onepage checkout)
$subtotal = Mage::getSingleton(‘checkout/session’)->getQuote()->getSubtotal()
If cart total is less than 500 flat rate will enabled and free shipping will be disabled , for this
app/design/frontend/Your-Namespace /MODULE/template/checkout/onepage/shipping_method/available.phtml
<?php
if($subtotal >=500)
{
// Remove any other shipping methods if free shipping is available
if (array_key_exists(‘freeshipping’, $_shippingRateGroups )) {
$_shippingRateGroups = array(‘freeshipping’ => $_shippingRateGroups['freeshipping']);
}
}
?>

Tuesday, August 6, 2013

Stock Status Index process is working now. Please try run this process later in magento

Delete the locks files from var/locks or Delete var folder and create it again and give 777 premission
then tried again reindexing problem is solved.

Authorized.net Gateway error: (TESTMODE) The merchant login ID or password is invalid or the account is inactive in magento

Create test account and use
Go do  Magento Dashboard:
  1. Go to System -> Configuration
  2. Select Sales -> Payment Method (in the left sidebar)
  3. Expand the “Authorize.net
  4. Change the “Gateway URL” to https://test.authorize.net/gateway/transact.dll
  5. Click “Save Config” at the top.

How to call a phtml file from controller in magento



<?php
class Namespace_Module_DisplayController extends Mage_Core_Controller_Front_Action
{
public function popupAction()
{
$block = $this->getLayout()->createBlock(‘core/template’)
->setTemplate(‘zipcode/popup.phtml’);
$this->getResponse()->setBody(
$block->toHtml()
);
}
}

How to get the admin frontend name in magento

By default the magento admin path is ‘http://Yourwemsite/admin&#8217;. You  change this name (admin)  with any name  while installing. To get the adminFrontName use the following.
$adminFrontName = (string)Mage::getConfig()->getNode(‘admin/routers/adminhtml/args/frontName’);

Get Store Email address in Magento

//General Contact
echo $name = Mage::getStoreConfig('trans_email/ident_general/name'); //sender name
echo $email = Mage::getStoreConfig('trans_email/ident_general/email'); //sender email
//Sales Representative
echo $name = Mage::getStoreConfig('trans_email/ident_sales/name'); //sender name
echo $email = Mage::getStoreConfig('trans_email/ident_sales/email'); //sender email
//Customer Support
echo $name = Mage::getStoreConfig('trans_email/ident_support/name'); //sender name
echo $email = Mage::getStoreConfig('trans_email/ident_support/email'); //sender email
 //Custom Email 1
echo $name = Mage::getStoreConfig('trans_email/ident_custom1/name'); //sender name
echo $email = Mage::getStoreConfig('trans_email/ident_custom1/email'); //sender email
//Custom Email 2
echo $name = Mage::getStoreConfig('trans_email/ident_custom2/name'); //sender name
echo $email = Mage::getStoreConfig('trans_email/ident_custom2/email'); //sender email