Magento is a popular shopping cart solution that can be used in conjunction with Lead Gen & CRM's shopping cart.
Integrating with Lead Gen & CRM's shopping cart allows you to automatically record web transactions from your online store and attribute those sales to Lead Gen & CRM leads and campaigns.
This enables you to measure your end-to-end marketing ROI for eCommerce based businesses directly in Lead Gen & CRM. This article will detail how to integrate your shopping cart with Magento 1 and 2.
Article Contents
Trial | ||
Essential | ✓ | |
Advanced | ✓ | |
Ultimate | ✓ |
Administrators | ✓ | |
Company Managers | ||
Marketing Managers | ||
Sales Managers | ||
Salespersons | ||
Jr. Salespersons |
Integrating with Magento 1
Shopping Cart integrations require that Lead Gen & CRM tracking code be placed on the store pages.
To integrate Lead Gen & CRM with Magento 1, do the following:
- Locate your success.phtml file within Magento 1.
- Paste the following code into the success.phtml file:
<?php $fjs_orderID = $this->escapeHtml($this->getOrderId()); ?> <script type='text/javascript'> <?php $_data = getSharpSpringCode ( $fjs_orderID ); $transactionID = $_data['transactionID']; $_items = $_data['items']; ?> _ss.push(['_setTransaction', { 'transactionID': '<?php echo $transactionID; ?>', 'storeName': '<?php echo $_data['storeName'] ;?>', 'total': '<?php echo $_data['total'] ;?>', 'tax': '<?php echo $_data['tax'] ;?>', 'shipping': '<?php echo $_data['shipping'] ;?>', 'city': '<?php echo $_data['city'] ;?>', 'state': '<?php echo $_data['state'] ;?>', 'zipcode': '<?php echo $_data['zipcode'] ;?>', 'country': '<?php echo $_data['country'] ;?>', 'firstName' : '<?php echo $_data['firstName'] ;?>', 'lastName' : '<?php echo $_data['lastName'] ;?>', 'emailAddress' : '<?php echo $_data['emailAddress'] ;?>' }]); <?php foreach ($_items as $key => $item) { ?> _ss.push(['_addTransactionItem', { 'transactionID': '<?php echo $transactionID; ?>', 'itemCode': '<?php echo $item['itemCode']; ?>', 'productName': '<?php echo $item['productName']; ?>', 'category': '<?php echo $item['category']; ?>', 'price': '<?php echo $item['price']; ?>', 'quantity': '<?php echo $item['quantity']; ?>' }]); <?php } ?> _ss.push(['_completeTransaction', { 'transactionID': '<?php echo $transactionID; ?>' }]); </script> <?php function getSharpSpringCode ($OrderNumber) { $order = Mage::getModel('sales/order')->load($OrderNumber, 'increment_id'); $orderData = $order->getData(); $orderItems = $order->getItemsCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('product_type', array('eq'=>'simple')) ->load()->getData(); $shippData = $order->getShippingAddress()->getData(); /*******************************/ $ret = array(); $ret['transactionID']= $orderData['increment_id']; $ret['storeName'] = 'Your Store Name'; $ret['total'] = $orderData['grand_total']; $ret['tax'] = $orderData['tax_amount']; $ret['shipping'] = $orderData['shipping_amount']; $ret['city'] = $shippData['city']; $ret['state'] = $shippData['region']; $ret['zipcode'] = $shippData['postcode']; $ret['country'] = $shippData['country_id']; $ret['firstName'] = $shippData['firstname']; $ret['lastName'] = $shippData['lastname']; $ret['emailAddress'] = $orderData['customer_email']; /*******/ $sItems = array(); foreach ($orderItems as $key => $oItem) { $sItems[$key]['transactionID']=$ret['transactionID']; $sItems[$key]['itemCode']=$oItem['product_id']; $sItems[$key]['productName']=$oItem['name']; $sItems[$key]['category']=$oItem['product_type']; $sItems[$key]['price']=$oItem['price']; $sItems[$key]['quantity']=$oItem['qty_ordered']; } $ret['items'] = $sItems; return $ret; }
- In the pasted code, locate
'Your Store Name';
. - Change this to the name of your store.
Important: While Shopping Cart Abandonment was created to work with a variety of platforms, the implementation and ease of use will vary by platform. Lead Gen & CRM recommends having a developer handle implementing abandonment.
Integrating with Magento 2
Shopping Cart integrations require that Lead Gen & CRM tracking code be placed on the store pages.
To integrate Lead Gen & CRM with Magento 2, do the following:
- Locate your success.phtml file within Magento 2.
- Paste the following code into the success.phtml file:
<?php $lid = $this->getOrderId(); echo "Order ID:".$lid."<br/>"; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $order = $objectManager->create('Magento\Sales\Model\Order')->load($lid); $shippingAddress = $order->getShippingAddress(); //Echo some values for testing purposes echo "Order Total: ".$order->getGrandTotal()."<br/>"; echo "Telephone No: ".$shippingAddress->getTelephone()."<br/>"; echo "postcode: ".$shippingAddress->getPostcode()."<br/>"; ?> <script type='text/javascript'> _ss.push(['_setTransaction', { 'transactionID': '<?php echo $lid; ?>', 'storeName': 'Your Store Name', 'total': '<?php echo $order->getGrandTotal(); ?>', 'tax': '<?php echo $order->getTaxAmount(); ?>', 'shipping': '<?php echo $order->getShippingAmount(); ?>', 'city': '<?php echo $shippingAddress->getCity(); ?>', 'state': '<?php echo $shippingAddress->getRegion(); ?>', 'zipcode': '<?php echo $shippingAddress->getPostcode(); ?>', 'country': '<?php echo $shippingAddress->getCountryId(); ?>', 'firstName' : '<?php echo $shippingAddress->getFirstname(); ?>', 'lastName' : '<?php echo $shippingAddress->getLastname(); ?>', 'emailAddress' : '<?php echo $order->getCustomerEmail(); ?>' }]); </script> <?php $items = $order->getAllItems(); foreach($items as $i): $_product = $objectManager->create('Magento\Catalog\Model\Product')->load($i->getProductId())->getSku(); $_price = $objectManager->create('Magento\Catalog\Model\Product')->load($i->getProductId())->getPrice(); $_name = $objectManager->create('Magento\Catalog\Model\Product')->load($i->getProductId())->getName(); //Echo for Testing Purposes echo "product sku:".$_product."<br/>"; ?> <script type='text/javascript'> _ss.push(['_addTransactionItem', { 'transactionID': '<?php echo $lid; ?>', 'itemCode': '<?php echo $_product; ?>', 'productName': '<?php echo $_name; ?>', 'category': 'General', 'price': '<?php echo $_price; ?>', 'quantity': '<?php echo intval($i->getQtyOrdered()); ?>', }]); </script> <?php endforeach; ?> <script type='text/javascript'> _ss.push(['_completeTransaction', { 'transactionID': '<?php echo $lid; ?>' }]); </script>
- In the pasted code, locate
'Your Store Name';
. - Change this to the name of your store.
Important: While Shopping Cart Abandonment was created to work with a variety of platforms, the implementation and ease of use will vary by platform. Lead Gen & CRM recommends having a developer handle implementing abandonment.