Pages

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

Track visitors information in magento

Here, I will show you how to track visitor’s data information in Magento. By visitor’s information, I mean information like remote address, http host, user agent (browser), referer url, first visit date time, last visit date time, etc.
The following code fetches the vistor data:-
$visitorData = Mage::getSingleton('core/session')->getVisitorData();
// printing visitor information data
echo "<pre>"; print_r($visitorData); echo "</pre>";
You will get an array of visitor information data like the following one:-

Array
(
    [] =>
    [server_addr] => 167772437
    [remote_addr] => 167772437
    [http_secure] =>
    [http_host] => 127.0.0.1
    [http_user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.237 Safari/534.10
    [http_accept_language] => en-US,en;q=0.8
    [http_accept_charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
    [request_uri] => /magento/index.php/catalog/category/view/id/22
    [session_id] => 13qm5u80238vb15lupqcac97r5
    [http_referer] => http://127.0.0.1/magento/
    [first_visit_at] => 2011-01-17 11:42:23
    [is_new_visitor] =>
    [last_visit_at] => 2011-01-17 11:58:38
    [visitor_id] => 41
    [last_url_id] => 139
)

In the above array, the server_addr and remote_addr are in different form than usual. The (IPv4) Internet Protocol dotted address has been converted into a proper address using ip2long PHP function. You can get the same kind of value from the following code:-
// user's ip address (visitor's ip address)
$remoteAddr = Mage::helper('core/http')->getRemoteAddr(true);
// server's ip address (where the current script is)
$serverAddr = Mage::helper('core/http')->getServerAddr(true);

Hope this helps. Thanks.

How to get the customer login, logout, register and checkout url in magento

Mage::getUrl(‘customer/account/login’); //login url
Mage::getUrl(‘customer/account/logout’); //logout url
Mage::getUrl(‘customer/account’); //My Account url
Mage::getUrl(‘customer/account/create’); // Register url
Mage::getUrl(‘checkout/cart’); //Checkout url

Remove or rename ‘Add New’ button from Admin Grid Magento

Rename ‘Add New’ button

Here are the steps to rename the ‘Add New’ text to anything you required (for example, ‘Add Report’):-
- Go to YourNamespace -> YourModule -> Block -> Adminhtml -> YourFile.php
- Add the following code in the constructor of this file:-

$this->_addButtonLabel = Mage::helper('yourmodulename')->__('Add Report');


Remove ‘Add New’ button

Here are the steps to remove the ‘Add New’ button:-
- Go to YourNamespace -> YourModule -> Block -> Adminhtml -> YourFile.php
- Add the following code in the constructor of this file (it should be just below the call to parent constructor):-

parent::__construct();
$this->_removeButton('add');

Thursday, August 1, 2013

Script to export magento categories

If you are after a quick method to get all the category ID’s for your categories for some Excel lookups (for new data imports), then this quick PHP script should help you out:

<?php

    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/import/catwithid.csv";
        file_put_contents($file,"catId, catNamen");
        foreach ( $ids as $id ) {
          $string = $id . ', ' .$category->load($id)->getName() . "n";
            file_put_contents($file,$string,FILE_APPEND);
        }
    }
?>

Generate Category Tree in Magento

<?php
$rootDir = ""; //include root path
include($rootDir."app/Mage.php");
$rootcatId= Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
function  get_categories($categories) {
    $array= '<ul>';
    foreach($categories as $category) {
        $cat = Mage::getModel('catalog/category')->load($category->getId());
        $count = $cat->getProductCount();
        $array .= '<li>'.
        '<a href="' . Mage::getUrl($cat->getUrlPath()). '">' .
                  $category->getName() . "(".$count.")</a>\n";
        if($category->hasChildren()) {
            $children = Mage::getModel('catalog/category')->getCategories($category->getId());
             $array .=  get_categories($children);
            }
         $array .= '</li>';
    }
    return  $array . '</ul>';
}
echo  get_categories($categories); ?>