Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2011
    Posts
    13
    Plugin Contributions
    0

    help question Where can I hook in some code to run after an order is made?

    I am not the worlds greatest coder but I can usually hack together bits and pieces as needed, but in the hopes of saving myself a medium lifespan's worth of time I wonder if anyone can point me in the general direction of where I can hook in some code..

    Basically what I need to do is check through the order after it has been placed and paid for for a specific product, if that product is included in the order I need to perform some calculations on attributes and then email the results to myself.

    The email forms a check list which I use to make the product and check off various quality issues during the manufacture.

    Getting the info from the database, extracting the bits I need, forming the email and sending it are not problems I need help with, that is all pretty much already done on my existing site.

    What I need to know is where I can intercept the program flow and slip my hack in, it needs to be done after the order has been made and paid for. At the moment I use Paypal IPN and do everything in the IPN validation script on my non zencart site.

    If anyone has any ideas I would be very grateful ;)

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,873
    Plugin Contributions
    96

    Default Re: Where can I hook in some code to run after an order is made?

    You could create an observer (refer to http://www.zen-cart.com/wiki/index.p...Observer_Class) that watches for NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS.

  3. #3
    Join Date
    Apr 2011
    Posts
    13
    Plugin Contributions
    0

    Default Re: Where can I hook in some code to run after an order is made?

    Quote Originally Posted by lat9 View Post
    You could create an observer (refer to http://www.zen-cart.com/wiki/index.p...Observer_Class) that watches for NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS.

    MMMM, Did I mention I am not the worlds greatest coder? Maybe I should have elaborated slightly and said I am a crap coder ;)

    Surprisingly, given that I have never used classes in my life, some (most) of that does actually sense to me.

    I am not sure why you are suggesting NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS though. I am assuming that would be after the products have been added to the order ?

    Wouldn't NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL be pretty much the last thing in the checkout process, I am assuming that would be called once the confirmation email has been sent to the customer and therefore when everything has gone through correctly - i.e. payment made etc.

    If that is the case that would maybe be the best place, as essentially I would just be sending out another email to myself.

    So if my thinking on that is correct, how could I obtain the order number for the order just processed in that observer?

  4. #4
    Join Date
    Feb 2010
    Posts
    154
    Plugin Contributions
    0

    Default Re: Where can I hook in some code to run after an order is made?

    Louise, been a while since you opened this thread. Is it still relevant to you? (I've just been playing with the NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL observer.)

  5. #5
    Join Date
    Apr 2011
    Posts
    13
    Plugin Contributions
    0

    Default Re: Where can I hook in some code to run after an order is made?

    Quote Originally Posted by Celtic View Post
    Louise, been a while since you opened this thread. Is it still relevant to you? (I've just been playing with the NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL observer.)
    It is still relevant, I have put it on the back burner for now while I get the shop up and running, but eventually I will probably need to implement the changes.

    In fact there are a couple of things I would need to tie in with this, one being updating a separate database with donations made, at the moment my IPN routine takes care of that so my main website is updated with PDSA donations in real time.

  6. #6
    Join Date
    Feb 2010
    Posts
    154
    Plugin Contributions
    0

    Default Re: Where can I hook in some code to run after an order is made?

    Louise,

    For what it's worth, here's the two files (auto_loader & observer) I cobbled together to send a 'packing list' email triggered by the NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL notifier...


    /includes/auto_loaders/config.celtic_PackingListEmail.php
    PHP Code:


    <?php
    // includes/auto_loaders/config.celtic_PackingList.php   ... 
    //
    // Config for class to send a Packing list email after order completion
    // by Celtic, 02-June-2011
    //
    // see also /includes/classes/observers/class.celtic_PackingListEmail.php

    // Note: 10 has been chosen to cause the observer class to be loaded before the session is started. 
    // Note: 90 has been chosen as the offset since the observer needs to attach to the $SESSION['cart'] class, which is instantiated at offset 80.

        
    $autoLoadConfig[10][] = array('autoType'=>'class',
                                     
    'loadFile'=>'observers/class.celtic_PackingListEmail.php');

        
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                     
    'className'=>'celticPackingListEmail',
                                     
    'objectName'=>'celticPackingListEmail');
    ?>

    /includes/classes/observers/class.celtic_PackingListEmail.php
    PHP Code:


    <?php
    // /includes/classes/observers/class.celtic_PackingListEmail.php
    //
    // Observer class to send a Packing list email after order completion
    // by Celtic, 02-June-2011
    //
    //    see also /includes/auto_loaders/config.celtic_PackingListEmail.php

    class celticPackingListEmail extends base {

        
    // CONSTRUCTOR METHOD
        
    function celticPackingListEmail() {
                   
    $this->attach$this, Array('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL'));
        }
        
        
    // UPDATE METHOD
        
    function update( &$class$eventID$paramsArray = array() ) {
                
    // create a packing list email for this order and send to packing department
                
                
    $packingListEmailTo "[email protected]";
                
    $packingListSubject "PACKING LIST: " EMAIL_ORDER_NUMBER_SUBJECT $paramsArray[0] . " " $paramsArray[3]['INTRO_DATE_ORDERED'];

                
    $packingDetails 
                    
    $paramsArray[3]['PRODUCTS_DETAIL'] . "\n\n" 
                    
    $paramsArray[3]['ADDRESS_DELIVERY_DETAIL'] . "\n\n" 
                    
    $paramsArray[3]['SHIPPING_METHOD_DETAIL'] . "\n\n" 
                    
    $paramsArray[3]['ORDER_COMMENTS'] . "\n\n";

                
    $html_msg "";    //$packingDetails;            

                // send packing list email
            
    zen_mail(''$packingListEmailTo$packingListSubject$packingDetailsSTORE_NAMEEMAIL_FROM$html_msg'checkout_extra');

        }
    }
    ?>
    Note: to send an HTML format email needs all the various/relevant HTML email settings switched on within your Zencart admin, so I've just left mine blank in the update method above. When it's blank, zen_mail() just sends a plaintext one.

    You mentioned wanting to get the order number. You can see in the update() function that it is passed an array called $paramsArray[] and in the $packingListSubject line I am getting the order number from $paramsArray[0].

    To see what $paramsArray[] contains, just put: print_r($paramsArray); exit; inside the update method.

    Hope it helps in some way when you get back to this,
    Celtic

  7. #7
    Join Date
    Apr 2011
    Posts
    13
    Plugin Contributions
    0

    Default Re: Where can I hook in some code to run after an order is made?

    That is brilliant! Thank you so much for sharing your knowledge it is really appreciated ;)

    Probably 90% of what I need is there already!

    Can I just ask, is this triggered after checkout is completed successfully and payment made?

  8. #8
    Join Date
    Feb 2010
    Posts
    154
    Plugin Contributions
    0

    Default Re: Where can I hook in some code to run after an order is made?

    Glad that's of use.

    Yes, this is triggered after checkout/payment is complete. NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL is triggered, as it suggests, after the order email is sent to the store owner, so we're just tagging onto that and sending another email somewhere else. The $paramsArray[] is a bit limiting as to what you can pull out of it, but once you have the order number you can query the database directly for whatever other info you want.

    In case it's of use, NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL is triggered from the bottom of: /includes/classes/order.php

  9. #9
    Join Date
    Apr 2011
    Posts
    13
    Plugin Contributions
    0

    Default Re: Where can I hook in some code to run after an order is made?

    I would need the list of items ordered and attributes selected, but I can as you say pull that from the DB if need be.

    Thanks again ;)

  10. #10
    Join Date
    Jul 2012
    Posts
    15
    Plugin Contributions
    0

    Default Re: Where can I hook in some code to run after an order is made?

    Quote Originally Posted by Celtic View Post
    Louise,

    For what it's worth, here's the two files (auto_loader & observer) I cobbled together to send a 'packing list' email triggered by the NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL notifier...


    /includes/auto_loaders/config.celtic_PackingListEmail.php
    PHP Code:


    <?php
    // includes/auto_loaders/config.celtic_PackingList.php   ... 
    //
    // Config for class to send a Packing list email after order completion
    // by Celtic, 02-June-2011
    //
    // see also /includes/classes/observers/class.celtic_PackingListEmail.php

    // Note: 10 has been chosen to cause the observer class to be loaded before the session is started. 
    // Note: 90 has been chosen as the offset since the observer needs to attach to the $SESSION['cart'] class, which is instantiated at offset 80.

        
    $autoLoadConfig[10][] = array('autoType'=>'class',
                                     
    'loadFile'=>'observers/class.celtic_PackingListEmail.php');

        
    $autoLoadConfig[90][] = array('autoType'=>'classInstantiate',
                                     
    'className'=>'celticPackingListEmail',
                                     
    'objectName'=>'celticPackingListEmail');
    ?>

    /includes/classes/observers/class.celtic_PackingListEmail.php
    PHP Code:


    <?php
    // /includes/classes/observers/class.celtic_PackingListEmail.php
    //
    // Observer class to send a Packing list email after order completion
    // by Celtic, 02-June-2011
    //
    //    see also /includes/auto_loaders/config.celtic_PackingListEmail.php

    class celticPackingListEmail extends base {

        
    // CONSTRUCTOR METHOD
        
    function celticPackingListEmail() {
                   
    $this->attach$this, Array('NOTIFY_ORDER_AFTER_SEND_ORDER_EMAIL'));
        }
        
        
    // UPDATE METHOD
        
    function update( &$class$eventID$paramsArray = array() ) {
                
    // create a packing list email for this order and send to packing department
                
                
    $packingListEmailTo "[email protected]";
                
    $packingListSubject "PACKING LIST: " EMAIL_ORDER_NUMBER_SUBJECT $paramsArray[0] . " " $paramsArray[3]['INTRO_DATE_ORDERED'];

                
    $packingDetails 
                    
    $paramsArray[3]['PRODUCTS_DETAIL'] . "\n\n" 
                    
    $paramsArray[3]['ADDRESS_DELIVERY_DETAIL'] . "\n\n" 
                    
    $paramsArray[3]['SHIPPING_METHOD_DETAIL'] . "\n\n" 
                    
    $paramsArray[3]['ORDER_COMMENTS'] . "\n\n";

                
    $html_msg "";    //$packingDetails;            

                // send packing list email
            
    zen_mail(''$packingListEmailTo$packingListSubject$packingDetailsSTORE_NAMEEMAIL_FROM$html_msg'checkout_extra');

        }
    }
    ?>
    Note: to send an HTML format email needs all the various/relevant HTML email settings switched on within your Zencart admin, so I've just left mine blank in the update method above. When it's blank, zen_mail() just sends a plaintext one.

    You mentioned wanting to get the order number. You can see in the update() function that it is passed an array called $paramsArray[] and in the $packingListSubject line I am getting the order number from $paramsArray[0].

    To see what $paramsArray[] contains, just put: print_r($paramsArray); exit; inside the update method.

    Hope it helps in some way when you get back to this,
    Celtic

    Hi Celtic,

    I have used the same process with SMS ON SALE mod by swguy.

    I have just did one modification and that is instead on zen_mail() call I have replaced by curl API which I have received from my SMS Gateway service provider.

    Whats happening is that SMS is being pushed to the Gateway and is received successfully, Order is generated, Order Confirmation Mail is also generated. But, checkout_success page shows blank page with HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

    I have attached ZIP File containing the code files affected: http://www.zen-cart.com/showthread.p...54#post1140554

    Kindly advice some solution as I am beginner.

    Thanks & Regards,
    Max

 

 

Similar Threads

  1. Replies: 5
    Last Post: 22 Nov 2014, 04:26 AM
  2. Made a mistake some where...
    By cornick in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 6 Feb 2009, 05:48 AM
  3. Where can I put some Google Analytics code?
    By Solarpitch in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 9 Dec 2008, 03:09 PM
  4. I made a custom template but it not working can some one help me
    By touchclothing in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 18 Mar 2007, 10:31 PM

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