Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Apr 2008
    Posts
    150
    Plugin Contributions
    0

    Default Displaying new music product field and data on product pages

    I've successfully added a new field (format) to my Product - Music product type. The new field displays on my product creation pages and is listed in my Admin>Extras drop-down menu. I can edit the list of values for media formats there (LP, CD, DVD, etc.).

    The problem I'm having now is getting the information to display on the storefront's product pages. I've edited the tpl_product_music_info_display.php file to match the same way it handles the artist field (which displays on the product pages in the productDetailsList). I've looked at other files handling the artist field to make sure the format field is always handled the same way. But no matter where I look or modify, I can't produce the field output on the product page.

    I've looked in my templates and everywhere else that handles music product files (and forum threads that deal with general products doing the same). But can't even find something that alters the existing displayed fields (Model number and Artist) to indicate I'm on the right track. What very fundamental step am I missing to get the information displayed on the store's product pages? Thank you.

  2. #2
    Join Date
    Apr 2008
    Posts
    150
    Plugin Contributions
    0

    Default Re: Displaying new music product field and data on product pages

    Okay, apparently this is activated under Admin>Catalog>Product Types (click on product type selection) in the Product Type Info Page Layout options :: Product - Music

    I can see the Artist, Genre, and Record Company... but not for the new Format field.

    Does this have to be registered in Admin>Admins>Admin Page Registration?

  3. #3
    Join Date
    Jul 2012
    Posts
    16,799
    Plugin Contributions
    17

    Default Re: Displaying new music product field and data on product pages

    Take a look in the folder includes/modules/pages/product_music.

    You should see at least two files, header_php.php and main_template_vars.php (I think is the name). This second file generally produces the variables that you are seeking.

    Keeping your modifications independent of existing "core" files, there are two ways that generally are used to get your additional data. Either add an additional file (variable file or an additional header) or take advantage of notifiers that are observed to push your new data.

    There are pros and cons to both, but that's basically where to look.

    Also to get a little more "appreciation" of how/where to put things so that they are loaded where/when desired, recommend looking through index.php found at the root of the site to see generally what file(s) are loaded in what sequence.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Apr 2008
    Posts
    150
    Plugin Contributions
    0

    Default Re: Displaying new music product field and data on product pages

    In includes/modules/pages/product_music_info I have the header_php.php, main_template_vars.php, and main_template_vars_product_type.php files.

    header_php.php has almost nothing in it. It's a very small file with a bit of code at the bottom.

    main_template_vars.php, and main_template_vars_product_type.php, I have altered extensively to mimic the Artist field:

    main_template_vars.php:
    Code:
      
    $flag_show_product_music_info_artist = zen_get_show_product_switch($_GET['products_id'], 'artist');
    $flag_show_product_music_info_format  = zen_get_show_product_switch($_GET['products_id'], 'format');
    main_template_vars_product_type.php:
    Code:
        $music_extras = $db->Execute($sql);
    
        $sql = "select * from " . TABLE_RECORD_ARTISTS . "
                where artists_id = '" . $music_extras->fields['artists_id'] . "'";
    
        $artist = $db->Execute($sql);
    
        $sql = "select * from " . TABLE_RECORD_ARTISTS_INFO . "
                where artists_id = '" . $music_extras->fields['artists_id'] . "'
                and languages_id = '" . (int)$_SESSION['languages_id'] . "'";
    
        $artist_info = $db->Execute($sql);
    
        $sql = "select * from " . TABLE_MEDIA_FORMAT . "
                where format_id = '" . $music_extras->fields['format_id'] . "'";
    
        $format = $db->Execute($sql);
    
        $sql = "select * from " . TABLE_MEDIA_FORMAT_INFO . "
                where format_id = '" . $music_extras->fields['format_id'] . "'
                and languages_id = '" . (int)$_SESSION['languages_id'] . "'";
    and

    Code:
     * extract info from queries for use as template-variables:
     */
      $products_artist_name = $artist->fields['artists_name'];
      $products_artist_url = $artist_info->fields['artists_url'];
    
      $products_format_name = $format->fields['format_name'];
      $products_format_url = $format_info->fields['format_url'];
    
      $products_record_company_name = $record_company->fields['record_company_name'];
      $products_record_company_url = $record_company_info->fields['record_company_url'];
      $products_music_genre_name = $music_genre->fields['music_genre_name'];
      if (!empty($products_artist_url)) $products_artist_name = '<a href="' . zen_href_link(FILENAME_REDIRECT, 'action=music_artist&artists_id=' . zen_output_string_protected($music_extras->fields['artists_id']), 'NONSSL', true, false) . '" target="_BLANK">'.$products_artist_name.'</a>';
      if (!empty($products_format_url)) $products_format_name = '<a href="' . zen_href_link(FILENAME_REDIRECT, 'action=music_format&format_id=' . zen_output_string_protected($music_extras->fields['format_id']), 'NONSSL', true, false) . '" target="_BLANK">'.$products_format_name.'</a>';
      if (!empty($products_record_company_url)) $products_record_company_name = '<a href="' . zen_href_link(FILENAME_REDIRECT, 'action=music_record_company&record_company_id=' . zen_output_string_protected($music_extras->fields['record_company_id']), 'NONSSL', true, false) . '" target="_BLANK">'.$products_record_company_name.'</a>';
    
      // This should be last line of the script:
      $zco_notifier->notify('NOTIFY_PRODUCT_TYPE_VARS_END_PRODUCT_MUSIC_INFO');
    I've tried to copy as accurately as possible, so not sure where I may have gone wrong.

  5. #5
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,849
    Plugin Contributions
    11

    Default Re: Displaying new music product field and data on product pages

    lets see:

    • you have added fields/tables into the database
    • you are able to update them on the admin side
    • you are now having difficulty displaying them on the product info page


    does that accurately describe your current situation?

    if so, you have a couple of areas to look at to resolve this problem:

    • are you sure you are editing the correct template file (tpl_product_music_info_display.php)? you can add a constant into that file to see if it displays when you test. i'm sure you can figure that out. its very easy to be updating the wrong file.
    • if you are editing the correct template file, you then have to ensure that you correctly retrieved the data from the database. you can do that by adding:

      Code:
      print_r($format);
      print_r($format_info);


    if you can see the data on the page from the print_r command you should be able to then display the fields. if you can not see the data, you will have to go back and look at where you constructed those db objects and correct them.

    best.
    author of square Webpay.
    mxWorks now has Apple Pay and Google Pay. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  6. #6
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,731
    Plugin Contributions
    27

    Default Re: Displaying new music product field and data on product pages

    If you get through carlwhat's list and still have problems...

    Check out Twitch Hidden Searchable Model Number to find a file-map of the files you'll need to change to statically add one field from admin -> database -> product page:
    https://www.zen-cart.com/downloads.php?do=file&id=1794

    You'll see the modules/pages/product_info/main_template_vars.php file is preparing the data for output on the product page - storefront.

    $products_model_spoon = $product_info->fields['products_model_spoon'];


    Although not in the package (hiding the model is the point of that module) to output the data collected from the database on your product page simply add to includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_display.php:

    <h1 id="productName" class="productGeneral"><?php echo $products_name; ?><?php echo $products_model_spoon ; ?></h1>

    or anywhere you would like to display the new data.

    Also note: Be certain to edit the correct product type files in admin as there is a collect_info.php page for each type.
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    Twitch Base8 - Obsidian - This, is what's new.

  7. #7
    Join Date
    Apr 2008
    Posts
    150
    Plugin Contributions
    0

    Default Re: Displaying new music product field and data on product pages

    Quote Originally Posted by carlwhat View Post
    lets see:

    • you have added fields/tables into the database
    • you are able to update them on the admin side
    • you are now having difficulty displaying them on the product info page


    does that accurately describe your current situation?

    if so, you have a couple of areas to look at to resolve this problem:

    • are you sure you are editing the correct template file (tpl_product_music_info_display.php)? you can add a constant into that file to see if it displays when you test. i'm sure you can figure that out. its very easy to be updating the wrong file.
    • if you are editing the correct template file, you then have to ensure that you correctly retrieved the data from the database. you can do that by adding:

      Code:
      print_r($format);
      print_r($format_info);


    if you can see the data on the page from the print_r command you should be able to then display the fields. if you can not see the data, you will have to go back and look at where you constructed those db objects and correct them.

    best.
    I do have the Table: media_format in the database, and I can write to it. Though it doesn't appear to have the Edit Copy Delete options in front of each row like other tables do. Still, I can edit them through Admin>Extras>Media Format, and I can media format values into individual products through the product creation page.

    My override was not set up well and I did not see it in my Admin>Tools>Template Selection. I fixed that and now see the select option in my admin and have it set to that. Prior to that tpl_product_music_info_display.php in the template default was handling the page. After adding the print commands
    Code:
    print_r($format);
    print_r($format_info);
    I get a real mess that looks like this (I've deleted anything that looks like specific server information):
    queryFactoryResult Object ( [EOF] => [cursor] => 0 [fields] => Array ( [format_id] => 4 [format_name] => 7" vinyl [format_image] => [date_added] => [last_modified] => ) [is_cached] => [result] => Array ( ) [result_random] => [limit] => [resource] => mysqli_result Object ( [current_field] => 0 [field_count] => 5 [lengths] => Array ( [0] => 1 [1] => 8 [2] => 0 [3] => 0 [4] => 0 ) [num_rows] => 1 [type] => 0 ) [link] => mysqli Object ( [affected_rows] => 1 [client_info] => DELETED [client_version] => 100134 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 1 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => DELETED [server_version] => 100131 [stat] => Uptime: 569284 Threads: 17 Questions: 313305399 Slow queries: 0 Opens: 85935 Flush tables: 1 Open tables: 26083 Queries per second avg: 550.349 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 4359777 [warning_count] => 0 ) [sql_query] => select * from media_format where format_id = '4' ) queryFactoryResult Object ( [EOF] => 1 [cursor] => 0 [fields] => [is_cached] => [result] => Array ( ) [result_random] => [limit] => [resource] => mysqli_result Object ( [current_field] => 0 [field_count] => 5 [lengths] => [num_rows] => 0 [type] => 0 ) [link] => mysqli Object ( [affected_rows] => -1 [client_info] => DELETED [client_version] => 100134 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 1 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => DELETED [server_version] => 100131 [stat] => Uptime: 569284 Threads: 17 Questions: 313305399 Slow queries: 0 Opens: 85935 Flush tables: 1 Open tables: 26083 Queries per second avg: 550.349 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 4359777 [warning_count] => 0 ) [sql_query] => select * from media_format_info where format_id = '4' and languages_id = '1' )
    I'm not getting any error logs, but not exactly getting the field value I was hoping for either.

    Also, when working correctly I should be able to control this field display through the admin under Admin>Catalog>Product Types (click on product type selection) in the Product Type Info Page Layout options :: Product - Music. I believe there is a table in the database that lists those admin options. But my last attempt to fix that too didn't go very well.

  8. #8
    Join Date
    Jul 2012
    Posts
    16,799
    Plugin Contributions
    17

    Default Re: Displaying new music product field and data on product pages

    What that means is that is the value returned from your query isn't being handled the way expected.

    Can't seem to be able to tell which variable was posted, whether $format or $format_info, but whichever it is was basically set like:

    $var = $db->Execute("SELECT * FROM " . TABLE_MEDIA_FORMAT_INFO . " WHERE format_id = '" . $some_selected_value . "' AND languages_id = '" . (int)$_SESSION['languages_id'] . "'");

    In order to get the specific value of one of the five fields of the table: ([format_id] => 4 [format_name] => 7" vinyl [format_image] => [date_added] => [last_modified] => ), need to reference the field more directly:

    $format_name = $var->fields['format_name'];


    As to the setting options in the product type, yes there are a few things that need to be brought together to add those and to be sure that the naming convention works with other built in software.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    Apr 2008
    Posts
    150
    Plugin Contributions
    0

    Default Re: Displaying new music product field and data on product pages

    Quote Originally Posted by mc12345678 View Post
    What that means is that is the value returned from your query isn't being handled the way expected.

    Can't seem to be able to tell which variable was posted, whether $format or $format_info, but whichever it is was basically set like:

    $var = $db->Execute("SELECT * FROM " . TABLE_MEDIA_FORMAT_INFO . " WHERE format_id = '" . $some_selected_value . "' AND languages_id = '" . (int)$_SESSION['languages_id'] . "'");

    In order to get the specific value of one of the five fields of the table: ([format_id] => 4 [format_name] => 7" vinyl [format_image] => [date_added] => [last_modified] => ), need to reference the field more directly:

    $format_name = $var->fields['format_name'];
    Could this be caused by confusing the fields? That is, ZC refers to the artist field in the plural (record_artists, artists_id), sometimes singular (TEXT_PRODUCT_ARTIST, $artist). But I simply replaced all instances of "record" with "media," and "artist/artists" with "format," thinking they would still remain unique. "TEXT_PRODUCT_FORMAT" and "media_format." Could that cause a problem like this? Except for the Product Type Info Page Layout options, all seems to be working on the admin side.

    I'm also having a very hard time overriding includes/modules/pages/product_music_info/main_template_vars_product_type.php (which appears to determine the display on music products). I was trying to avoid altering the ZC issued file, but as of now that's all I seem to be able to work with.

  10. #10
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,849
    Plugin Contributions
    11

    Default Re: Displaying new music product field and data on product pages

    joe,
    i would like to stay on point, which goes back to post #5: you have updated on the admin side, but you cannot display it on the customer side. i then quoted 2 possibilities, which is you are either not modifying the correct template file or you are not getting the data correctly from the database.

    based on the information you have posted, you are modifying the correct template file. so we can eliminate that from your problem. in addition, in post #4, you have the following code:

    Code:
      $products_format_name = $format->fields['format_name'];
      $products_format_url = $format_info->fields['format_url'];
    based on the information provided, $products_format_name is correctly populated, and can be used on the template page. your title and OP says you are having difficulty displaying new product field data on product pages. and yet your code suggests that by echoing that var, you can safely use that element, which would say "vinyl". have you tried using that variable on the product info page? is that the correct value for that variable for this product?

    your other variable is not being correctly populated as the sql statement you have constructed returns nothing:

    Code:
    select * from media_format_info where format_id = '4' and languages_id = '1'
    so you have incorrectly populated that table or incorrectly constructed the above sql statement.

    in addition, the populating of the first table seems to be missing some fields as the date modified and date added have no values.

    with regards to not modifying core ZC files, good luck with that! (said sarcastically....) as i have previously stated, i do not think what you are trying to do is easy. and it is not handled easily in other shopping cart systems that provide overrides and field creation and the like.... my opinion previously stated is to put as much as possible in your own extra_functions file and then call needed functions, most likely from the template file to preserve as much of the ZC core as possible. and if you truly want to have an audit trail of what you are doing, i would put all source under a source version control system, ie git, so that you can see what you did. (mind you, learning git is a major job in and/of itself; but well worth the value in the long run...)

    with regards to the problem and your question raised in #9 above, frankly i'm at a loss. i do not agree w MCs statement that "..the value returned from your query isn't being handled the way expected." i provided you some tools to see what is available in the database objects you constructed, named $format and $format_info. they provided exactly the information i expected/needed to help you with your problem. if you look closely at the "real mess" object that you provided, perhaps you can better understand what those objects are and now to use them.

    best.
    author of square Webpay.
    mxWorks now has Apple Pay and Google Pay. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v155 Adding New Fields to the Music Product Type that Display on Store Pages
    By Joseph M in forum All Other Contributions/Addons
    Replies: 3
    Last Post: 12 Aug 2018, 11:07 PM
  2. 1060 error choosing 'Product - Music' and new product
    By RAD1964 in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 22 Nov 2011, 09:41 PM
  3. New product data field?
    By AnimeJim in forum General Questions
    Replies: 1
    Last Post: 28 May 2010, 10:15 AM
  4. Replies: 1
    Last Post: 16 Oct 2009, 04:03 PM
  5. New Product Type - issue with displaying new field
    By rwoody in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 22 Nov 2007, 12:24 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