Forums / Code Collaboration / 1.5.7 addition observers Product info - not getting my head arround them

1.5.7 addition observers Product info - not getting my head arround them

Started by brittainmark on 25 Jun 2020, 5:58 PM · Views: 2,970

Results 1 to 8 of 8
25 Jun 2020, 5:58 PM
#1
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
509
Plugin Contributions:
1

1.5.7 addition observers Product info - not getting my head arround them

Moving to 1.5.7. Currently 1.5.6. php 7.3.6 mysql 5.6.43 Quite a few mods.
I had written myself a mod to add the product location to enable me to easily find my products. In 1.5.6 I create a new table and added the products_id and products location to the table. I then change all the collect_info.php and preview_info files.

I now see that you have added new observers to the collect_info files.
I am just having trouble getting my head around how to use it to populate the data and display the data.

I already use an observer for product delete to remove the entry from the products_location table.

It looks like I can use NOTIFY_ADMIN_PRODUCT_COLLECT_INFO_EXTRA_INPUTS to display the info and allow user input.
Any pointers as to where I get the info back to update my table?
Or do i need to mod the products table to add the new field?

Any help welcome.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

25 Jun 2020, 7:31 PM
#2
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,892
Plugin Contributions:
20

Re: 1.5.7 addition observers Product info - not getting my head arround them

Why not just use the built-in search in the admin? Referenced at https://www.zen-cart.com/showthread.php?226879-Reasons-to-update-to-1-5-7&p=1369993#post1369993

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

25 Jun 2020, 8:06 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,128
Plugin Contributions:
56

Re: 1.5.7 addition observers Product info - not getting my head arround them

FWIW, I find no reference to NOTIFY_ADMIN_PRODUCT_COLLECT_INFO_EXTRA_INPUTS within the just-released zc157 fileset.

25 Jun 2020, 10:18 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: 1.5.7 addition observers Product info - not getting my head arround them

lat9:

FWIW, I find no reference to NOTIFY_ADMIN_PRODUCT_COLLECT_INFO_EXTRA_INPUTS within the just-released zc157 fileset.
https://github.com/zencart/zencart/blob/v157/admin/includes/modules/product/collect_info.php#L210
And:
https://github.com/zencart/zencart/blob/v1.5.7/admin/includes/modules/product/collect_info.php#L210

Second one is the released version

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

25 Jun 2020, 10:28 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: 1.5.7 addition observers Product info - not getting my head arround them

brittainmark:

Moving to 1.5.7. Currently 1.5.6. php 7.3.6 mysql 5.6.43 Quite a few mods.
I had written myself a mod to add the product location to enable me to easily find my products. In 1.5.6 I create a new table and added the products_id and products location to the table. I then change all the collect_info.php and preview_info files.

I now see that you have added new observers to the collect_info files.
I am just having trouble getting my head around how to use it to populate the data and display the data.

I already use an observer for product delete to remove the entry from the products_location table.

It looks like I can use NOTIFY_ADMIN_PRODUCT_COLLECT_INFO_EXTRA_INPUTS to display the info and allow user input.
Any pointers as to where I get the info back to update my table?
Or do i need to mod the products table to add the new field?

Any help welcome.
What is meant by "products location"? Is this say a shelf number in the warehouse? A building associated with its storage or availability? A link to the catalog side of the store? A link to the edit and/or price manager for the product?

Unfortunately it's not yet clear what the need is for this additional table.

As to the notifier/observer, by being on the collect_info page, either it can be used to display information that has been made available "above" that line (or originally generated at that line), it can be used to retrieve information from above that line or depending on execution sequence from some other observer of that notification, basically. If you want to capture something that has been newly entered on the product information page, then would need to collect that information later either in the load of the preview of the information, the update of the information or even from that same collect_info page but based on some form of javascript loaded during that page load that captures the desired information and makes it available for such processing and storage...

Kind of depends on what your data source is which leads back to the above question.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

26 Jun 2020, 12:42 AM
#6
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,974
Plugin Contributions:
8

Re: 1.5.7 addition observers Product info - not getting my head arround them

dbltoe:

Why not just use the built-in search in the admin? Referenced at https://www.zen-cart.com/showthread.php?226879-Reasons-to-update-to-1-5-7&p=1369993#post1369993

