Magento salesforce integrations with Customers in 3 Creative Steps

If you are running eCommerce website then you always fear to lose your customer accounts one solution is to keep the backup on daily basis but it comes very headache to keep lots of backups also need lots of space. Another solution is Magento 2 customers Salesforce integration.There are two ways for Magento Salesforce Integration for customers. One is to do is manually or another is to do it automatically (Using crone on specific events). We have described the automatically approach to synchronize Magento Salesforce Integration for customers.

Magento Salesforce Integration for Customers

Following are the steps to Magento Salesforce Integration for customers  based upon Magneto 2 customers creation or update

Step 1: Entering Observer event in the XML

This is the important part to handle the event into Magento 2. Go to your module ->etc->frontend and verify that the XML file named as the event.xml exists or not if exist then create. Open event.xml and do the following code inside this

 

    ............
    ............
    <event name="customer_save_after">
        <observer name="customer_save_after" instance="Package\Module Name\Observer\CustomerUpdateObserver" />
    </event>
    ............
    ............

Step 2: Creating Observer

Now we have to create the observer file to perform Magento Salesforce Integration operations according to our need. In my case my observer name is CustomerUpdateObserver.php . To create the file go to path project/app/code/package/module/Observer/ and create you observer here with following code.

add your needed helper files inside the constructor

 ........
 ......
 public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager, //to performs some operations 
        \Ipragmatech\Msintegration\Helper\Account\Data $helper //we have written our functions inside this helper
    ) {
        $this->_objectManager = $objectManager;
        $this->_helper = $helper;
    }

Add the following line of code inside the execute function of observer

       try {
            $customer = $observer->getEvent()->getCustomer();
            $salesforceId = $this->_helper->getClientSfId($customer->getId());
            if (empty($salesforceId)) {
                $id = $this->_helper->createAccount($customer);
                if (!empty($observer->getCustomerAddress())) {
                   $this->_helper->updateAddress($observer->getCustomerAddress(), $id);
                }
            } else {
                $this->_helper->updateAccount($salesforceId, $customer);
                if (!empty($observer->getCustomerAddress())) {
                    $this->_helper->updateAddress($observer->getCustomerAddress(), $id);

                }
            }
        } catch (\Exception $e) {
            // do what ever you wanna perform based on your exception log or some operation
        }


 

Step 3: Create Helper file

