Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / metatags overide using the notifier, to add extra fields from bookx

metatags overide using the notifier, to add extra fields from bookx

Views: 755

Results 1 to 5 of 5
20 Sep 2016, 2:16 PM
#1
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

metatags overide using the notifier, to add extra fields from bookx

Hi
I'm making some customization on the metatags to incorporate some extra fields related to other module ( bookx )

I can do this by altering the meta_tags.php ( overinding, etc ), but I was trying to use the notifiers to do it, so I woundt'n need to mess with that file.

I'm using this notifier

$zco_notifier->notify('NOTIFY_MODULE_META_TAGS_OVERRIDE', $metatag_page_name, $meta_tags_over_ride, $metatags_title, $metatags_description, $metatags_keywords);

And this is a example how I'm calling it (?) (I've learn this way)

function __construct() {

        global $zco_notifier;
        $notifyme = array();

        $notifyme[] = 'NOTIFY_MODULE_META_TAGS_OVERRIDE';

        $this->attach($this, $notifyme);
    }  

function update(&$callingClass, $notifier, $paramsArray) {
        if ( $notifier == 'NOTIFY_MODULE_META_TAGS_OVERRIDE' ) {
            $this->tpl_pb_insertMetaTagsFilters($callingClass, $notifier, $paramsArray);
        }

ok, I've pretty much done all I had to do related to other pages of this modules ( authors, publishers, etc... ) . But to add some more stuff in the products page metatags ( in this case, book fields such as ISBN, etc ), I'm having difficulty, and not sure if this is possible, just using a notifier.

So I can access the $product_info_metatags, etc, I just can't seen to add stuff to those variables ( title, description, keywords).

Example ( to add a book subtitle to the meta_products_name :

function tpl_pb_insertMetaTagsFilters(&$callingClass, $notifier, $paramsArray) {

global $db, $current_page, $og_type, $og_image, $og_title, $og_author_books, $flag_page, $metatags_title, $meta_tags_over_ride, $metatag_page_name, $metatags_keywords, $metatags_description;
global $product_info_metatags, $meta_products_name  ,$meta_products_price, $meta_products_description;

switch ( $metatag_page_name ) {

 case 'index': 

            // etc, etc, working ok for other pages! 
 break; 

// FOR THE PRODUCT PAGE 

 case (strstr($_GET['main_page'], 'product_') or strstr($_GET['main_page'], 'document_')):

    if ( (isset($_GET['products_id']) && $current_page == 'product_bookx_info' ) ) {
           
       if ( !empty($product_info_metatags->fields['metatags_keywords']) or ! empty($product_info_metatags->fields['metatags_description']) ) {
                    
                    $meta_products_name = zen_clean_html($meta_products_name . $metatag_subtitle);
                    
                } else {

                    if ( $metatag_subtitle != '' ) {

                        $meta_products_name = zen_clean_html($meta_products_name . $metatag_subtitle);
                    }
                }

                 define('META_TAG_TITLE', str_replace('"','',$review_on . $meta_products_name . $meta_products_price . PRIMARY_SECTION . TITLE . TAGLINE));
         
      }
}

.... but it's not working....
All I can do for the products page, is to use the other NOTIFY_MODULE_START_META_TAGS, and change the file meta_tags.php directly

Thanks

20 Sep 2016, 3:59 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: metatags overide using the notifier, to add extra fields from bookx

The scheme of the above is not taking into account all of the other variables that are passed by the notifier.

Assuming that you wish to keep with the function update instead of updateNotifyModuleMetaTagsOverride (which is supported on ZC 1.5.3 and above, then your update function should have the additional parameters added to it to receive all of the provided variables (again only available in ZC 1.5.3 and above).

Therefore:

function update(&$callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords) {

        if ( $notifier == 'NOTIFY_MODULE_META_TAGS_OVERRIDE' ) {
            $this->tpl_pb_insertMetaTagsFilters($callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords);
        }
}

But, then perhaps the issue really is or also is in the function that is called from there.. For example the use of: $metatag_subtitle... There is no "sharing" of that information, nor do I see where it is populated, so perhaps it is something within the function and it is not executed...

Further, there is an attempt to redefine the META_TAG_TITLE constant that would have already been assigned within the applicable case statement. Effectively, the only way to be able to define that constant as part of an outside observer is to listen to:

$zco_notifier->notify('NOTIFY_MODULE_START_META_TAGS', $current_page_base, $metatag_page_name, $meta_tags_over_ride);

and

$zco_notifier->notify('NOTIFY_MODULE_META_TAGS_BUILDKEYWORDS', CUSTOM_KEYWORDS, $keywords_string_metatags);

Otherwise, basically if there are any meta-tags already assigned for the applicable "group" then the constants META_TAG_TITLE, META_TAG_DESCRIPTION, and META_TAG_KEYWORDS would already be defined for that case statement...

There's a lot going on in the file, and I've provided cursory review/comment. Need to be sure that you are still able to assign/define the item(s) you want depending on the data available and assignments already made. Once a constant is defined, it can not be redefined, therefore if you want to "read" a certain way then it should be assigned before the other code has an opportunity to do so which may involve use of other notifiers.

20 Sep 2016, 4:37 PM
#3
lat9 avatar

lat9

Administrator

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

Re: metatags overide using the notifier, to add extra fields from bookx

Just a minor coding point. Starting with PHP 5.3, a function must be *declared *to receive its arguments as pass-by-reference; that said, the highlighted code fragment is no longer legal:

function update(&$callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords) {

        if ( $notifier == 'NOTIFY_MODULE_META_TAGS_OVERRIDE' ) {
            $this->tpl_pb_insertMetaTagsFilters($callingClass, $notifier, $paramsArray, [B]&$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords[/B]);
        }
}

You'll need to revise that to the following, changing the handler's function declaration and removing the reference operator (&) from the four parameters supplied when the function is called:

function update(&$callingClass, $notifier, $paramsArray, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords) {

        if ( $notifier == 'NOTIFY_MODULE_META_TAGS_OVERRIDE' ) {
            $this->tpl_pb_insertMetaTagsFilters($callingClass, $notifier, $paramsArray, $meta_tags_over_ride, $metatags_title, $metatags_description, $metatags_keywords);
        }
}
.
.
function tpl_pb_insertMetaTagsFilters(&$callingClass, $notifier, $paramsArray[B],  &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords[/B]) { 

See this definition for additional information: http://php.net/manual/en/language.references.pass.php

20 Sep 2016, 4:39 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: metatags overide using the notifier, to add extra fields from bookx

Yup and at some point since the near dawn of computers, a dangerous feature of copy and paste has existed...

22 Sep 2016, 11:24 AM
#5
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: metatags overide using the notifier, to add extra fields from bookx

Hi
Thanks for the reply. I've try to follow some of your tips , but achieve nothing. I'm simply not at that level.

I was using a observer to do a lot of stuff, so the update function with all those variables confuses me .... because I dont' know that much.

Using the NOTIFY_MODULE_START_META_TAGS I can define stuff, but then I need the data from the query $product_info_metatags ( and I can only access it using NOTIFY_MODULE_META_TAGS_OVERRIDE

I even try to call or pull one into the other, so I could use the info again.... but that's redundant, doens't make much sense, and I failed.

So I guess I'll stick to what I was doing, that was the use of NOTIFY_MODULE_START_META_TAGS and then add that extra info to the variables present in meta_tags.php file.

Thanks for the reply's