Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Store hidden variable associated with customer
 
Mark Middleton
Jr. Member
 
Total Posts:  1
Joined:  2008-10-15
 

Hi there,

simply, I want to store an ID variable associated with each customer - if it exists in the initial URL:

example:

http://www.mysite.com/magento/index.php?id=abc123

The customer would click on a link to arrive at the site with the GET variable set above (the variable name will not ever change - just a simple referral ID) - we would like to set a session or cookie variable with the above ID that will be stored during checkout in the customer’s record.

Has someone done something similar that can point me in the right direction?

notes:
the customer never needs to see the ID
we can manage extracting the ID from the database after the order - no need for admin reporting, etc. at this time.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brilliand
Member
 
Total Posts:  34
Joined:  2008-08-29
 

I’m doing something like this - here are some relevant bits:

etc/config.xml:

<config>
    <global>
        <
events>
            <
sales_order_place_after>
                <
observers>
                    <
affiliates_observer>
                        <
type>singleton</type>
                        <class>
affiliates/observer</class>
                        <
method>apply_affiliate</method>
                    </
affiliates_observer>
                </
observers>
            </
sales_order_place_after>
            <
controller_front_init_before>
                <
observers>
                    <
affiliates_observer>
                        <
type>singleton</type>
                        <class>
affiliates/observer</class>
                        <
method>apply_cookie</method>
                    </
affiliates_observer>
                </
observers>
            </
controller_front_init_before>
        </
events>
    </global>
</
config>

Model/Observer.php:

public function apply_affiliate($observer)
    
{
        
if(isset($_COOKIE['affiliate_id']))
            
$observer->getEvent()->getOrder()->setAffiliateId($_COOKIE['affiliate_id']);
    
}

    
public function apply_cookie($observer)
    
{
        
if(isset($_GET['click']))
            
$affiliate $_GET['click'];
        elseif(isset(
$_GET['Click']))
            
$affiliate $_GET['Click'];
        if(isset(
$affiliate))
            
setcookie('affiliate_id'$affiliatetime()+$this->_getCookieDuration(), '/');
    
}

    
protected function _getCookieDuration()
    
{
        
return
            
60 *    //seconds
            
60 *    //minutes
            
24 *    //hours
            
5000;    //days
    
}

Model/Mysql4/Setup.php:

public function getDefaultEntities()
    
{
        
return array(
            
'order' => array(
                
'entity_model'    => 'sales/order',
                
'table'            =>'sales/order',
                
'increment_model'=>'eav/entity_increment_numeric',
                
'increment_per_store'=>true,
                
'attributes'    => array(
                    
'affiliate_id'  => array('type'=>'int'),
                ),
            ),
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top