ich versuche gerade die Shopping Card aus diesem Tutorial (http://www.qualitycodes.com/tutorial.php?articleid=25) in ein Modul zu packen.
Ich bin erst bei der Products-Seite und kommt nicht weiter - hoffe Ihr könnt mir helfen.
Die Testdaten die ich versuche auszulesen liegen in der sc_products
Code: Alles auswählen
INSERT INTO `sc_products` (`serial`, `name`, `description`, `price`, `picture`) VALUES
(1, 'View Sonic LCD', '19" View Sonic Black LCD, with 10 months warranty', 250, 'upload/shop/lcd.jpg'),
(2, 'IBM CDROM Drive', 'IBM CDROM Drive', 80, 'images/cdrom-drive.jpg'),
(3, 'Laptop Charger', 'Dell Laptop Charger with 6 months warranty', 50, 'upload/shop/charger.jpg'),
(4, 'Seagate Hard Drive', '80 GB Seagate Hard Drive in 10 months warranty', 40, 'upload/shop/hard-drive.jpg'),
(5, 'Atech Mouse', 'Black colored laser mouse. No warranty', 5, 'upload/shop/mouse.jpg'),
(6, 'Nokia 5800', 'Nokia 5800 XpressMusic is a mobile device with 3.2" widescreen display brings photos, video clips and web content to life', 299, 'upload/shop/mobile.jpg');
SC-Products_container.html
Code: Alles auswählen
<table border="0" cellpadding="0" width="100%">
{items}
</table>
Code: Alles auswählen
<tr>
<td>{IMG}</td>
<td> <b>{NAME}</b><br />
{DESCRIPTION}<br />
{PRICE}:<big style="color:green">
{CURRENCY}{PRICE-DEC}</big><br /><br />
<input type="button" value="Add to Cart" onclick="addtocart({SERIAL})" />
</td>
</tr>
<tr><td colspan="2"><hr size="1" /></td></tr>

Code: Alles auswählen
<?php
#Includes
cInclude('classes', 'SC.functions.php');
//check if there is a template instance
if (!is_object($tpl)) {
$tpl = new Template;
}
// reset template object
$tpl->reset();
$limit = 20;
// build shopping card
$sql = "SELECT * FROM sc_products";
$db->query($sql);
if ($db->next_record()) {
$picture = $db->f('picture');
$name = $db->f('name');
$description = $db->f('description');
$price = $db->f('price');
$serial = $db->f('serial');
}
var_dump($count);
if($db->num_rows() > 0) {
$count = $db->num_rows();
var_dump($count);
if ($count > 0) {
if (is_numeric($limit) AND strlen($limit) > 0) {
if ($limit < $list->count) {
$limit_art = $limit;
} else {
$limit_art = $list->count;
}
} else {
$limit_art = $list->count;
}
for ($i = 0; $i < $limit_art; $i ++) {
$tpl->set('d', 'IMG', $picture);
$tpl->set('d', 'NAME', $name);
$tpl->set('d', 'DESCRIPTION', $description);
$tpl->set('d', 'PRICE', mi18n("Preis"));
$tpl->set('d', 'CURRENCY', mi18n("€"));
$tpl->set('d', 'PRICE-DEC', $price);
$tpl->set('d', 'SERIAL', $serial);
$tpl->next();
}
$sItems = $tpl->generate('templates/SC-Products_items.html', true, false);
$tpl->reset();
$tpl->set('s', 'items', $sItems);
$tpl->generate('templates/SC-Products_container.html');
}
}
?>
Code: Alles auswählen
<table border="0" cellpadding="0" width="100%">
<tr>
<td>{IMG}</td>
<td> <b>{NAME}</b><br />
{DESCRIPTION}<br />
{PRICE}:<big style="color:green">
{CURRENCY}{PRICE-DEC}</big><br /><br />
<input type="button" value="Add to Cart" onclick="addtocart({SERIAL})" />
</td>
</tr>
<tr><td colspan="2"><hr size="1" /></td></tr>
</table>
die SC.functions.php die dort included wird sieht wie folgt aus
Code: Alles auswählen
<?
function get_product_name($pid){
$result=mysql_query("select name from sc_products where serial=$pid");
$row=mysql_fetch_array($result);
return $row['name'];
}
function get_price($pid){
$result=mysql_query("select price from sc_products where serial=$pid");
$row=mysql_fetch_array($result);
return $row['price'];
}
function remove_product($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
unset($_SESSION['cart'][$i]);
break;
}
}
$_SESSION['cart']=array_values($_SESSION['cart']);
}
function get_order_total(){
$max=count($_SESSION['cart']);
$sum=0;
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
$sum+=$price*$q;
}
return $sum;
}
function addtocart($pid,$q){
if($pid<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($pid)) return;
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
$_SESSION['cart'][$max]['qty']=$q;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['productid']=$pid;
$_SESSION['cart'][0]['qty']=$q;
}
}
function product_exists($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
$flag=0;
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
$flag=1;
break;
}
}
return $flag;
}
?>