Advertisement
Guest User

SHARE A SALE

a guest
Nov 19th, 2019
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. For Magento versions 2.0 and higher, first locate the file /vendor/magento/module-checkout/view/frontend/templates/success.phtml file.
  2.  
  3. As always, make a backup of the file first. Once you've made a backup, add the following code to the end of the file:
  4.  
  5. <!-- begin ShareASale.com affiliate tracking -->
  6. <?php
  7. $merchantid = "93162";
  8. $sscidmode = 6;
  9. $sscid = ! empty( $_COOKIE['shareasaleMagentoSSCID'] ) ? $_COOKIE['shareasaleMagentoSSCID'] : '';
  10. $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
  11. $orderId = $block->getOrderId();
  12. $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
  13. $subtotal = $order->getSubtotal();
  14. $discount = $order->getDiscountAmount();
  15. $affiliateTotal = ($subtotal + $discount);
  16. $ordered_items = $order->getAllVisibleItems();
  17. $skulist = '';
  18. $pricelist = '';
  19. $quantitylist = '';
  20. $last_index = array_search(end($ordered_items), $ordered_items, true);
  21. foreach($ordered_items as $index => $item){
  22. $delimiter = $index === $last_index ? '' : ',';
  23. $skulist .= $item->getSku() . $delimiter;
  24. $quantitylist .= ceil($item->getQtyOrdered()) . $delimiter;
  25. $pricelist .= ($item->getProduct()->getFinalPrice() - ($item->getDiscountAmount() / $item->getQtyOrdered())) . $delimiter;
  26. }
  27. $couponcodes = $order->getCouponCode();
  28. $newcustomer = '';
  29. $customer = $order->getCustomerId();
  30. if($customer){
  31. $orderCount =
  32. $objectManager
  33. ->create('\Magento\Sales\Model\ResourceModel\Order\CollectionFactory')
  34. ->create()
  35. ->addFieldToSelect('*')
  36. ->addFieldToFilter('customer_id', $customer)
  37. ->setOrder('created_at','desc')
  38. ->count();
  39. $newcustomer = ($orderCount > 1 ? 0 : 1);
  40. }
  41. $currency = $order->getOrderCurrencyCode();
  42. //render pixel below
  43. ?>
  44. <img id="_SHRSL_img_1" src="https://shareasale.com/sale.cfm?tracking=<?php echo $orderId ?>&amp;amount=<?php echo $affiliateTotal ?>&amp;transtype=sale&amp;merchantID=<?php echo $merchantid ?>&amp;couponcode=<?php echo $couponcodes ?>&amp;skulist=<?php echo $skulist ?>&amp;quantitylist=<?php echo $quantitylist ?>&amp;pricelist=<?php echo $pricelist ?>&amp;newcustomer=<?php echo $newcustomer ?>&amp;currency=<?php echo $currency ?>&amp;sscid=<?php echo $sscid ?>&amp;sscidmode=<?php echo $sscidmode ?>&amp;v=2.0" width="1" height="1">
  45. <script defer async type="text/javascript" src="https://shareasale-analytics.com/j.js"></script>
  46. <!-- end ShareASale.com affiliate tracking -->
  47.  
  48.  
  49.  
  50. In your Magento admin, navigate to the sidebar >> Content >> Configuration under Design >> click edit next to your default store view >> HTML Head >> Scripts and Stylesheets section. Copy and paste the code below into it, then click the "Save Configuration" button in the top-right corner.
  51.  
  52. <script>var shareasaleMagentoSSCID=shareasaleMagentoGetParameterByName("sscid");function shareasaleMagentoSetCookie(e,a,t,o,n){if(e&&a){var r,s=o?"; path="+o:"",i=n?"; domain="+n:"",g="";t&&((r=new Date).setTime(r.getTime()+t),g="; expires="+r.toUTCString()),document.cookie=e+"="+a+g+s+i}}function shareasaleMagentoGetParameterByName(e,a){a||(a=window.location.href),e=e.replace(/[\[\]]/g,"\\$&");var t=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)").exec(a);return t?t[2]?decodeURIComponent(t[2].replace(/\+/g," ")):"":null}shareasaleMagentoSSCID&&shareasaleMagentoSetCookie("shareasaleMagentoSSCID",shareasaleMagentoSSCID,94670778e4,"/");</script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement