Forums / Templates, Stylesheets, Page Layout / PHP - Lost, any advice?

PHP - Lost, any advice?

Views: 1,886

Results 1 to 13 of 13
16 Apr 2014, 4:01 AM
#1
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

PHP - Lost, any advice?

Hello,

I was wondering why adding the code in red below to 'modules/custom/product_listing.php' doesn't display the media link after the price in the Product Listings. Is there anywhere else I should try to add this code, or is this a much bigger job than I think?

        case 'PRODUCT_LIST_NAME':
        $lc_align = '';
        if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        } else {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        }
		require($template->get_template_dir('/tpl_modules_media_manager.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_media_manager.php') ;
        break;
16 Apr 2014, 4:26 AM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: PHP - Lost, any advice?

You need to accumulate the output into $lc_text, not just process/output it immediately. Is it outputting somewhere early in the page before any of the listing? That is what I would expect if it is functioning at all now.

16 Apr 2014, 4:31 AM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: PHP - Lost, any advice?

That is a reasonable place to add the code; you just need to alter it so that it saves the output in a variable which can then be appended to $lc_text.```php
//fetch the link content for the current product and save in $your_link_content
$lc_text .= $your_link_content;

16 Apr 2014, 4:36 AM
#4
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

Thanks for the reply! No, it's not outputting anything. When I append the code it's calling from 'tpl_modules_media_manager' to $lc_text it just returns a value of '1' with no links. Is there any way I can slip that code into the template file 'tpl_product_listing' or anywhere else to make it work?

16 Apr 2014, 4:49 AM
#5
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

Something like this?

        case 'PRODUCT_LIST_NAME':
        $lc_align = '';
        if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        } else {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '<span class="Play" href="' zen_href_link(DIR_WS_MEDIA  . $za_clip['clip_filename'], '', 'NONSSL', false, true, true) .  '" target="_blank">' . '<span class="mediaClipFilename">' . $za_clip['clip_filename'] . '</span>' . (!empty($za_clip['clip_type']) ? '<span class="mediaClipType"> (' . $za_clip['clip_type'] . ')</span>' : ''); '</div>' ;
        }
        break;
16 Apr 2014, 7:42 AM
#6
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

Still going crazy :smile: Any suggestions?

Added to top of 'product_listing.php'

		function getScriptOutput($path, $print = FALSE){
			ob_start();
			if( is_readable($path) && $path )
			{
				include $path;
			}
			else
			{
				return FALSE;
			}
			if( $print == FALSE )
				return ob_get_clean();
			else
				echo ob_get_clean();
		}

And made these changes, but no luck..

        case 'PRODUCT_LIST_NAME':
        $lc_align = '';
        if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        } else {

		$path = DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_media_manager.php');
		$html = getScriptOutput($path);
		$lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . $html . '</div>' ;
        }
        break;

Please help!:frusty:

16 Apr 2014, 9:23 AM
#7
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

This doesn't work either lol? :wacko:

        case 'PRODUCT_LIST_NAME':
        $lc_align = '';
        if (isset($_GET['manufacturers_id'])) {
          $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>' ;
        } else {
		
  require(DIR_WS_MODULES . zen_get_module_directory('media_manager.php'));
				$za_play = $zq_clips->fields['clip_filename'] ;
				$lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '<a href ="' . $za_play . '">' . '<img src="images/play_button.png"/>' . '</div>' ;
        }
        break;
17 Apr 2014, 3:15 AM
#8
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

I think I can get this working if I can just figure out how to set a variable ($za_play) to the 'clip filename' in 'media_manager.php' Any suggestions as to what I'm doing wrong?

<?php
/**
 * iterates thru media collections/clips
 *
 * @package productTypes
 * @copyright Copyright 2003-2009 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: media_manager.php 11825 2009-01-15 09:46:19Z drbyte $
 */
if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}

/**
 * get list of media collections assigned to specified product
 */
$zv_collection_query = "select media_id, product_id from " . TABLE_MEDIA_TO_PRODUCTS . "
                        where product_id = '" . (int)$_GET['products_id'] . "'";
$zq_collections = $db->Execute($zv_collection_query);
$zv_product_has_media = false;
$za_play = 'HELLO';
/**
 * loop thru collections to identify actual media clips
 */
if ($zq_collections->RecordCount() > 0) {
  $zv_product_has_media = true;
  while (!$zq_collections->EOF) {
    /**
     * get names of assigned media collections
     */
    $zf_media_manager_query = "select media_id, media_name from " . TABLE_MEDIA_MANAGER . "
                               where media_id = '" . (int)$zq_collections->fields['media_id'] . "'";
    $zq_media_manager = $db->Execute($zf_media_manager_query);
    if ($zq_media_manager->RecordCount() < 1) {
      $zv_product_has_media = false;
    } else {
      /**
       * build array of [collection_id][text] = collection-name
       */
      $za_media_manager[$zq_media_manager->fields['media_id']] = array('text' => $zq_media_manager->fields['media_name']);
      /**
       * get list of media clips associated with the current media collection, sorted by filename (to allow display sort order to be controlled by filename)
       */
      $zv_clips_query = "select media_id, clip_id, clip_filename, clip_type from " . TABLE_MEDIA_CLIPS . "
                         where media_id = '" . (int)$zq_media_manager->fields['media_id'] . "' order by clip_filename";
      $zq_clips = $db->Execute($zv_clips_query);
      if ($zq_clips->RecordCount() < 1) {
        $zv_product_has_media = false;
      } else {
        while (!$zq_clips->EOF) {
          /**
           * get list of media types and filenames associated with the current media
           * @TODO - run this as separate static array, since only needs to run once, not repeatedly in a loop
           */
          $zf_clip_type_query = "select type_ext, type_name from " . TABLE_MEDIA_TYPES . "
                                 where type_id = '" . (int)$zq_clips->fields['clip_type'] . "'";

          $zq_clip_type = $db->Execute($zf_clip_type_query);

          $za_media_manager[$zq_media_manager->fields['media_id']]['clips'][$zq_clips->fields['clip_id']] =
                array('clip_filename' => $zq_clips->fields['clip_filename'],
                      'clip_type' => $zq_clip_type->fields['type_name']);
          $zq_clips->MoveNext();
		  
        }
      }
    }
    $zq_collections->MoveNext();
  }
}
$zv_product_has_media = (sizeof($za_media_manager)) > 0 ? TRUE : FALSE;

$za_play = $zq_clips->fields['clip_filename'];
18 Apr 2014, 4:44 AM
#9
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

Any suggestions? I just need to append the products single clip_filename to the product name.

19 Apr 2014, 3:29 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: PHP - Lost, any advice?

Try this:

        case 'PRODUCT_LIST_NAME':        $lc_align = '';
        $lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id'] > 0) ?  zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '</a></h3><div class="listingDescription">' . zen_trunc_string(zen_clean_html(stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';
        // bof: display media clip filenames
        $_GET['products_id'] = $listing->fields['products_id'];
        require(DIR_WS_MODULES . zen_get_module_directory('media_manager.php'));
        if ($zv_product_has_media) {
          while (list($za_media_key, $za_media) = each($za_media_manager)) {
            while(list($za_clip_key, $za_clip) = each($za_media_manager[$za_media_key]['clips'])) {
              $lc_text .= $za_clip['clip_filename'];
            }
          }
        }
        unset($_GET['products_id'], $za_media_manager, $zv_product_has_media);
        // eof: display media clip filenames
        break;
        case 'PRODUCT_LIST_MANUFACTURER':

If that works for you, donations always appreciated at: https://www.zen-cart.com/donate

.
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.

20 Apr 2014, 12:50 AM
#11
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

Thank you so much! I will definitely send a donation.

4 May 2014, 9:11 PM
#12
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

I just had 1 more question about this. Code works great in the product_listing but when I add it to a Featured Items mod it causes all the info on the product pages not to display.

    if (DISPLAY_FLEX_FEATURED_CENTERBOX_NAME == 'true') {
		$products_name = '<span class="flexFCBname"><a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' . $featured_products->fields['products_id']) . '">' . $featured_products->fields['products_name'] . '</a>' . '</span>';
		// bof: display media clip filenames
        $_GET['products_id'] = $featured_products->fields['products_id'];
        require(DIR_WS_MODULES . zen_get_module_directory('media_manager.php'));
        if ($zv_product_has_media) {
          while (list($za_media_key, $za_media) = each($za_media_manager)) {
            while(list($za_clip_key, $za_clip) = each($za_media_manager[$za_media_key]['clips'])) {
			$products_name .= '   <span class="Play" href ="media/' . $za_clip['clip_filename'] . '">' . '<img src="images/play_button.png"/></span>';
            }
          }
        }
        unset($_GET['products_id'], $za_media_manager, $zv_product_has_media);
        // eof: display media clip filenames

Example here:
https://www.hiphopbeatz.com/2014

I think it has to do with unset($_GET['products_id']. Any suggestions?

Thanks!

4 May 2014, 11:18 PM
#13
jenniferxo avatar

jenniferxo

New Zenner

Join Date:
Apr 2014
Location:
Los Angeles
Posts:
41
Plugin Contributions:
0

Re: PHP - Lost, any advice?

This did the trick:

unset($za_media_manager, $zv_product_has_media);
$_GET['products_id'] = $_REQUEST['products_id'];