SHARE
TWEET

Untitled

a guest Jun 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function sales_order_place_after($observer) {
  2.     $order = $observer->getEvent()->getOrder();
  3.     $quote_id = $order->getQuoteId();
  4.  
  5.     $orderId = $order->getEntityId();
  6.     $order = Mage::getModel('sales/order')->load($orderId);
  7.  
  8.     $text = "";
  9.     $fp = fopen('hide/directory/for/question' . $order->getIncrementId() . '.txt', 'w');
  10.  
  11.     // billing info
  12.     $billingAddress = $order->getBillingAddress();
  13.     $countryCode = $billingAddress->getCountryId();
  14.     $country = Mage::getModel('directory/country')->loadByCode($countryCode);
  15.     $countryName = $country->getName();
  16.  
  17.     //ship to billing info
  18.     $shippingAddress = $order->getShippingAddress();
  19.     $shippingAddressCountryCode = $shippingAddress->getCountryId();
  20.     $shippingAddressCountry = Mage::getModel('directory/country')->loadByCode($shippingAddressCountryCode);
  21.     $shippingAddressCountryName = $shippingAddressCountry->getName();
  22.  
  23.     $query = "Collect";
  24.     $shippingDescription = $order->getShippingDescription();
  25.     if (substr($shippingDescription, 0, strlen($query)) !== $query) {
  26.         $shippingCode = "PPD";
  27.         $shippingAgentCode = "UPS";
  28.         $shippingServiceCode = explode(" - UPS ", $shippingDescription)[1];
  29.         $carrierAccountNumber = "";
  30.         $shippingAmount = $shippingAddress->getShippingAmount();
  31.     } else {
  32.         // Shipping info
  33.         $shippingCode = "COL";
  34.         $shippingAgentCode = "";
  35.         $shippingServiceCode = "";
  36.  
  37.         $order_id = $order->getId();
  38.  
  39.         $carrierAccountNumber = Mage::getSingleton('checkout/session')->getCollectmemoComment();
  40.         $carrierAccountNumber = $carrierAccountNumber[$quote_id];
  41.         $shippingAmount = 0;
  42.     }
  43.  
  44.     //Order Info
  45.     $orderDate = $order->getCreatedAt();
  46.     $orderDateToShow = date('n/j/Y',strtotime($orderDate));
  47.  
  48.  
  49.     // Transaction Info
  50.     $orderTransactionDateTime = date('n/j/Y h:i:s A',strtotime($orderDate));
  51.  
  52.     // Account INfo
  53.     $userEmail = $order->getCustomerEmail();
  54.  
  55.     // Payment info
  56.     $payment = $order->getPayment();
  57.     $paymentCcType = $payment->getData('cc_type');
  58.     $paymentPoNumber = $payment->getData('po_number');
  59.     $paymentPoComment = $payment->getData('po_comment');
  60.     $paymentIdTwo = $payment->getCcTransId();
  61.     $poRefferenceNumber = $payment->getData('po_ref_number');
  62.  
  63.  
  64.     $paymentId = $payment->getCcTransId();
  65.     // $paymentId = $payment->getData('cc_trans_id');
  66.  
  67.     $paymentApproval = $payment->getData('cc_approval');
  68.     // $paymentApproval = $payment->getCcApproval();
  69.  
  70.  
  71.     $paymentCcStatus = "";
  72.  
  73.  
  74.     if ($paymentPoNumber != "" ) {
  75.         $paymentCcStatus;
  76.     } else {
  77.         $paymentCcStatus = "Approved";
  78.  
  79.     }
  80.  
  81.     if ($paymentCcType == "VI") {
  82.         $paymentCcType = "Visa";
  83.     } else if ($paymentCcType == "MC") {
  84.         $paymentCcType = "MasterCard";
  85.     } else if ($paymentCcType == "AE") {
  86.         $paymentCcType = "American Express";
  87.     } else if ($paymentCcType == "DI") {
  88.         $paymentCcType = "Discover";
  89.     }
  90.  
  91.     $item_incrementer = 1;
  92.     foreach ($order->getAllItems() as $itemId => $item) {
  93.         $fields = array($billingAddress->getCompany(), $billingAddress->getFirstname(), $billingAddress->getMiddlename(), $billingAddress->getLastname(), $billingAddress->getStreet(1), $billingAddress->getStreet(2), $billingAddress->getCity(), $billingAddress->getRegion(), $billingAddress->getPostcode(), $countryName, $billingAddress->getTelephone(), $userEmail ,$shippingAddress->getCompany(), $shippingAddress->getFirstname(), $shippingAddress->getMiddlename(), $shippingAddress->getLastname(), $shippingAddress->getStreet(1), $shippingAddress->getStreet(2), $shippingAddress->getCity(), $shippingAddress->getRegion(), $shippingAddress->getPostcode(), $shippingAddressCountryName, $shippingAddress->getTelephone(), $shippingCode, $shippingAgentCode, $shippingServiceCode, $carrierAccountNumber, $order->getShippingAmount(), $paymentPoNumber, $paymentPoComment, $poRefferenceNumber, $order->getIncrementId(), $orderDateToShow, $paymentCcStatus, $paymentCcType, $paymentApproval, $paymentId, $paymentIdTwo ,$order->getGrandTotal(), $orderTransactionDateTime,  $item_incrementer, $item->getSku(), $item->getQtyOrdered(), $item->getPrice() );
  94.  
  95.  
  96.         // echo '<pre>' , var_dump($fields) , '</pre>';
  97.  
  98.         $field_incrementer = 0;
  99.         foreach($fields as $field ) {
  100.             if ($field_incrementer > 0) {
  101.                 $text .= "t";
  102.             }
  103.             $text .= $field;
  104.  
  105.             $field_incrementer++;
  106.         }
  107.  
  108.         $text .= "rn";
  109.  
  110.         $item_incrementer++;
  111.     }
  112.  
  113.     fwrite($fp, $text) ;
  114.  
  115.     fclose($fp);
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top