Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
  1. #11
    Join Date
    Jun 2008
    Posts
    328
    Plugin Contributions
    0

    Default Re: Extract Transaction's Customer Info to be written to a file?

    Quote Originally Posted by DrByte View Post
    Isn't the object named $order, not $orders ?
    No, it is $orders, as can be seen in the attached image.

    I am still lost as to why the contents of the $orders->fields[] array is empty or what is the proper stage to "snatch" it. I tried the following notificatications - to no avail:

    NOTIFY_HEADER_START_CHECKOUT_SUCCESS
    NOTIFY_HEADER_END_CHECKOUT_SUCCESS
    NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL

    I am still successful at writing test text (and variables) to the test file in upon any of the above notifications. However, the $orders->fields[] seems to be empty when I do that, since non of those fields get written to the file.

    Any idea how to snatch correctly those $orders->fields[] values?

    Thanks,
    Daniel
    Attached Images Attached Images  

  2. #12
    Join Date
    Jan 2004
    Posts
    66,419
    Blog Entries
    7
    Plugin Contributions
    277

    Default Re: Extract Transaction's Customer Info to be written to a file?

    A "queryFactoryResult" object is the returned data from a database query.

    The actual order object that contains the data for the currently in-progress order while checkout_process is creating and storing an order, is $order.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #13
    Join Date
    Jun 2008
    Posts
    328
    Plugin Contributions
    0

    Default Re: Extract Transaction's Customer Info to be written to a file?

    Quote Originally Posted by DrByte View Post
    A "queryFactoryResult" object is the returned data from a database query.

    The actual order object that contains the data for the currently in-progress order while checkout_process is creating and storing an order, is $order.
    Thanks for pointing this out. I tried the same exact thing with $order (instead of $orders) but I am receiving the same results.

    By now I am almost certain that my problem is not a syntax bug, but something conceptual that I am missing.

    What could it be?

  4. #14
    Join Date
    Jun 2008
    Posts
    328
    Plugin Contributions
    0

    help question Re: Extract Transaction's Customer Info to be written to a file?

    Well, I haven't solved the mystery yet, but I can already admit to one conceptual mistake: I forgot to read the source code (and relied, instead, on documentation and existing threads in the Zen Cart forums).

    Also, so that I can save other beginners from the same syntax mistake, the correct syntax for accessing the $orders->field[] array elements is $orders->fields['customers_name'], not $orders->fields[customers_name] (long live single quotes...)

    Fixing this syntax mistake didn't help, of course, because IMHO my problem lies within the scope/lifetime of the objects I am trying to "snatch".

    In the meanwhile, I am providing here a snapshot of the my partially working solution, along with what actually gets written to the file:

    includes\auto_loaders\config.writeCustInfo.php:
    PHP Code:
    <?php

    $autoLoadConfig
    [90][] = array('autoType'=>'class',
                                  
    'loadFile'=>'observers/class.writeCustInfo.php');
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                  
    'className'=>'writeCustInfo',
                                  
    'objectName'=>'writeCustInfo');

    ?>
    includes\classes\observers\class.writeCustInfo.php:
    PHP Code:
    <?php
    /**
     * Observer class to write customer info to a temp file.
     */
    class writeCustInfo extends base {

     
    /**  constructor method !
       * 
       * Attach observer class to the global $zco_notifier and watches for a single notifier event.
       */
      
    function writeCustInfo() {
        global 
    $zco_notifier;
        
    $zco_notifier->attach($this, array('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL'));
      }

     
    /**   Actual Method that writes customer info to file
       * 
       * Called by observed class when any of the notifiable events occur
       *
       * @param object $class
       * @param string $eventID
       */
      
    function update(&$class$eventID) {
        
    $myFile "testFile.txt";
        
    $fh fopen($myFile'a') or die("can't open file");

        
    /**
        * Write the following fields to a file
        */
        
    $stringData "This is the first line of ";
        
    $stringData $stringData $myFile;
        
    fwrite($fh$stringData);
        
    fwrite($fh"\r\n");
        
        
    $customerInfo "Customer Information: \r\n";
        
    $customerInfo $customerInfo $myFile;
        
    $customerInfo $customerInfo $order->fields['customers_name'];
        
    $customerInfo $customerInfo $order->fields['customers_company'];
        
    $customerInfo $customerInfo $order->fields['customers_street_address'];
        
    fwrite($fh$customerInfo);
        
    fwrite($fh"\r\n");

        
    fclose($fh);    
      }
    }
    ?>
    The output, in testFile.txt:
    This is the first line of testFile.txt
    Customer Information:
    testFile.txt
    I will post here the complete solution, once I have it. But if you notice any gross mistake in my code that could explain the mystery, that would help me post the solution faster.

    Thanks,
    Daniel

  5. #15
    Join Date
    Jan 2004
    Posts
    66,419
    Blog Entries
    7
    Plugin Contributions
    277

    Default Re: Extract Transaction's Customer Info to be written to a file?

    Try making the following alterations ...

    from this:
    Code:
        $customerInfo = "Customer Information: \r\n";
        $customerInfo = $customerInfo . $myFile;
        $customerInfo = $customerInfo . $order->fields['customers_name'];
        $customerInfo = $customerInfo . $order->fields['customers_company'];
        $customerInfo = $customerInfo . $order->fields['customers_street_address'];
    to this:
    Code:
        global $order;
        $customerInfo = "Customer Information: \r\n";
        $customerInfo .= 'First: ' . $order->customer['firstname'] . "\r\n";
        $customerInfo .= 'Last: ' . $order->customer['lastname'] . "\r\n";
        $customerInfo .= 'Email: ' . $order->customer['email_address'] . "\r\n";
        $customerInfo .= "\r\n\r\n\r\nOther information available is described here:\r\n" . print_r($order, true) . "\r\n";
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #16
    Join Date
    Jun 2008
    Posts
    328
    Plugin Contributions
    0

    Have a Drink Re: Extract Transaction's Customer Info to be written to a file?

    Dr. Byte - you seem to be a true doctor - Thank you so much!

    I did discover by myself that the class 'order' has no member called 'fields' but has a member named 'customer' (array) - and I tried a fix similar to what you suggested, which of course didn't work because... I was missing the line
    PHP Code:
    global $order
    That was my "conceptual" mistake. Although I remembered to place a similar line in the observer's constructor:
    PHP Code:
    global $zco_notifier
    I failed to tell update() that $order is global.

    Now all is well and here is the final result (config.writeCustInfo.php remains unchanged and so I will post the complete code for class.writeCustInfo.php only):

    PHP Code:
    <?php
    /**
     * Observer class to write customer info to a temp file.
     */
    class writeCustInfo extends base {

     
    /**  constructor method !
       * 
       * Attach observer class to the global $zco_notifier and watches for a single notifier event.
       */
      
    function writeCustInfo() {
        global 
    $zco_notifier;
        
    $zco_notifier->attach($this, array('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL'));
      }

     
    /**   Actual Method that writes customer info to file
       * 
       * Called by observed class when any of the notifiable events occur
       *
       * @param object $class
       * @param string $eventID
       */
      
    function update(&$class$eventID) {
        
    $myFile "testFile.txt";
        
    $fh fopen($myFile'a') or die("can't open file");

        
    /**
        * Write the following fields to a file
        */
        
    $stringData "This is the first line of ";
        
    $stringData $stringData $myFile;
        
    fwrite($fh$stringData);
        
    fwrite($fh"\r\n");

        
        global 
    $order;
        
    $customerInfo "Customer Information: \r\n";
        
    $customerInfo .= 'First: ' $order->customer['firstname'] . "\r\n";
        
    $customerInfo .= 'Last: ' $order->customer['lastname'] . "\r\n";
        
    $customerInfo .= 'Email: ' $order->customer['email_address'] . "\r\n";
     
    //   $customerInfo .= "\r\n\r\n\r\nOther information available is described here:\r\n" . print_r($order, true) . "\r\n";

        
        
    fwrite($fh$customerInfo);
        
    fwrite($fh"\r\n");

        
    fclose($fh);    
      }
    }
    ?>
    Thanks again!
    Daniel

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: 7 Jun 2010, 03:22 AM
  2. which file inserts customer info in DB?
    By g_force in forum Managing Customers and Orders
    Replies: 6
    Last Post: 12 Feb 2010, 08:11 PM
  3. Storing order/customer info in a flat file
    By mithaimate in forum General Questions
    Replies: 0
    Last Post: 30 Sep 2009, 10:29 AM
  4. What file holds all the order and customer info ?
    By snarkys in forum Managing Customers and Orders
    Replies: 3
    Last Post: 19 Nov 2006, 12:26 PM
  5. Can I extract a customer list???
    By Honeysmom in forum General Questions
    Replies: 2
    Last Post: 12 Jul 2006, 02:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR