OK, my HTML/CSS is strong, my JS is ‘capable’ and my PHP is ‘weak’!
However, I’m trying to improve this situation. And I’m hoping solving this problem will help me understand PHP/MySQL a little better and put me on a path to PHP enlightenment. I hope some clever bean can offer some words of wisdom…
Background
I am building a site based on Cubecart (a PHP/MySQL ecommerce platform).
The problem
Here is a screengrab to show the issue (building it with MAMP at present so no live url):
At the footer of the site is a featured products section which displays products and prices. When a user switches currency (on the left), the price and currency symbol change accordingly.
In the right sidebar I have a popular products section, however, by default this does not show the price and currency symbol. How do I make it?
More information about how Cubecart works
Cubecart uses a controlling php file and then a tpl template file to control the output.
Example code from the working section
For example, the latest products section uses the following PHP file:
if (!defined('CC_INI_SET')) die("Access Denied");
$lang = getLang("includes".CC_DS."boxes".CC_DS."randomProd.inc.php");
$seed = mt_rand(1, 10000);
if(isset($_GET['catId'])) {
$_GET['catId'] = (int)$_GET['catId'];
}
$whereClause = (isset($_GET['catId'])) ? "AND I.cat_id=".$db->mySQLSafe($_GET['catId'])." AND I.cat_id > 0 AND C.hide != '1'" : "AND I.cat_id > 0";
$sql = sprintf("SELECT I.name, I.image, I.productId FROM %1\\$sCubeCart_inventory AS I, %1\\$sCubeCart_category AS C WHERE I.cat_id = C.cat_id AND I.disabled != '1' AND C.hide = '0' AND (C.cat_desc != '##HIDDEN##' OR C.cat_desc IS NULL) %2\\$s ORDER BY RAND(%3\\$d) LIMIT 1", $glob['dbprefix'], $whereClause, $seed);
$randProd = $db->select($sql);
if ($randProd) {
if (($val = prodAltLang($randProd[0]['productId'])) !== false) {
$randProd[0]['name'] = $val['name'];
}
$box_content = new XTemplate ('boxes'.CC_DS.'randomProd.tpl');
$box_content->assign('LANG_RANDOM_PRODUCT',$lang['randomProd']['featured_prod']);
$box_content->assign('PRODUCT_ID',$randProd[0]['productId']);
$box_content->assign('PRODUCT_NAME',validHTML($randProd[0]['name']));
$thumbRootPath = imgPath($randProd[0]['image'],1,'root');
$thumbRelPath = imgPath($randProd[0]['image'],1,'rel');
if (file_exists($thumbRootPath) && !empty($randProd[0]['image'])) {
$box_content->assign('IMG_SRC', $thumbRelPath);
} else {
$box_content->assign('IMG_SRC', $GLOBALS['rootRel'].'skins/'. SKIN_FOLDER . '/styleImages/thumb_nophoto.gif');
}
$box_content->parse('random_prod');
$box_content = $box_content->text('random_prod');
} else {
$box_content = '';
}
?>
And then the following in the template file:
<div class="boxTitleRight">{LANG_RANDOM_PRODUCT}</div>
<div class="boxContentLeft" style="text-align: center">
<a href="index.php?_a=viewProd&productId={PRODUCT_ID}" title="{PRODUCT_NAME}"><img src="{IMG_SRC}" alt="{PRODUCT_NAME}" border="0" title="{PRODUCT_NAME}" /></a>
<br />
<span class="txtCopy"><a href="index.php?_a=viewProd&productId={PRODUCT_ID}" title="{PRODUCT_NAME}" class="txtDefault">{PRODUCT_NAME}</a></span>
</div>
This code is somehow grabbing the price of the item and the correct currency and displaying it correctly. My thinking is I need to grab the relevant sections of code, stick them in my popularProducts.inc.php (the controlling file for the Popular Products section) and it will show the correct price and currency for each popular product item too.
However, what part of that little lot specifies the price and what currency to use?
Any pointers greatly appreciated.