Search This Blog

Friday 27 April 2012

Automatic Customer Login and redirect to home page


Code to autologin the customer by his email address:

<?php
    require_once 'app/Mage.php';
    umask(0);
    Mage::app("default");
    Mage::getSingleton("core/session", array("name" => "frontend"));


    $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getWebsite()->getId());
    $customer->loadByEmail('customer@domain.com');
    Mage::getSingleton('customer/session')->loginById($customer->getId());
    Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getBaseUrl())->sendResponse();

?>

Tuesday 17 April 2012

Setting up Fedex shipping in Latest Magento Versions

This is guide about setting FedEx shipping method in Magento.

Step 1. Go to: Fedex Developer Resource Center and create developer’s account.

Step 2. When you create developer’s account go to Develop & Test Your Application Now, you will see the link Develop & Test Your Application (about testing, obtain developer test key) click on it. Then you only have to send request for test environment, you can see the link "Obtain Developer Test Key" click on it and fill the form. After sending form with data, you will receive email message from FedEx with all required data for testing FedEx shipping method.
In this email message you will get: Test Account Number:xxxxxxxxx , Key, Meter Number and Password (for FedEx Web Services for Shipping only) and you have to insert this number in field Account ID in FedEx config section. Set the Sandbox mode to Yes. You are done !!!!!!

Step 3. When you’re almost ready to launch:
After you’ve successfully tested your application and are ready to go into production, go to Technical Resources and click on FedEx Web Services for Shipping and Move to production. Then at the bottom of the page click obtain production key.

FedEx Error Codes:
http://www.fedex.com/us/developer/product/WebServices/MyWebHelp_August2010/Content/Proprietary_Developer_Guide/Error_Codes_conditionalized.htm

Thursday 12 April 2012

IE9 Detection and CSS Stylesheet Selection in WordPress

<?php
  $user_agent = $_SERVER['HTTP_USER_AGENT'];
  if (strpos($user_agent, 'MSIE 9') !== false || strpos($user_agent, 'Opera') !== false) {
?>
     <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_url' ); ?>/opera.css" />
<?php } else if(strpos($user_agent, 'MSIE') !== false) { ?>
     <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'template_url' ); ?>/ie.css" />
<?php } ?>

Browser Detection plugin in wordpress : http://wordpress.org/extend/plugins/php-browser-detection/

Wednesday 11 April 2012

Useful Magento Resources

Reusing Magento’s calendar control

How to embed Google Custom Search in Magento

Fix Session Save Path Unwritable error in PHP

 Depending on the web hosting service you used, there are several possible solutions as listed below.

Define session.save_path directive in PHP.INI
If you have root access or control to the web host (for example, in VPS or dedicated server), edit the PHP.INI PHP configuration file in the web server to add in the environment variable. Normally the session.save_path directive is already included in the default PHP.INI, but been commented out. Add or edit the line so that it looks like below:
session.save_path = /tmp

Include session.save_path in .htaccess file
If you can’t modify PHP.INI global configuration file, or just want to make the change affect Joomla! or Mambo application only, create or edit the .htaccess file in the installation directory for Joomla! or Mambo, and add the following line (only works in Apache web server which configured to support .htaccess – most cPanel hosts do):
php_value session.save_path '/tmp'

Include in PHP file 
If nothing mentioned above you can do, then try to edit globals.php file comes with Joomla. Firstly create a writable folder, and then edit the globals.php in root Joomla! directory. Add in the following line at the top, right after <?php line:
ini_set('session.save_path','/tmp');


Thursday 5 April 2012

Adding And Removing Attributes in Magento


$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$setup->addAttribute('catalog_category', 'author', array(
'group' => 'General',
'input' => 'text',
'type' => 'varchar',
'label' => 'Author',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$setup->addAttribute('catalog_category', 'author_description', array(
'group' => 'General',
'input' => 'textarea',
'type' => 'text',
'label' => 'Author_description',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$setup->addAttribute('catalog_category', 'vendors', array(
'group' => 'General',
'input' => 'select',
'type' => 'varchar',
'label' => 'Vendors',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'option' => array ('value' => array('optionone' => array('Sony'),'optiontwo' => array('Samsung'),
'optionthree' => array('Apple'),)),

));

<?php

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->removeAttribute('customer', 'customcode');

?>

Remove the add item button in custom module magento

 Simply add $this->_removeButton('add'); line as specified below in Block/AdminHtml/Module_Name.php file

public function __construct()
{
$this->_controller = 'adminhtml_yourmodule';
$this->_blockGroup = 'yourmodule';
$this->_headerText = Mage::helper('yourmodule')->__('Module Manager');
parent::__construct();
$this->_removeButton('add');
}

Monday 2 April 2012

Working with AJAX in Magento

Add Custom Tabs to the Magento Product Admin / Customer Edit

Get all grouped products with status Enabled

$arrayAttrs = array(
'sku',
);

$groupedProductsCollection = Mage::getModel(‘catalog/product’)
->getCollection()
->addAttributeToFilter('type_id','grouped')
->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
->addAttributeToSelect($arrayAttrs);

Get associated products of a Grouped product

$_associatedProducts = array();
if ($_product->getTypeId() == 'grouped')
{
$_associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
}