not really sure how these 2 things are related. the change mentioned in the above link is primarily about product display on the admin side and cleaning up the sorting options. the combined listings of categories and products, at least to me, was always a tad confusing and not implemented in a manner i felt appropriate. the change referenced in the link allows for sorting of search results. 1.5.6 did not allow for sorting of search results as you would get a search result set, and when you attempted to sort it, you lost the search results. in addition, the sorting of the search result set was always based on the category sort, not the product sort.

i had previously implemented this feature for my clients, and frankly it made sense to make it available to the community. apparently the core code maintainers agreed which is why it is now part of the ZC core.

mc12345678:

What is meant by "products location"? Is this say a shelf number in the warehouse? A building associated with its storage or availability? A link to the catalog side of the store? A link to the edit and/or price manager for the product?

Unfortunately it's not yet clear what the need is for this additional table.

As to the notifier/observer, by being on the collect_info page, either it can be used to display information that has been made available "above" that line (or originally generated at that line), it can be used to retrieve information from above that line or depending on execution sequence from some other observer of that notification, basically. If you want to capture something that has been newly entered on the product information page, then would need to collect that information later either in the load of the preview of the information, the update of the information or even from that same collect_info page but based on some form of javascript loaded during that page load that captures the desired information and makes it available for such processing and storage...

Kind of depends on what your data source is which leads back to the above question.

brittainmark, please correct me if i'm wrong, but when you say location, you are referring to a physical product location. none of the other guesses in these posts seem to make sense to me. as those guesses as to what you might mean are readily available and found.

unfortunately inventory management is not really done adequately in ZC. the popularity of the plugin stock by attributes only attests to the need for inventory to be done better (or potentially integrated).

your question is actually a good one. the observer allows one to collect additional information for a particular product. i am guessing that you would need to update your data using another observer. probably here:

https://github.com/zencart/zencart/blob/0ad1b0990f0d13080fa7c9c79a1c51187ae78afc/admin/includes/modules/update_product.php#L124

$zco_notifier->notify('NOTIFY_MODULES_UPDATE_PRODUCT_END', array('action' => $action, 'products_id' => $products_id));

i can only "assume" that the $_POSTS from the collect info observer would be available at that time, but i have not tested it.

as someone who has incorporated numerous extra fields for product types, i would stick with your initial design of a separate table. no need to change that by adding a new field to the product table.

i hope that helps and is not more confusing.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.

26 Jun 2020, 12:20 PM
#7
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,128
Plugin Contributions:
56

Re: 1.5.7 addition observers Product info - not getting my head arround them

You might use the Zen Products (and Tag Cloud) as your model; that's the plugin from which those notifiers were incorporated in the first place!

26 Jun 2020, 3:44 PM
#8
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
509
Plugin Contributions:
1

Re: 1.5.7 addition observers Product info - not getting my head arround them

Thanks for all the interest guys. I think I have finally go my head around it with all the extra notifiers I have manage to rewrite the mod just changing 3 core file.
The way I did it was to just allow a simple text entry to be stored for a product to tell me where it is. I suppose to do I properly I really should have a table of locations and link the location to the product like product to categories. Might look at that later! But for know I have it working using the following notifiers
'NOTIFY_ADMIN_PRODUCT_COLLECT_INFO_EXTRA_INPUTS',
'NOTIFIER_ADMIN_ZEN_REMOVE_PRODUCT',
'NOTIFY_PRODUCT_MUSIC_UPDATE_PRODUCT_END',
'NOTIFY_PRODUCT_MUSIC_COPY_TO_CONFIRM_DUPLICATE',
'NOTIFY_MODULES_COPY_TO_CONFIRM_DUPLICATE',
'NOTIFY_MODULES_UPDATE_PRODUCT_END'

A couple of trip ups were the fact that product info is now an object so needed to use $p1->products_id and not $p1['products_id'] this is only in the collect_info modules.
The second was realising that the $extra_product_inputs needs to be an array of arrays so

 $p2 = array('products_location'=>array(
                       'label'=> array(
                         'text' => TEXT_PRODUCTS_LOCATION,
                         'field_name' =>'products_location'),
                       'input' => $input));

I also gave mine a name just in case I find anyone else using it.
Finally I have even sanitised the input which I must say was surprisingly easy (so good job who ever wrote that!)

$sanitizer = AdminRequestSanitizer::getInstance();
$group = array(
    'products_location' => array('sanitizerType' => 'ALPHANUM_DASH_UNDERSCORE', 'method' => 'post'),
);
$sanitizer->addComplexSanitization($group);

Thanks Again for all the interest. Might even post it as a mod later.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\