Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,690
    Plugin Contributions
    9

    Default using observers...

    v157.

    i am curious about the order class and specifically the number of observers. i see 39 different observers. i'm curious if anyone makes use of this one:

    NOTIFY_ORDER_DURING_CREATE_ADDED_PRODUCT_LINE_ITEM

    if we look at the code in

    includes/classes/order.php

    lines: 871-880

    PHP Code:
                zen_db_perform(TABLE_ORDERS_PRODUCTS$sql_data_array);

                
    $order_products_id $db->insert_ID();

                
    $this->notify('NOTIFY_ORDER_DURING_CREATE_ADDED_PRODUCT_LINE_ITEM',
                    
    array_merge(array('orders_products_id' => $order_products_id'i' => $i), $sql_data_array),
                    
    $order_products_id);

                
    $this->notify('NOTIFY_ORDER_PROCESSING_CREDIT_ACCOUNT_UPDATE_BEGIN');
                
    $order_total_modules->update_credit_account($i);//ICW ADDED FOR CREDIT CLASS SYSTEM

                
    $this->notify('NOTIFY_ORDER_PROCESSING_ATTRIBUTES_BEGIN'); 
    would it not make more sense to have the obsever BEFORE the insert? what is the point of having the $sql_data_array after the insert is already done?

    the notifier is valuable in that one could now, in theory, manipulate data within that row. but would it make more sense to have the observer prior to the insert being done? from a performance standpoint, manipulating the data and then hitting the db seems more efficient to me.

    and while i am sure there is a reason, i suppose it escapes me the need to have 3 different observers almost directly in a row.

    curious about anyone's thoughts on this.

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

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

    Default Re: using observers...

    The "NOTIFY_ORDER_DURING_CREATE_ADDED_PRODUCT_LINE_ITEM" notifier was placed there, and named using "ADDED" to imply past-tense, that the action is finished.
    It supplies details of the record added and the data used to do so.

    You are correct: there's not one to intercept the data before the record is created.
    .

    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
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: using observers...

    Stock by Attributes in support of earlier operations used to specifically observe that notifier. It still does if/when installed to ZC 1.5.1, but now because other specific code is monitored and performs necessary actions, the operation(s) previously performed are actually captured in another observer.

    Looking over the (recent?) history of the notifier, the data that was associated with the added product is provided; however, it wasn't until ZC 1.5.5 that the notifier actually included the database record associated with the previous insertion. Note that with this information there seems to be two sides of the discussion, 1) the notifer is there to alter the information to be stored into the database or to build off of it or as used in SBA, 2) to use the record indicator to be able to populate a separate table that references the original information. This allows using a different database table to manage additional information rather than to alter an existing ZC table.

    As far as a "pre-use" notifier, I would say that there is actually a notifier that can be used just before that database insertion: NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_END can be used to alter any of the `$this->products` data by referencing the variable of the first parameter of the observer (I tend to use &$callingClass) as in $callingClass->products[$passedIVar]['whateverKeyIsNeeded']. Only thing is that if there are other pieces of data to be captured/stored, then they have to be addressed in the later observer because the array that is built does not include some sort of array_merge or other builder for additional array data. So one way to use the notifiers in association with their "names" to incorporate information into the orders_products table without modifying the order.php class would be to possibly use the NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_END notifier to first populate all of the $this->products data necessary, then in observing NOTIFY_ORDER_DURING_CREATE_ADDED_PRODUCT_LINE_ITEM, to use the new insertion record ($order_products_id) to then store the additional information that was not in $sql_data_array or alternatively to store only specific additional information that was previously captured in the $this->products array.

    I do know that some of the way that notifiers are used/what they pass is a result of a request made here: https://www.zen-cart.com/showthread....rder-notifiers as a result of seeing how data was being handled and the operation possibilities based on what had been provided over time. Anyways, if there is something that is modified about the discussed notifier, I believe it is still necessary to at least pass along or provide a method to directly obtain the record(s) generated for relational use across other database records.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v156 Watching Observers: Support Thread
    By lat9 in forum All Other Contributions/Addons
    Replies: 4
    Last Post: 14 Jun 2020, 01:03 PM
  2. Using class observers
    By SpaceMonkey in forum General Questions
    Replies: 1
    Last Post: 29 Jun 2018, 04:30 AM
  3. Using observers to modify original function
    By necroside in forum General Questions
    Replies: 1
    Last Post: 11 Apr 2017, 05:18 AM
  4. Observers and redirects
    By audleman in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 10 Sep 2008, 05:19 PM
  5. Using Observers instantiated from application-top.php?
    By enigmabomb in forum General Questions
    Replies: 7
    Last Post: 24 Jan 2008, 10:29 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