Go to helper folder create a folder named Account and inside folder create a file named Data.php. Inside the file, we need to write our functions for creating a customer account, updating customer, and updating customer address.

  • Creating customer account on the Salesforce
     public function createAccount($customer)
        {
            $name = $customer->getFirstname() . " " . $customer->getLastname();
            $email = $customer->getEmail();
            $lastUrl = "sobjects/Account/";
    
            $params = array(
                array(
                    "Name" => $name,
                )
    
            );
            $acountResult = $this->_helper->postAction($params, $lastUrl);
            $response = $acountResult ['response'];
            $status = $acountResult ['status'];
            $id = $response["id"];
            $mappingArray = [
                'customer_id' => $customer->getId(),
                'customer_salesforce_id' => $id,
    
            ];
            try {
                $model = $this->_objectManager->create('Ipragmatech\Msintegration\Model\Customermapping');
                $model->setData($mappingArray);
                $model->save();
            } catch (\Exception $e) {
                // put your own code
            }
    
            return $id;
        }
  • Updating customer account on Salesforce
     public function updateAccount($salesforceId, $customer)
        {
    
            $name = $customer->getFirstname() . " " . $customer->getLastname();
            $email = $customer->getEmail();
            $lastUrl = "sobjects/Account/$salesforceId";
            $params = array("Name" => $name);
            $updateAccount = $this->_helper->updateAction($params, $lastUrl);
            $status = $updateAccount ['status'];
    
            if ($status != 204) {
               // failed with status 
            }
            return true;
    
        }
  • Updating customer address on the Salesforce
        public function updateAddress($addressObject, $salesforceId)
        {
            $name = $addressObject->getFirstname() . " " . $addressObject->getLastname();
            $streets = $addressObject->getStreet();
            $country = $addressObject->getCountry();
            $city = $addressObject->getCity();
            $postCode = $addressObject->getPostCode();
            $company = $addressObject->getCompany();
            $state = $addressObject->getState();
            $telephone = $addressObject->getTelePhone();
            $strt = "";
            foreach ($streets as $street) {
                $strt .= "," . $street;
            }
    
            $lastUrl = "sobjects/Account/$salesforceId";
    
            $params = array(
                array(
                    "Name" => $name,
                    "BillingCity" => $city,
                    "BillingStreet" => $strt,
                    "BillingState" => $state,
                    "BillingPostalCode" => $postCode,
                    "BillingCountry" => $country,
                    "ShippingCity" => $city,
                    "ShippingStreet" => $strt,
                    "ShippingState" => $state,
                    "ShippingPostalCode" => $postCode,
                    "ShippingCountry" => $country,
                    "Phone" => $telephone
                )
            );
            try {
                $updateAddress = $this->_helper->updateAction($params, $lastUrl);
                $status = $updateAddress ['status'];
                if ($status != 204) {
                    //your own message call has been failed
                return true;
            } catch (\Exception $e) {
               //handle exception accordingly
            }
    
        }
    

Conclusion

The Magento Salesforce Integration for sync customers is an advantageous integration tool for Magento 2 and Salesforce. In this Magento Salesforce Integration you do not encounter any technical difficulties or confusion with it, support for this Magento Salesforce Integration is available, you can ask the question on this blog or you may have a look at a solution which we have already implemented for Magento Salesforce Integration, products and orders to Salesforce on their update/ create in Magento 2. Click here to know about our plugin. So don’t wait any longer, go for it!

7 Easy tips to improve magento store loading speed in 2017

Magento is an open-source eCommerce platform with a large number of active online merchants using it. Magento is very robust with great flexibility, scalability, and customization. Most of the CMS or eCommerce platforms like Magento and WooCommerce are having issues with speed and their performance degrading over time. Why do we need to optimize Magento performance?

    • According to KISSMetrics, 40% of the customer will abandon an eCommerce site if it takes longer than three seconds to load. More noticeable, an ONE-SECOND delay in load time can result in a 7% reduction in conversions.
    • As you know by now, Google is using site speed in web search ranking, and not only for Google but mainly for the User Experience (UX) on your eCommerce store.

In this article, we share some tips and tricks on how you can optimize Magento performance of your Magento based eCommerce store.

Tips to improve Magento store loading

1. Latest Version:

Always upgrade to the latest Magento version. Not only will you get more features and bug- and security fixes, but with every update, Magento performs better. You didn’t check every time to magneto website to for latest release, Magento does a good job of notifying you of important updates that become available within your messages inbox.

2. Enable Flat Catalog:

Magento uses the EAV model (entity attribute value) to store customer and product data. Enabling the flat catalog for categories and products merges product data into one table, thereby improving performance by responding to MySQL queries faster. If your eCommerce store has more than 1000 products, this can very beneficial.

Magento uses the EAV model (entity attribute value) to store customer and product data. Enabling the flat catalog for categories and products merges product data into one table, thereby improving performance by responding to MySQL queries faster. If your eCommerce store has more than 1000 products, this can very beneficial.
1. Login to your Magento Store as admin
2. Navigate to “System” → “Configuration” → “Catalog.”
3. Under “Frontend” change “Use Flat Catalog Category” and “Use Flat Catalog Product” to “Yes.”
4. Click on “Save Config.”
5. Clear the cache. The recommended way to do this is to delete everything from the /var/cache directory. You can also do it by navigating to “System” → “Cache Management” and clicking on “Flush Cache Storage” which is equivalent to deleting all the cache.

3. Cache & Indexers: 

There are many forms of caching that can be implemented with Magento. Combining NGINX + APC + Memcache + Varnish caching is a great way to success. Magento also comes with a built-in caching module as well. One more thing using Magento’s page caching. It reduces the web server processing load is taken off from the web server by serving pages already visited before from a cache which makes it a lot faster. There are lots of pages caching extensions available for Magento you can choose according to your requirement.

Using a PHP accelerator is another form of caching. They increase the performance of PHP scripts by caching them in their compiled state. You can use a PHP accelerator like APCXcacheeAccelerator  etc.

As we know Magento has lots of feature one of them is the indexer. Magento updates indexes on every object store by default, but in some cases, manual updates are required. Basically, indexes are used to speed up Database queries.

4. Code and Database Optimization:

Use a PHP accelerator like Zend and uninstall unnecessary PHP or Apache modules you don’t need or use. Improve your database performance using query indexing and broad optimization scripts. Use your DB management system to optimize the database on the frequent basis.

Magento has a compilation feature which has been reported to sometimes give up to a 50% performance boost. By default, Magento’s application files are searched in a certain order every time the page loads, which results in a lot of filesystem reads. In Magento admin, (top menu) System > Tools > Compilation, click Enable. This will take all the active scripts in Magento’s core structure and bring them to the front for faster website speed. The Magento compiler reduces these reads by copying all of these files into a single include directory and also caches ones that are used more frequently.

Optimizing your product images can dramatically increase the speed of your pages as this decreases their download times. You can compress them before uploading them using a tool like PhotoShop or there are a number of extensions you can use to auto-optimize them like TinyPNG Extension.

5. Merge CSS & JS:

Magento actually has a built in feature to concatenate (merge) your CSS and Javascript files into one file. This will reduce your total number of HTTP requests and in turn help speed up the loading of your pages. By using the advanced configuration in Magento admin, you can merge you JavaScript and CSS files, this reduces the load time. Please be aware that merging your javascript files may cause issues that need to be further resolved, but in the end, it certainly is best for your store.

6. Use CDN:

Implementing a Content Delivery Network (CDN) with Magento is one of the easiest ways to instantly see decreased load times. Using a content delivery network (CDN) such as MetaCDN enables serving your assets from a location geographically closest to your customers and hence reduces latency and increases download speed for those assets. Magento lets you define where certain assets (CSS, javascript, images, etc.) are loaded from such as a URL pointing to a CDN.  Magento CDN integration guide for details how to integrate the MetaCDN Site Accelerator into your Magento installation.

7. Hosting environment:

And last but not least, choosing a reliable and fast web host can be one of the most important decisions you will make when trying to improve Magento performance. We recommend staying away from shared hosting as they tend to overcrowd their servers and you will end up sharing resources between hundreds of website. We suggest going with a VPS like socialfoxhosting.comDigital Ocean, Linode etc. The reason is that you will be in complete control of your resources.

Conclusion

There are many ways to optimize Magento performance for your Magento based eCommerce site. Some of them we have discussed here. If you suffer from slow Magento performance, we can help you with Magento optimization to speed up Magento in no time! Making sure your eCommerce solution is running fast is one of the most important factors to your sales, SEO rankings, and overall best user experience.

For further reading

Ultimate Guide to send OTP using PHP(Twilio) in 5 minutes?

Are you facing an increase in attempts by spam to gain unauthorized access to your website? Once you’ve launched your website and you haven’t put any spam prevention measure in place. Verification Code allows you to protect your website by adding send sms verification functionality to User Registration functions before the user can see the full content of your website.

Verification Code is used Twilio Networks HTTP API to send messages, meaning you will need a valid Twilio Networks username and password in order to be able to send SMS messages. The account can be obtained from the https://www.twilio.com

Basic Php Integration to Send SMS with Twilio

1. How to Setup Twilio

To send SMS and outgoing messages perform an HTTP POST to the Messages resource URI. We will also use the Twilio PHP Library for making REST requests.

If you are using a Twilio Trial account for this example, you will only be able to send SMS messages to phone numbers that you have verified with Twilio. Phone numbers can be verified via your Twilio Console’s Verified Caller IDs. The ‘From’ parameter will also need to be a phone number you purchased from Twilio.

Create an account on Twilio.

  • Follow this link for create account on Twilio https://www.twilio.com.
  • If you created trial account on Twilio then you can send SMS to only the verified number of Twilio account.
  • For send SMS on any number you need to create premium account or upgrade the Twilio account.

2. Scheduled SMS campaigns

You’ll be assigned a number when you sign up to Twilio that you can use for testing but can’t send any actual texts through it. We just credited the account straight away so we could see the text coming through live. For us and probably most others we only needed to send a handful of texts whilst testing. As you’ll see further down this write up the library provided by Twilio is super simple and you are only charged when a text is successfully delivered so for the cost of having the convenience of actual messages being delivered to real phones was well worth it.

Sign up for a free Twilio account and buy a phone number.

3. Grab the PHP library and your API credentials

Download the PHP library provided by Twilio and put it somewhere that it can be included in the PHP script you want to use to send the SMS text. When sending your messages you’ll also need your account sid and your Auth Token. These can be grabbed from your account settings.

4. Set up the sending of the message

Firstly include the PHP library you’ve just downloaded and unzipped:

require "PATH YOUR TWILIO LIBRARY/Services/Twilio.php";
$client = new Services_Twilio('ACCOUNT SID HERE', 'AUTHTOKENHERE');

You have to find the your account SID and auth token in your console dashboard, and your phone number in your phone numbers list. Create a file called settings.php to store these values.

 
     $account_sid = "YOURACCOUNTSID";
     $auth_token = "YOURAUTHTOKEN";
     $twilio_phone_number = "+YOURTWILIONUMBER";

Create a file called send-sms.php and paste in the code below to:

  • Include the helper library and settings file
  • Create a Twilio client using our account credentials
  • Create a new message from our twilio number, to our cellphone
require "PATH YOUR TWILIO LIBRARY/Services/Twilio.php";
include 'settings.php';
$client = new Services_Twilio('ACCOUNT SID HERE', 'AUTHTOKENHERE'); 
$client->account->messages->create(array(
  'To' => 'NUMBER OF RECIPIENT',
  'From' => 'NUMBER PURCHASED WITH YOUR ACCOUNT',
  'Body' => "THIS IS YOUR TEXT MESSAGE",
));

Save your file and run it:
php send-sms.php

Conculsion

It’s as easy as that! You’ll now be sending live text messages via PHP and Twilio. You can keep an eye on the outgoing messages via the logs area of your Twilio account area and keep an eye on costs via the usage area.
Following on from that we set the header type text/plain and simply output what we’d like to be text back to the number that has sent the text, Twilio does the rest. That’s sending a text messages and handling a response via a text all wrapped with small amount of code.

References

Twilio Docs
The Twilio Php Helper Library
SEND SMS AND MMS MESSAGES IN PHP

Further Reading

Twilio voice: Receive Call On Your Android Mobile
Easy way to play an audio file on call in android using twilio
How to enable two step verification in Socialengine websites