Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Add Default Text in "New Product" Fields?


hawken

Recommended Posts

I have installed the Extra Fields 2.3 mod onto my shop, and made a new field called "Download Link".

 

When creating a new product, I have to manually enter <a href="LINK" target="_blank"><img src="DOWNLOADBUTTON.JPG" border="0" alt="Download Now"></a>

 

Is there a way to have that text already load into my new field, so that when adding a new product, I only need to enter the LINK itself, rather than the whole HTML code?

 

Thank you.

Link to comment
Share on other sites

If the rest of that never changes, why put it into the database? Add it into the page where you want it to show and have the database filed be just the link.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

If the rest of that never changes, why put it into the database? Add it into the page where you want it to show and have the database filed be just the link.

 

Regards

Jim

 

that does sound easier, thank you Jim! How do I do that? haha

 

So on product_info.php if I add "<a href="LINK" target="new"><img src="download_button.jpg" border="0" alt="Download Now"></a>", what text do I have to enter to display the "LINK" I entered in my newly added field?

 

<?php
/*
 $Id$

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2010 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);

 $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
 $product_check = tep_db_fetch_array($product_check_query);

// begin Extra Product Fields
 $epf = array();
 if ($product_check['total'] > 0) {
   $epf_query = tep_db_query("select * from " . TABLE_EPF . " e join " . TABLE_EPF_LABELS . " l where e.epf_status and (e.epf_id = l.epf_id) and (l.languages_id = " . (int)$languages_id . ") and l.epf_active_for_language order by epf_order");
   while ($e = tep_db_fetch_array($epf_query)) {  // retrieve all active extra fields
     $field = 'extra_value';
     if ($e['epf_uses_value_list']) {
       if ($e['epf_multi_select']) {
         $field .= '_ms';
       } else {
         $field .= '_id';
       }
     }
     $field .= $e['epf_id'];
     $epf[] = array('id' => $e['epf_id'],
                    'label' => $e['epf_label'],
                    'uses_list' => $e['epf_uses_value_list'],
                    'multi_select' => $e['epf_multi_select'],
                    'columns' => $e['epf_num_columns'],
                    'display_type' => $e['epf_value_display_type'],
                    'show_chain' => $e['epf_show_parent_chain'],
                    'search' => $e['epf_advanced_search'],
                    'keyword' => $e['epf_use_as_meta_keyword'],
                    'field' => $field);
   }
   $query = "select p.products_date_added, p.products_last_modified, pd.products_name";
   foreach ($epf as $e) {
     if ($e['keyword']) $query .= ", pd." . $e['field'];
   }
   $query .= " from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'";
   $pname = tep_db_fetch_array(tep_db_query($query));
   $datemod = substr((tep_not_null($pname['products_last_modified']) ? $pname['products_last_modified'] : $pname['products_date_added']), 0, 10);
 } else {
   $pname = TEXT_PRODUCT_NOT_FOUND;
   $datemod = date('Y-m-d');
 }
// end Extra Product Fields


 require(DIR_WS_INCLUDES . 'template_top_extra_fields.php');

 if ($product_check['total'] < 1) {
?>

<div class="contentContainer">
 <div class="contentText">
   <?php echo TEXT_PRODUCT_NOT_FOUND; ?>
 </div>

 <div style="float: right;">
   <?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'triangle-1-e', tep_href_link(FILENAME_DEFAULT)); ?>
 </div>
</div>

<?php
 } else {
// begin Product Extra Fields
   $query = "select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id";
   foreach ($epf as $e) {
     $query .= ", pd." . $e['field'];
   }
   $query .= " from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'";
   $product_info_query = tep_db_query($query);
   // end Product Extra Fields

   $product_info = tep_db_fetch_array($product_info_query);

   tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . (int)$languages_id . "'");

   if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
     $products_price = '<del>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</del> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
   } else {
     $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
   }

   if (tep_not_null($product_info['products_model'])) {
     $products_name = $product_info['products_name'] . '<br /><span class="smallText">[' . $product_info['products_model'] . ']</span>';
   } else {
     $products_name = $product_info['products_name'];
   }
?>

<?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?>

<div>
 <h1 style="float: right;"><?php echo $products_price; ?></h1>
 <h1><?php echo $products_name; ?></h1>
</div>

<div class="contentContainer">
 <div class="contentText">

<?php
   if (tep_not_null($product_info['products_image'])) {
     $pi_query = tep_db_query("select image, htmlcontent from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order");

     if (tep_db_num_rows($pi_query) > 0) {
?>

   <div id="piGal">
     <ul>

<?php
       $pi_counter = 0;
       while ($pi = tep_db_fetch_array($pi_query)) {
         $pi_counter++;

         $pi_entry = '        <li><a href="';

         if (tep_not_null($pi['htmlcontent'])) {
           $pi_entry .= '#piGalimg_' . $pi_counter;
         } else {
           $pi_entry .= tep_href_link(DIR_WS_IMAGES . $pi['image']);
         }

         $pi_entry .= '" target="_blank" rel="fancybox">' . tep_image(DIR_WS_IMAGES . $pi['image']) . '</a>';

         if (tep_not_null($pi['htmlcontent'])) {
           $pi_entry .= '<div style="display: none;"><div id="piGalimg_' . $pi_counter . '">' . $pi['htmlcontent'] . '</div></div>';
         }

         $pi_entry .= '</li>';

         echo $pi_entry;
       }
?>

     </ul>
   </div>

<script type="text/javascript">
$('#piGal ul').bxGallery({
 maxwidth: 300,
 maxheight: 200,
 thumbwidth: <?php echo (($pi_counter > 1) ? '75' : '0'); ?>,
 thumbcontainer: 300,
 load_image: 'ext/jquery/bxGallery/spinner.gif'
});
</script>

<?php
     } else {
?>

   <div id="piGal">
     <?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES . $product_info['products_image']) . '" target="_blank" rel="fancybox">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], addslashes($product_info['products_name']), null, null, 'hspace="5" vspace="5"') . '</a>'; ?>
   </div>

<?php
     }
?>

<script type="text/javascript">
$("#piGal a[rel^='fancybox']").fancybox({
 cyclic: true
});
</script>

<?php
   }
?>

<div class="description"><?php echo stripslashes($product_info['products_description']); ?></div>

<?php
   $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
// begin Extra Product Fields
 foreach ($epf as $e) {
   $mt = ($e['uses_list'] && !$e['multi_select'] ? ($product_info[$e['field']] == 0) : !tep_not_null($product_info[$e['field']]));
   if (!$mt) { // only display if information is set for product
     echo '<b>' . $e['label'] . ': </b>';
     if ($e['uses_list']) {
       if ($e['multi_select']) {
         $values = explode('|', trim($product_info[$e['field']], '|'));
         $listing = array();
         foreach ($values as $val) {
           $listing[] = tep_get_extra_field_list_value($val, $e['show_chain'], $e['display_type']);
         }
         echo implode(', ', $listing);
       } else {
         echo tep_get_extra_field_list_value($product_info[$e['field']], $e['show_chain'], $e['display_type']);
       }
     } else {
       echo $product_info[$e['field']];
     }
     echo '<br>';
   }
 }
 // end Extra Product Fields

   $products_attributes = tep_db_fetch_array($products_attributes_query);
   if ($products_attributes['total'] > 0) {
?>

   <p><?php echo TEXT_PRODUCT_OPTIONS; ?></p>

   <p>
<?php
     $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");
     while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
       $products_options_array = array();
       $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");
       while ($products_options = tep_db_fetch_array($products_options_query)) {
         $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
         if ($products_options['options_values_price'] != '0') {
           $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
         }
       }

       if (is_string($HTTP_GET_VARS['products_id']) && isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
         $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
       } else {
         $selected_attribute = false;
       }
?>
     <strong><?php echo $products_options_name['products_options_name'] . ':'; ?></strong><br /><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?><br />
<?php
     }
?>
   </p>

<?php
   }
?>

   <div style="clear: both;"></div>

<?php
   if ($product_info['products_date_available'] > date('Y-m-d H:i:s')) {
?>

   <p style="text-align: center;"><?php echo sprintf(TEXT_DATE_AVAILABLE, tep_date_long($product_info['products_date_available'])); ?></p>

<?php
   }
?>

 </div>

<?php
   $reviews_query = tep_db_query("select count(*) as count from " . TABLE_REVIEWS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and reviews_status = 1");
   $reviews = tep_db_fetch_array($reviews_query);
?>

	<div class="buttonSet">
	<?php
       // http://www.linuxuk.co.uk FIMBLE: added for osC info site
        if (SHOW_BUTTON == 'True'){?>
	<span class="buttonAction"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', null, 'primary'); ?></span>
	<?php }
	if ((SHOW_REVIEWS == 'True') || (MASTER_SWTICH == 'True' )){?>
	<?php echo tep_draw_button(IMAGE_BUTTON_REVIEWS . (($reviews['count'] > 0) ? ' (' . $reviews['count'] . ')' : ''), 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params())); ?>
	<?php
        }   // http://www.linuxuk.co.uk FIMBLE: added for osC info site
       ?>
	</div>

<?php
   if ((USE_CACHE == 'true') && empty($SID)) {
     echo tep_cache_also_purchased(3600);
   } else {
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }
?>

</div>

</form>

<?php
 }

 require(DIR_WS_INCLUDES . 'template_bottom.php');
 require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Link to comment
Share on other sites

I'm not an expert on Extra Product Fields. Given that, I would try replacing this line:

        echo $product_info[$e['field']];

with this:

        echo '<a href="' . tep_href_link($product_info[$e['field']]) . ' target="new"><img src="download_button.jpg" border="0" alt="Download Now"></a>';

Or something like that. Probably should use the tep_image function, or the jquery button if you are in 2.3.1. First let's see if this actually works.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

You're definitely on to something!! That's very close to what I need.

 

The problem is, the link is:

http://www.blocktapes.com/catalog/http://www.blocktapes.com/mixtapes/Chamillionaire-Badazz_Freemixes-2011-Blocktapes.zip%20target=

 

the link should be (And is what I enter in the field when adding the product):

http://www.blocktapes.com/mixtapes/Chamillionaire-Badazz_Freemixes-2011-Blocktapes.zip

Link to comment
Share on other sites

Missed one lousy little double quote. Try this:

        echo '<a href="' . tep_href_link($product_info[$e['field']]) . '" target="new"><img src="download_button.jpg" border="0" alt="Download Now"></a>';

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

Genius! Thank you!! I had to change it a bit, because the link was still coming out as:

http://www.blocktapes.com/catalog/http://www.blocktapes.com/mixtapes/Chamillionaire-Badazz_Freemixes-2011-Blocktapes.zip

 

I changed it to:

echo '<a href="' . $product_info[$e['field']] . '" target="new"><img src="http://www.blocktapes.com/catalog/images/download_button.jpg" border="0" alt="Download Now"></a>';

 

Now it displays the link exactly as I enter it in admin!! Thank you very much! I owe you.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...