Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- For Magento versions 2.0 and higher, first locate the file /vendor/magento/module-checkout/view/frontend/templates/success.phtml file.
- 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:
- <!-- begin ShareASale.com affiliate tracking -->
- <?php
- $merchantid = "93162";
- $sscidmode = 6;
- $sscid = ! empty( $_COOKIE['shareasaleMagentoSSCID'] ) ? $_COOKIE['shareasaleMagentoSSCID'] : '';
- $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
- $orderId = $block->getOrderId();
- $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
- $subtotal = $order->getSubtotal();
- $discount = $order->getDiscountAmount();
- $affiliateTotal = ($subtotal + $discount);
- $ordered_items = $order->getAllVisibleItems();
- $skulist = '';
- $pricelist = '';
- $quantitylist = '';
- $last_index = array_search(end($ordered_items), $ordered_items, true);
- foreach($ordered_items as $index => $item){
- $delimiter = $index === $last_index ? '' : ',';
- $skulist .= $item->getSku() . $delimiter;
- $quantitylist .= ceil($item->getQtyOrdered()) . $delimiter;
- $pricelist .= ($item->getProduct()->getFinalPrice() - ($item->getDiscountAmount() / $item->getQtyOrdered())) . $delimiter;
- }
- $couponcodes = $order->getCouponCode();
- $newcustomer = '';
- $customer = $order->getCustomerId();
- if($customer){
- $orderCount =
- $objectManager
- ->create('\Magento\Sales\Model\ResourceModel\Order\CollectionFactory')
- ->create()
- ->addFieldToSelect('*')
- ->addFieldToFilter('customer_id', $customer)
- ->setOrder('created_at','desc')
- ->count();
- $newcustomer = ($orderCount > 1 ? 0 : 1);
- }
- $currency = $order->getOrderCurrencyCode();
- //render pixel below
- ?>
- <img id="_SHRSL_img_1" src="https://shareasale.com/sale.cfm?tracking=<?php echo $orderId ?>&amount=<?php echo $affiliateTotal ?>&transtype=sale&merchantID=<?php echo $merchantid ?>&couponcode=<?php echo $couponcodes ?>&skulist=<?php echo $skulist ?>&quantitylist=<?php echo $quantitylist ?>&pricelist=<?php echo $pricelist ?>&newcustomer=<?php echo $newcustomer ?>&currency=<?php echo $currency ?>&sscid=<?php echo $sscid ?>&sscidmode=<?php echo $sscidmode ?>&v=2.0" width="1" height="1">
- <script defer async type="text/javascript" src="https://shareasale-analytics.com/j.js"></script>
- <!-- end ShareASale.com affiliate tracking -->
- 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.
- <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