Using Files Containing Boilerplate Text in the osCommerce Product Description
Donate! Show your appreciation by
supporting my efforts.
Relevance: osCommerce 2.2rc2a and forward. The same approach can be used in prior versions.
Cost: Free, but
donation appreciated
Related:
Using Boilerplate Text in the Product Description
Including entire files of boilerplate in the description can be done in
a manner similar to that described in a prior tip called
Using Boilerplate Text in the Product Description. However, instead of the keyword being replaced by a string,
I'll show you how to replace a keyword with a file.
Create the directory
catalog/includes/languages/<your-language>/boilerplate
You will populate this directory with files whose names are <some-keyword>.html. For instance, suppose you have some text you want
to add to all your DVD products. Create a file called DVD.html in this directory, i.e.
catalog/includes/languages/<your-language>/boilerplate/DVD.html
Put whatever HTML marked-up text you want in that file.
Now go to
catalog/product_info.php
Replace
<p><?php echo stripslashes($product_info['products_description']); ?></p>
with this code:
<?php
function html_include_cb($match) {
$prefix = "HTML_INCLUDE_";
$match_filename = str_replace($prefix, '', $match[0]);
$filename = DIR_WS_LANGUAGES . $_SESSION['language'] .
'/boilerplate/' .
$match_filename . ".html";
$buffer = "";
if (file_exists($filename)) {
$handle = @fopen($filename, "r");
while (!feof($handle)) {
$buffer .= fgets($handle, 4096);
}
fclose($handle);
}
return $buffer;
}
$products_description = $product_info['products_description'];
$pattern = "/HTML_INCLUDE_[a-zA-Z0-9]*/";
$products_description = preg_replace_callback($pattern, "html_include_cb",
$products_description, -1);
echo '<p>' . stripslashes($products_description) . '</p>';
?>
Now to use this logic, all you need to do is enter HTML_INCLUDE_DVD in
the product description
(under Admin - Categories), and when you
display the product info page, it will be changed.
For any HTML_INCLUDE_SomeAlphanumericString you add to a product
description, simply create a file called
includes/languages/<your-language>/boilerplate/SomeAlphanumericString.html
and it will automatically be displayed. Note that the string really does have
to be alphanumeric; don't use dashes, underscores, spaces or special
characters in the name.
Although this tip describes the additive use of HTML Boilerplate, it can
also be used to completely replace the product description which is entered in the
osCommerce Admin Panel.
| Certificates of appreciation most welcome! |
|
|
If the information you learned reading this site is helping your store make
more money, please consider making a donation. Thank you!
|