Magento event observer for customer registration success
If you are looking for how to execute some code when customer successfully sign up in your website, you can use below code to check if the registration was successful. Note, this will NOT check if customer was registered from checkout page, if you are looking for that please go to this post.
In your xml file:
1 2 3 4 5 6 7 8 9 10 11 | <events>
<customer_register_success>
<observers>
<namespace_module_customer_register_success>
<type>singleton</type>
<class>Namespace_Module_Model_Observer</class>
<method>customerRegisterSuccess</method>
</namespace_module_customer_register_success>
</observers>
</customer_register_success>
</events> |
And in your Observer.php file:
1 2 3 4 5 6 7 8 9 10 | class Namespace_Module_Model_Observer {
public function customerRegisterSuccess(Varien_Event_Observer $observer) {
$event = $observer->getEvent();
$customer = $event->getCustomer();
$email = $customer->getEmail();
if($email) {
//code to handle if customer is successfully registered
}
}
} |
Magento check if customer registered in checkout page
If you want to check if the customer is guest, registered or just register to the site when they place the order, below script will help you identify that in success.phtml file.
You can find success / order confirmation phtml file at:
app/design/frontend/[package]/[theme]/template/checkout/success.phtml
Just at the end of this file put below lines of code:
1 2 3 4 5 6 7 8 9 10 11 12 | <?php $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$quoteId = $order->getQuoteId();
$quote = Mage::getModel('sales/quote')->load($quoteId);
$method = $quote->getCheckoutMethod(true);
$customer_email = $order->getCustomerEmail();
if ($method == 'register'){ ?>
//code to handle if customer just registered to your site
<?php } elseif($method == 'guest') {?>
//code to handle if customer is guest
<?php } else { ?>
//code to handle for logged in customer
<?php } ?> |
In the same file, success.phtml, you can request for order number, customer email, customer id, subtotal, grandtotal, order ID just created etc. like this:
1 2 3 4 5 6 7 8 | $_customerId = Mage::getSingleton('customer/session')->getCustomerId();
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$_totalData =$order->getData();
$_sub = $_totalData['subtotal'];
$_orderEmail = $_totalData['customer_email'];
$_orderNumber = $_totalData['increment_id']; |
Magento get State Code, ID, Name from Region ID
Magento get state name, ID, code from region ID or region code.
Get state code from state id
1 2 | $region = Mage::getModel('directory/region')->load(12);
$state_code = $region->getCode(); //CA |
Get state name from state id
1 2 | $region = Mage::getModel('directory/region')->load(12);
$state_name = $region->getName(); //California |
Get state id from state code
1 2 | $region = Mage::getModel('directory/region')->loadByCode('CA', 'US');
$state_id = $region->getId(); //12 |
Magento: Sample apache virtualhost for your website
Sample apache virtualhost to point to your magento directory and run your local website with specified URL.
1 2 3 4 5 6 7 8 | <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/var/www/magento/" ServerName loca.lho.st ServerAlias loca.lho.st ErrorLog "logs/error_log" CustomLog "logs/access_log" common </VirtualHost> |
Add entry to /etc/hosts too:
1 | 127.0.0.1 loca.lho.st |
Restart apache (service httpd restart OR service apache2 restart) and point your browser location to:
1 | http://loca.lho.st |
and you will see the website running from your /var/www/magento directory.
Magento: Sample local.xml template
Sample app/etc/local.xml file template. Change mysql database name, username and password with yours and clear the cache.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | <!--
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Core
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
-->
<config>
<global>
<install>
<date><![CDATA[Mon, 23 Sep 2013 19:53:16 +0000]]></date>
</install>
<crypt>
<key><![CDATA[414c9022922d31b62bbe4447356e4ed6]]></key>
</crypt>
<disable_local_modules>false</disable_local_modules>
<resources>
<db>
<table_prefix><![CDATA[]]></table_prefix>
</db>
<default_setup>
<connection>
<host><![CDATA[127.0.0.1]]></host>
<username><![CDATA[MYSQL_USERNAME]]></username>
<password><![CDATA[MYSQL_PASSWORD]]></password>
<dbname><![CDATA[DATABASE_NAME]]></dbname>
<initStatements><![CDATA[SET NAMES utf8]]></initStatements>
<model><![CDATA[mysql4]]></model>
<type><![CDATA[pdo_mysql]]></type>
<pdoType><![CDATA[]]></pdoType>
<active>1</active>
</connection>
</default_setup>
</resources>
<session_save><![CDATA[files]]></session_save>
</global>
<admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
</routers>
</admin>
</config> |
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (1)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)