0

I've been writing a script that exports a CSV into a directory. The CSV contains the information of the order, once the order has been made. The issue i'm having is exporting the information for transaction ID and CC Approval. Does anyone have any idea on how to gather that information?

Below you can see the two vars that are trying to gather the information $paymentId and $paymentApproval

public function sales_order_place_after($observer) {
    $order = $observer->getEvent()->getOrder();
    $quote_id = $order->getQuoteId();

    $orderId = $order->getEntityId();
    $order = Mage::getModel('sales/order')->load($orderId);

    $text = "";
    $fp = fopen('hide/directory/for/question' . $order->getIncrementId() . '.txt', 'w');

    // billing info
    $billingAddress = $order->getBillingAddress();
    $countryCode = $billingAddress->getCountryId();
    $country = Mage::getModel('directory/country')->loadByCode($countryCode);
    $countryName = $country->getName();

    //ship to billing info
    $shippingAddress = $order->getShippingAddress();
    $shippingAddressCountryCode = $shippingAddress->getCountryId();
    $shippingAddressCountry = Mage::getModel('directory/country')->loadByCode($shippingAddressCountryCode);
    $shippingAddressCountryName = $shippingAddressCountry->getName();

    $query = "Collect";
    $shippingDescription = $order->getShippingDescription();
    if (substr($shippingDescription, 0, strlen($query)) !== $query) {
        $shippingCode = "PPD";
        $shippingAgentCode = "UPS";
        $shippingServiceCode = explode(" - UPS ", $shippingDescription)[1];
        $carrierAccountNumber = "";
        $shippingAmount = $shippingAddress->getShippingAmount();
    } else {
        // Shipping info
        $shippingCode = "COL";
        $shippingAgentCode = "";
        $shippingServiceCode = "";

        $order_id = $order->getId();

        $carrierAccountNumber = Mage::getSingleton('checkout/session')->getCollectmemoComment();
        $carrierAccountNumber = $carrierAccountNumber[$quote_id];
        $shippingAmount = 0;
    }

    //Order Info
    $orderDate = $order->getCreatedAt();
    $orderDateToShow = date('n/j/Y',strtotime($orderDate));


    // Transaction Info
    $orderTransactionDateTime = date('n/j/Y h:i:s A',strtotime($orderDate));

    // Account INfo
    $userEmail = $order->getCustomerEmail();

    // Payment info
    $payment = $order->getPayment();
    $paymentCcType = $payment->getData('cc_type');
    $paymentPoNumber = $payment->getData('po_number');
    $paymentPoComment = $payment->getData('po_comment');
    $paymentIdTwo = $payment->getCcTransId();
    $poRefferenceNumber = $payment->getData('po_ref_number'); 


    $paymentId = $payment->getCcTransId();
    // $paymentId = $payment->getData('cc_trans_id');

    $paymentApproval = $payment->getData('cc_approval');
    // $paymentApproval = $payment->getCcApproval();


    $paymentCcStatus = "";


    if ($paymentPoNumber != "" ) {
        $paymentCcStatus;
    } else {
        $paymentCcStatus = "Approved"; 

    }

    if ($paymentCcType == "VI") {
        $paymentCcType = "Visa";
    } else if ($paymentCcType == "MC") {
        $paymentCcType = "MasterCard";
    } else if ($paymentCcType == "AE") {
        $paymentCcType = "American Express";
    } else if ($paymentCcType == "DI") {
        $paymentCcType = "Discover";
    }

    $item_incrementer = 1;
    foreach ($order->getAllItems() as $itemId => $item) {
        $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() );


        // echo '<pre>' , var_dump($fields) , '</pre>';

        $field_incrementer = 0;
        foreach($fields as $field ) {
            if ($field_incrementer > 0) {
                $text .= "\t";
            }
            $text .= $field;

            $field_incrementer++;
        }

        $text .= "\r\n";

        $item_incrementer++;
    }

    fwrite($fp, $text) ;

    fclose($fp);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.