Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2014
    Location
    Amsterdam, Netherlands
    Posts
    9
    Plugin Contributions
    1

    help question order emails, How does it work?

    Hi,

    Been working on some changes in the way zen cart handles the order and notifies the customer.
    I'm fine with coding and most ZC stuff. (Working with ZC for several years now, mostly code-stuff)

    I'm looking for a way to:
    - Still get the order in the database upon leaving ZC to a payment page.
    - NOT send the order confirmation. I'll call this function later on.

    I'm aware of the classes/order.php (which has the functions) and the modules/checkout_process.php (which calls the functions???).
    A module I have already does the behaviour described above, but I can't find how it does that.

    So, if anyone has any suggestions, or maybe some detailed (dev)docs about the order&payment-system(really confused about the exact flow of this), it would make me very happy. Just need to know where I need to add an if-statement.. ;)

    Thnx!

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

    Default Re: Zen Cart order emails, How does it work?

    The Zen Cart order-confirmation email is sent via the store-side order class' send_order_email function.

    You can modify your store to not send the email during checkout by editing your template's override of /includes/modules/checkout_process.php (the copy of that file that is present in /includes/modules/YOUR_TEMPLATE/checkout_process.php) and commenting-out the call to send_order_email:
    Code:
    // load the before_process function from the payment modules
    $payment_modules->before_process();
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_BEFOREPROCESS');
    // create the order record
    $insert_id = $order->create($order_totals, 2);
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE');
    $payment_modules->after_order_create($insert_id);
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE');
    // store the product info to the order
    $order->create_add_products($insert_id);
    $_SESSION['order_number_created'] = $insert_id;
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS');
    //send email notifications
    //-Uncomment the following line to enable the checkout-confirmation email to be sent
    // $order->send_order_email($insert_id, 2);
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL');

  3. #3
    Join Date
    Feb 2014
    Location
    Amsterdam, Netherlands
    Posts
    9
    Plugin Contributions
    1

    Default Re: Zen Cart order emails, How does it work?

    Your solution sounds template specific, not module specific. In this case my "vanilla" payment methods will probably break (CoD/Freeshipper/moneyorder etc.)

    Is this file being called upon leaving the store to a payment gateway, or upon return from the payment gateway?
    My guess it's upon leaving to a gateway, not sure..

    I now see this function "$payment_modules->before_process();", I'll dive into that.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Zen Cart order emails, How does it work?

    Quote Originally Posted by vandijkstef View Post
    Your solution sounds template specific, not module specific. In this case my "vanilla" payment methods will probably break (CoD/Freeshipper/moneyorder etc.)

    Is this file being called upon leaving the store to a payment gateway, or upon return from the payment gateway?
    My guess it's upon leaving to a gateway, not sure..

    I now see this function "$payment_modules->before_process();", I'll dive into that.
    Umm, not sure what you mean by module specific when the solution provided is to modify a module that is (happens to be) template overrideable...

    If referring to making that change only for a specific payment module, then that was not initially expressed and therefore a suggestion/solution was not provided to address the one specific payment module that is in question. If that is the case/desired then the edit provided by lat9 could be modified to account for which payment module is being used/processing the payment and therefore could provide the email action in the above code for all payment modules except the one that needs to be handled separately.

    As for when the file is being processed, it is somewhat of a yes to your question of before or after the payment module has processed it... Perhaps your solution does lie within the before_process code for the applicable payment processor such that it has the appropriate checks to allow completion of the process outlined in the module (without edit) or perhaps the need for observers to integrate with the notifiers that have been provided... There are other notifiers (includes/classes/order.php) that can be used to modify the email being sent or not, and then later the email could be sent if the modifications in the before_process function above are not sufficient to provide the end goal.

    Again though, the posted request was:
    I'm looking for a way to:
    - Still get the order in the database upon leaving ZC to a payment page.
    - NOT send the order confirmation. I'll call this function later on.
    And the solution provided did that...

    To identify the payment module, could modify lat9's suggestion to something like the following:

    Code:
    // load the before_process function from the payment modules
    $payment_modules->before_process();
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_BEFOREPROCESS');
    // create the order record
    $insert_id = $order->create($order_totals, 2);
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE');
    $payment_modules->after_order_create($insert_id);
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_PAYMENT_MODULES_AFTER_ORDER_CREATE');
    // store the product info to the order
    $order->create_add_products($insert_id);
    $_SESSION['order_number_created'] = $insert_id;
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_ORDER_CREATE_ADD_PRODUCTS');
    //send email notifications
    if ($GLOBALS[$payment_modules->selected_module]->code != 'specialpaymentmodule') {
      $order->send_order_email($insert_id, 2);
    }
    $zco_notifier->notify('NOTIFY_CHECKOUT_PROCESS_AFTER_SEND_ORDER_EMAIL');
    Where $payment_modules->selected_module identifies the payment module... The above would perform the send_order_email action if the payment module of choice for the order is anything but specialpaymentmodule...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: order emails, How does it work?

    Quote Originally Posted by vandijkstef View Post
    I'm looking for a way to:
    - Still get the order in the database upon leaving ZC to a payment page.
    - NOT send the order confirmation. I'll call this function later on.
    The v1.5.x (and earlier versions) architecture of Zen Cart's checkout flow doesn't store the order in the db until after the payment module completes its steps.
    The normal flow is that the payment module runs its before_process() method to take the data from the payment page and submit it in real-time to the payment gateway (or receive the response from the offsite gateway after completing payment and returning to the site). Then optionally runs an after_process() method if present (often just to update internal logs, if anything at all).
    Then it writes the order to the database. The premise here is that only the orders that have been accepted by the payment process (ie: usually this means "payment received" or at least payment is pending because of a valid credit card authorization or the customer has agreed to send a check in the mail) actually make it into the database.
    Then it sends the email.
    Then it shows the checkout-success page to the customer.

    The money_order.php module is an example of allowing pending-payment orders to get saved.

    As for skipping the email confirmation, there's nothing in that part of the code to detect which payment method was used in order to take alternate action.
    As much as I hate using $GLOBALS, you could add a line to the beginning of the send_order_email() method of the order class to check something like
    Code:
    if ($GLOBALS[$_SESSION['payment']]->code == 'my_module_code_string') return;
    That would check the comparison against this line in your payment module:
    Code:
    $this->code = 'my_module_code_string';
    .

    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. #6
    Join Date
    Feb 2014
    Location
    Amsterdam, Netherlands
    Posts
    9
    Plugin Contributions
    1

    Default Re: order emails, How does it work?

    Now you mention, indeed my questions wasn't clear enough. Heat of the moment I suppose..

    This payment flow was really an unidentified part of ZC for me, thanks all for clearing this up! Really feel I'll get to a good solution with these answers

    To keep information (kinda) complete:
    I'm now working on a solution that involves some checking-code within the before_process(); (Which resides within the payment module). That code sets some flags to decide the rest of the processing. (My current module apparently immediatly accepts, if there are no errors, and then goes to it's gateway, emails already sent. It's not the best payment module around..)

 

 

Similar Threads

  1. v154 order emails work, contact us email form not working...
    By twitchtoo in forum General Questions
    Replies: 0
    Last Post: 30 Mar 2015, 09:39 PM
  2. v150 Custom Sort Order does not work
    By DeepGirl in forum Setting Up Categories, Products, Attributes
    Replies: 8
    Last Post: 6 Jun 2014, 04:22 PM
  3. Does PDF Order Center work with ZC1.3.5?
    By davale in forum All Other Contributions/Addons
    Replies: 6
    Last Post: 4 Sep 2008, 03:37 AM
  4. Expected Sort order does not work
    By PeterBKK in forum General Questions
    Replies: 9
    Last Post: 25 Apr 2008, 10:46 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