Page 1 of 6 123 ... LastLast
Results 1 to 10 of 57
  1. #1
    Join Date
    Oct 2020
    Location
    Florida
    Posts
    35
    Plugin Contributions
    0

    Default Adding special function when order is placed

    Hello, I would like to make it so when an order is placed from a specific product it does something Zencart cant.

    What file/file folder should I put this file in so when a product is purchased it runs this file?

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Adding special function when order is placed

    Can you be more specific about what you're actually doing? What's needing to run and why?

    Also, "when" should this program run? While the order details are being prepared so that some output can be included in the order? or after the emails are sent? or after the customer clicks a button on the checkout_success page? etc
    Does it need to run instantly? Or can it be queued to run periodically such as checking every 5 minutes to see if it needs to be run.
    Does it require any inputs from the order information? Which details does it require?

    And, is it possible that this program might generate errors? If so, how should those be handled?
    .

    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. #3
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Adding special function when order is placed

    I guess this is a duplicate of your other post? Need to send emails to supplier per product sale
    .

    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.

  4. #4
    Join Date
    Oct 2020
    Location
    Florida
    Posts
    35
    Plugin Contributions
    0

    Default Re: Adding special function when order is placed

    I'm looking to do this when the order is placed at about the same time the order.php file is run. But I have no idea where to put my own code so that it 1. does not conflict with the existing code 2. but also will execute everything I need it too.

    So yes kinda like my last post but I would just like to know where to put my code without messing with core files.

  5. #5
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Adding special function when order is placed

    It's not like you can just place a file somewhere and that's it... IMHO, the best way to do this would be to create an observer on NOTIFY_HEADER_END_CHECKOUT_PROCESS and then have it go through the list of purchased products, and if the product is found in that order, trigger your function to run whatever you're running.
    There are other possible approaches, but I believe this would be best and least obtrusive, and doesn't require modifying any core or template files.

    Another method that comes to mind is to create a new file in extra_functions/ directory, start it with something like
    Code:
    <?php
    function doSomethingZenCartCant {
        global $current_page_base;
        if($current_page_base == 'checkout_success')
        {
            // your code here
        }
    }
    and then figure out how to go through the list of purchased products and trigger your code if required product found. But I'd still go with the observer, it's actually simpler...

  6. #6
    Join Date
    Oct 2020
    Location
    Florida
    Posts
    35
    Plugin Contributions
    0

    Default Re: Adding special function when order is placed

    I will look into trying to create an observer for what I need to do, that might be the best option for what I am doing. Thank you!

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Adding special function when order is placed

    Without knowing more about your product setup or what you're aiming to do for each, here's a possible basic structure for an Observer class:

    PHP Code:
    <?php
    class send_supplier_emails_after_order_observer extends base
    {
        protected 
    $order_id;


        public function 
    __construct()
        {
            
    $this->attach($this, array(
                
    'NOTIFY_HEADER_END_CHECKOUT_PROCESS',
                
    // 'NOTIFY_CHECKOUT_PROCESS_BEFORE_CART_RESET',
            
    ));
        }


        
    // NOTIFY_HEADER_END_CHECKOUT_PROCESS
        
    public function updateNotifyHeaderEndCheckoutProcess(&$class$eventID$order_id)
        {
            
    // prior to v1.5.8 the order number must be retrieved this way:
            
    if (empty($order_id)) {
                global 
    $insert_id;
                if (!empty(
    $insert_id)) {
                    
    $order_id $insert_id;
                }
            }


            
    // abort if no order number
            
    if (empty($order_id)) return;


            
    $this->order_id $order_id;


            
    $order = new Order($this->order_id);


            
    $this->processProducts($order->products);
        }


        
    // NOTIFY_ORDER_DURING_CREATE_ADD_PRODUCTS
        
    public function updateNotifyCheckoutProcessBeforeCartReset(&$class$eventID$order_id)
        {
            
    // abort if no order number
            
    if (empty($order_id)) return;


            
    $this->order_id $order_id;


            
    $order = new Order($this->order_id);


            
    $this->processProducts($order->products);
        }


        
    /**
         * @param  array $products all products in the order
         * The indices of each product come from https://github.com/zencart/zencart/blob/7c324c2dfabd35b53eb543fae46efabf26a6a929/includes/classes/order.php#L181-L201
         * and the sub-indices of each products' [attributes] array come from https://github.com/zencart/zencart/blob/7c324c2dfabd35b53eb543fae46efabf26a6a929/includes/classes/order.php#L217-L223
         *
         */
        
    protected function processProducts($products)
        {
            foreach (
    $products as $product) {


                
    // take action based on product ID:
                
    switch ($product['id']) {
                    case 
    '333':
                        
    // do something related to product #333
                        
    break;
                    case 
    '444':
                        
    // do something related to product #444
                        
    break;
                }
            }
        }
    }
    .

    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.

  8. #8
    Join Date
    Oct 2020
    Location
    Florida
    Posts
    35
    Plugin Contributions
    0

    Default Re: Adding special function when order is placed

    This should work for what I need to do. I should be able to do what I need to from here thanks for the help!

  9. #9
    Join Date
    Oct 2020
    Location
    Florida
    Posts
    35
    Plugin Contributions
    0

    Default Re: Adding special function when order is placed

    Turns out I am still a bit confused.. Here is a function I want to run a copy of the admin email in this file, how can I achieve this because when the email fires it only gives the info defined in the file.

    PHP Code:
    public function emailOrder($zf_insert_id null)
        {
            if (
    $zf_insert_id === null$zf_insert_id $this->orderId;

            
    $extra_info email_collect_extra_info(''''$this->customer['firstname'] . ' ' $this->customer['lastname'], $this->customer['email_address'], $this->customer['telephone']);
            
    $html_msg['EXTRA_INFO'] = $extra_info['HTML'];

            
    // Add extra heading stuff via observer class
            
    $this->extra_header_text '';
            
    $this->notify('NOTIFY_ORDER_INVOICE_CONTENT_FOR_ADDITIONAL_EMAILS'$zf_insert_id$email_order$html_msg);
            
    $email_order $this->extra_header_text $email_order;
            
    $html_msg['EMAIL_TEXT_HEADER'] = nl2br($this->extra_header_text) . $html_msg['EMAIL_TEXT_HEADER'];

            
    zen_mail(
                
    '',
                
    'the email',
                
    SEND_EXTRA_NEW_ORDERS_EMAILS_TO_SUBJECT ' ' EMAIL_TEXT_SUBJECT EMAIL_ORDER_NUMBER_SUBJECT $zf_insert_id,
                
    $email_order $extra_info['TEXT'],
                
    STORE_NAME,
                
    EMAIL_FROM,
                
    $html_msg,
                
    'checkout_extra',
                
    $this->attachArray,
                
    $this->customer['firstname'] . ' ' $this->customer['lastname'],
                
    $this->customer['email_address']
            );
        } 
    So how can I pull the parameters set in the order.php file in this file so when the email is sent it has the correct info? As you may notice I did remove some of the things I don't want to be sent in this copy of the admin email.
    Last edited by Famine_1; 8 Jan 2021 at 06:17 PM.

  10. #10
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Adding special function when order is placed

    Using my code sample as a base, the $order variable built in both of those updateXYZ functions has access to all the data inside the order (comes from the order.php class).
    Inside those functions you can refer to that data via "$order->foo" the same as the order class would refer to "$this->foo"
    .

    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.

 

 
Page 1 of 6 123 ... LastLast

Similar Threads

  1. send me an email when order is placed
    By Funkhouserjm in forum General Questions
    Replies: 1
    Last Post: 29 Jun 2010, 11:54 PM
  2. sideboxes round when placed on right but not when placed on left!
    By hungrytazman in forum Basic Configuration
    Replies: 4
    Last Post: 11 Mar 2010, 09:11 PM
  3. Change 'To:" email when order is placed.
    By joefox in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 9 Apr 2009, 09:00 PM
  4. Order History Not appearing When an Order Is Placed
    By VNLLC in forum General Questions
    Replies: 9
    Last Post: 20 Mar 2009, 09:38 PM
  5. Auto print when order is placed??
    By jbourque in forum General Questions
    Replies: 4
    Last Post: 18 Jul 2008, 06:53 PM

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