Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2023
    Location
    UK
    Posts
    13
    Plugin Contributions
    0

    Default I need help to customize classes/order.php!

    Hi

    Using a basic 1.5.8a installation and PHP8.2 I am trying to get some extra information to be displayed on the ZC invoice.

    Reading through the odd old thread I see that the info needs to be placed, at the time of the order, to the orders/orders_products table.

    I need to get data from the CUSTOMERS table (named customers_qfcode) and from the PRODUCTS table (named products_qfcode).

    I have created a field in ORDERS for the customers_qfcode and a field in ORDERS_PRODUCTS for the product_qfcode.

    So far, so good.

    What I cannot get to work is includes/classes/order.php to populate the ORDERS / ORDERS_PRODUCTS fields when an order is placed.

    Can anyone point me in the right direction please?

    I have tried replicating what's in the $sql_data_array = (around line 897) but just get blank pages.

    Would appreciate any help.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,739
    Plugin Contributions
    17

    Default Re: I need help to customize classes/order.php!

    Best thing is likely to use an observer that will do the work you desire when the proper notifier(s) are triggered. One plugin that uses a similar set of notifiers is stock by attributes, though I think most of the heavy work is done earlier on. During the order process though, it does spite some data in various tables and fields in association with supporting the order. I also suspect that there are other plugins that really only record data similar to what you want to do.

    The "tricky part" is ensuring the observer loads before the class so that the observer action can occur.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,699
    Plugin Contributions
    9

    Default Re: I need help to customize classes/order.php!

    i would like to add my 2cents here. take it for what it is worth...

    mc is correct, using an observer is the way to go.

    you are incorrect; you do NOT need to add the data to the orders table or the orders_products table.

    i would suggest using an auto loaded observer. you can read about it here:

    https://docs.zen-cart.com/dev/code/n...aded-observers

    when you are constructing an invoice, the order class will be queried. so you need to add some elements to the order object when queried, and then use those elements when constructing an invoice.

    for example, if we were to look here:

    https://github.com/zencart/zencart/b...order.php#L367

    here is a notifier that you want to attach to. at this point, you will have a product_id and from within your observer you can then get the products_qfcode and make it part of your order object.

    you can then use the same observer to attach to the notifier here:

    https://github.com/zencart/zencart/b...order.php#L375

    at this point, the class should already have the customer_id and you can then retrieve the customers_qfcode and again make it part of your order object.

    then depending on where you want to display those elements on your invoice, they will be available for use. the invoice makes use of the order object as seen here:

    https://github.com/zencart/zencart/b...nvoice.php#L25

    and when using the order object it will query the order if an order number is provided as seen here:

    https://github.com/zencart/zencart/b....php#L151-L152

    while adding the elements to the 2 aforementioned table could be done, i think it will be a lot more work and rather unnecessary. unless of course these codes change over time, and you want to know what the codes were at the time of the order. that would require something completely different; and would necessitate storing those elements in the tables.

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  4. #4
    Join Date
    Jun 2023
    Location
    UK
    Posts
    13
    Plugin Contributions
    0

    Default Re: I need help to customize classes/order.php!

    Hi Carlwhat

    Both your response and MCs advises the use of an Observer. So sounds the way to go, but how?

    I understand the basics but I am not a seasoned coder. Could I ask you please to advise a bit more detail? Assume I know nothing (which would be about right).

    Thanks


    Quote Originally Posted by carlwhat View Post
    i would like to add my 2cents here. take it for what it is worth...

    mc is correct, using an observer is the way to go.

    you are incorrect; you do NOT need to add the data to the orders table or the orders_products table.

    i would suggest using an auto loaded observer. you can read about it here:

    https://docs.zen-cart.com/dev/code/n...aded-observers

    when you are constructing an invoice, the order class will be queried. so you need to add some elements to the order object when queried, and then use those elements when constructing an invoice.

    for example, if we were to look here:

    https://github.com/zencart/zencart/b...order.php#L367

    here is a notifier that you want to attach to. at this point, you will have a product_id and from within your observer you can then get the products_qfcode and make it part of your order object.
    Okay, I see the Notify bit but how do I attach to it? What do I need to do to attach to it?

    you can then use the same observer to attach to the notifier here:

    https://github.com/zencart/zencart/b...order.php#L375

    at this point, the class should already have the customer_id and you can then retrieve the customers_qfcode and again make it part of your order object. Same point as above.

    then depending on where you want to display those elements on your invoice, they will be available for use. the invoice makes use of the order object as seen here:

    https://github.com/zencart/zencart/b...nvoice.php#L25

    and when using the order object it will query the order if an order number is provided as seen here:

    https://github.com/zencart/zencart/b....php#L151-L152

    while adding the elements to the 2 aforementioned table could be done, i think it will be a lot more work and rather unnecessary. unless of course these codes change over time, and you want to know what the codes were at the time of the order. that would require something completely different; and would necessitate storing those elements in the tables.Whilst there is some merit in having an audit trail - it isn't necessary if the Observer method is easier to achieve.

    best.

  5. #5
    Join Date
    Jul 2012
    Posts
    16,739
    Plugin Contributions
    17

    Default Re: I need help to customize classes/order.php!

    Quote Originally Posted by DaxtheMan View Post
    Hi Carlwhat

    Both your response and MCs advises the use of an Observer. So sounds the way to go, but how?

    I understand the basics but I am not a seasoned coder. Could I ask you please to advise a bit more detail? Assume I know nothing (which would be about right).

    Thanks
    It would be a little helpful to understand the extent of "knowing nothing". Are there basics to assume understood? Know how to use a text editor? Know how to ftp to your site? Know how to create a file? Do you have a test site where you can work this development and not cause a problem with your live site?

    As to the tasking desired, I'll say I wasn't fully clear about what data you already have, what data you still need and where data is to be used. There was discussion about needing something on an invoice but then that all this order data has already been collected. At the same time, the arrangement explained appeared like this additional order related data was what would be collected or accumulated if and when an order was placed. A reason I had that thought was because it takes effort to assemble the data associated with the order being placed and if that level of work was available then it seems like transitioning over to the invoice would be easier than developing anew.

    Point is, please try to be as clear as possible about known conditions and unknown conditions of simply seeking specific coding assistance from the forum. Yeah you might get an offer for someone to just do it for you, but that too is a piece of helpful information.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Jun 2023
    Location
    UK
    Posts
    13
    Plugin Contributions
    0

    Default Re: I need help to customize classes/order.php!

    Hi MC

    Appreciate the response.

    I know not a lot about PHP8.2 coding. I can cut and paste and follow examples and can use Notepad++ to edit stuff. I have got the new database fields to be populated via admin by copying the code for other entries and applying the QFcode naming. And yes I have the ZC working on my local machine so no live site involved atm. I would say I am an average ZC user.

    My original thinking was based on this thread from way back https://www.zen-cart.com/showthread....ers-emails-ect wherein DrByte suggested a solution to bringing in data to be used in an invoice.

    Having tried that (obviously substituting products_qfcode for products_description) nothing gets added to the database (Orders_Products) but the log complains of an undefined array key. Maybe I keep making an error, maybe the code requirements have changed.

    I then wondered if the method, dating from 2006 was obsolete. I then approached the forum to see if someone with more experience could point me in the right direction. And you did.

    Where I am a blank sheet is in creating an Observer from scratch to do this stuff. I was hoping for some guidance from those familiar, or who had done so for another project, so I could get ahead.

    I just don't understand the solution but I'll persevere and hopefully will get there.

    Thank you for taking the time to have a look.



    Quote Originally Posted by mc12345678 View Post
    It would be a little helpful to understand the extent of "knowing nothing". Are there basics to assume understood? Know how to use a text editor? Know how to ftp to your site? Know how to create a file? Do you have a test site where you can work this development and not cause a problem with your live site?

    As to the tasking desired, I'll say I wasn't fully clear about what data you already have, what data you still need and where data is to be used. There was discussion about needing something on an invoice but then that all this order data has already been collected. At the same time, the arrangement explained appeared like this additional order related data was what would be collected or accumulated if and when an order was placed. A reason I had that thought was because it takes effort to assemble the data associated with the order being placed and if that level of work was available then it seems like transitioning over to the invoice would be easier than developing anew.

    Point is, please try to be as clear as possible about known conditions and unknown conditions of simply seeking specific coding assistance from the forum. Yeah you might get an offer for someone to just do it for you, but that too is a piece of helpful information.

  7. #7
    Join Date
    Jul 2012
    Posts
    16,739
    Plugin Contributions
    17

    Default Re: I need help to customize classes/order.php!

    Quote Originally Posted by DaxtheMan View Post
    Hi MC

    Appreciate the response.

    I know not a lot about PHP8.2 coding. I can cut and paste and follow examples and can use Notepad++ to edit stuff. I have got the new database fields to be populated via admin by copying the code for other entries and applying the QFcode naming. And yes I have the ZC working on my local machine so no live site involved atm. I would say I am an average ZC user.

    My original thinking was based on this thread from way back https://www.zen-cart.com/showthread....ers-emails-ect wherein DrByte suggested a solution to bringing in data to be used in an invoice.

    Having tried that (obviously substituting products_qfcode for products_description) nothing gets added to the database (Orders_Products) but the log complains of an undefined array key. Maybe I keep making an error, maybe the code requirements have changed.

    I then wondered if the method, dating from 2006 was obsolete. I then approached the forum to see if someone with more experience could point me in the right direction. And you did.

    Where I am a blank sheet is in creating an Observer from scratch to do this stuff. I was hoping for some guidance from those familiar, or who had done so for another project, so I could get ahead.

    I just don't understand the solution but I'll persevere and hopefully will get there.

    Thank you for taking the time to have a look.
    Between the posts here and the the referenced thread, there is a lot of good information. For you and anyone trying to accomplish something similar.

    The content of such logs are beyond helpful, they advise of the location where the problem occurred and then add stated some meaningful content/description of the issue.

    You've indicated as part of this thread that you using Zen Cart 1.5.8. There are already examples of the structure of an auto loading observer. This can be highly beneficial as you go forward.

    As to the missing key statement, well some of the biggest changes in PHP relate to coding with purpose and knowing the data structure so that issues and errors can be better prevented. Not sure which key was reported missing, though did see in some of the proposed code where a possible issue might now be reported that wouldn't have previously.

    The simplest of the example code that also uses about the maximum different considerations for an observer class can be found at: includes/classes/observers/auto.non_captcha_observer.php

    In the construct method (called when the class is instantiated), there are multiple notifiers being tracked. There is though only one class method that is specifically called directly by the notifier: updateNotifyContactUsCaptchaCheck

    The format of that method name is from the older style of method naming for observers but it remains available for use.

    Anyways, I would like to think that may be able to piece together which notifiers need to be observed so that can then do the operations necessary along the way. Several have been suggested at least for the invoice portion, but sounds like may still need to collect data at the order purchase part.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v155 Class 'ot_coupon' not found in includes/classes/order.php
    By delia in forum Upgrading to 1.5.x
    Replies: 9
    Last Post: 9 Jan 2019, 07:29 PM
  2. v155 Undefined index: shipping in classes/order.php
    By torvista in forum Bug Reports
    Replies: 3
    Last Post: 11 Sep 2017, 04:09 PM
  3. Replies: 1
    Last Post: 28 Jul 2011, 07:43 PM
  4. Version help with admin/includes/classes/order.php
    By Brent in forum General Questions
    Replies: 2
    Last Post: 4 Jan 2011, 03:25 PM
  5. PhP question about a line of code in includes/classes/order.php
    By dbrewster in forum Managing Customers and Orders
    Replies: 12
    Last Post: 1 Feb 2007, 03:30 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