Search This Blog

Thursday 26 July 2012

Magento: Create customer and send welcome email programatically

                try {
               
                    $customer = Mage::getModel("customer/customer");
                    $customer->website_id = 1;
                    $customer->store = 1;
                    $customer->entity_type_id     = 1;
                    $customer->group_id = 1;
                    $customer->email = $data['email'];
                   
                    $names = explode(" ", $data['name']);
                    $customer->firstname = $names[0];
                    if(count($names) > 1)
                    {
                        $customer->lastname = $names[1];
                    }
                    else
                    {
                        $customer->lastname = $names[0];
                    }
                   
                    $customer->created_in = "Admin";
                    $customer->created_at =date('Y-m-d H:i:s', time());
                    $customer->updated_at =date('Y-m-d H:i:s', time());
                    $customer->save();
                    //$customer->welcome_email = 1;
                    if ($customer->getWebsiteId())
                    {
                        $storeId = $customer->getSendemailStoreId();
                        $customer->sendNewAccountEmail('registered', '', $storeId);
                       
                     
                        $newPassword = $customer->generatePassword();
                        $customer->changePassword($newPassword);
                        $customer->sendPasswordReminderEmail();
                       
                        $customer->updated_at =date('Y-m-d H:i:s', time());
                        $customer->save();
                    }
                   
                    $data['customer_id'] = $customer->getEntityId();
               
                } catch (Exception $e){
               
                    echo $e->getMessage();
                   
                }

Wednesday 25 July 2012

Get Payflow Edition payment response details:

Extend the Payflowpro.php model app\code\local\Mage\Paypal\Model\Payflowpro.php

Add following line of code next to $this->_debug($debugData); in protected function _postRequest(Varien_Object $request) method Approx line number : 382
    Mage::getSingleton('customer/session')->setPaymentResponseInfo($debugData); // Storing the results in a temporary session

Add the following code in Order success method in OnepageController.php

    $order = Mage::getModel('sales/order')->load($lastOrderId);
    $debugData = Mage::getSingleton('customer/session')->getPaymentResponseInfo();
    if(is_array($debugData) and count($debugData) > 0)
    {
        $write = Mage::getSingleton('core/resource')->getConnection('core_write');
        $queryString = "CREATE TABLE IF NOT EXISTS `payment_response` (`id` int(11) NOT NULL auto_increment, `order_id` varchar(50) NOT NULL, `avsaddr` varchar(50) NOT NULL, `avszip` varchar(50) NOT NULL, `cvv2match` varchar(50) NOT NULL, `response` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
        $write->query($queryString);
      
        $order = Mage::getModel('sales/order')->load($lastOrderId);
        $query = "INSERT INTO `payment_response` (`order_id`, `avsaddr`, `avszip`, `cvv2match`, `response`) VALUES ('".$lastOrderId."', '".$debugData['avsaddr']."', '".$debugData['avszip']."', '".$debugData['cvv2match']."', '".json_encode($debugData)."')";
        $write->query($query);
      
        Mage::getSingleton('customer/session')->setPaymentResponseInfo('');//Unset the session information
    }

Do point 4 by extending OnepageController.php or Create an observer for order success and store the details into table

Add the following  code to display payment response in app\design\adminhtml\default\default\template\sales\order\view\tab\info.phtml

        if($_order->getEntityId())
        {
            $write = Mage::getSingleton('core/resource')->getConnection('core_write');
            $queryString = "CREATE TABLE IF NOT EXISTS `payment_response` (`id` int(11) NOT NULL auto_increment, `order_id` varchar(50) NOT NULL, `avsaddr` varchar(50) NOT NULL, `avszip` varchar(50) NOT NULL, `cvv2match` varchar(50) NOT NULL, `response` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
            $write->query($queryString);
          
          
            $write = Mage::getSingleton('core/resource')->getConnection('core_write');
            $query = "SELECT * FROM `payment_response` WHERE `order_id`=".$_order->getEntityId();
            $value = $write->query($query);
            $results = $value->fetchAll();
            $payResponse = json_decode($results[0]['response']);
        }
     if(count($results) > 0):
        <div><strong>Payment Response Information:</strong> </div>
        <div>
            CSC Match: echo $results[0]['cvv2match']; <br/>
            AVS Zip Match: echo $results[0]['avszip']; <br/>
            AVS Street Match: echo $results[0]['avsaddr'];<br/>
        </div>
    endif;

Magento: Very Useful Collection Functions

Magento: Very Useful Collection Functions

http://blog.chapagain.com.np/magento-collection-functions/

How to create a sandbox PayPal Payflow account


I've been working with PayPal PayFlow Pro a lot lately. But before I got the hang of it, I couldn't figure out how to create a sandbox account for Payflow.

As it goes, it's different than setting up a standard sandbox account. To set up a Payflow account for testing, you would walk through the sign up process as if you were signing up for a live Payflow account.

Once you get to the section in the sign up process where it is asking for the billing information, just cancel out of the process. This creates a test account for you at this point, which you can access by signing into PayPal Manager with the login and password that you created. The partner will be PayPal.

 
http://www.richardcastera.com/blog/how-to-create-a-sandbox-paypal-payflow-account

Magento: Delete Order Free Extensions

This is supported for all the versions and working fine. It supports deleting Orders,  Invoices, Shipments and Credit memos  related to the order.
http://www.magentocommerce.com/magento-connect/asperience-deleteorders.html

The following extension simply deletes the order:
http://www.magentocommerce.com/magento-connect/seamless-delete-order.html

Friday 13 July 2012

Magento: Regions list related by country

Function to get Regions list by Country:
 
 public function getRegionCollection()
    {
        if (!$this->_regionCollection) {
            $this->_regionCollection = Mage::getModel('directory/region')
                ->getResourceCollection()
                ->addCountryFilter($this->getAddress()->getCountryId())
                ->load();
        }
        return $this->_regionCollection;
    }

 
Adding More States and regions to the countries:
http://www.sycha.com/magento-add-custom-state-province-region-country

Magento: Display countries dropdown in custom module add / edit screen

Add below piece of code to the form page in customer module admin section

$countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false);
$fieldset->addField('country', 'select', array(
          'label'     => Mage::helper('core')->__('Country'),
          'name'      => 'country',
          'values'    => $countries,
  ));

Here 'country' is field name from your custom module


You are done!!!

Tuesday 10 July 2012

Magento: How to redirect to URL

$targetUrl = "http://www.google.com/";
Mage::app()->getFrontController()->getResponse()->setRedirect($targetUrl);

Monday 9 July 2012

Magento: addAttributeToFilter and OR condition in Collection

// Add OR condition:
$collection->addAttributeToFilter(array(
    array(
        'attribute' => 'field_name',
        'in'        => array(1, 2, 3),
        ),
    array(
        'attribute' => 'date_field',
        'from'      => '2000-09-10',
        ),
    ));
 
Defined at Magento Wiki...