Jump to content

problems with shopping cart....Help..


sandbudd

Recommended Posts

This is my display page and it works great.  I have tried several ways to use a shopping cart with this information and just can seem to get it to work.  If anyone could help talk me through this it would be great.

 


<?php
require_once('library/init.php');

$page['products'] = $catalog->getCategories();

$pID = $core->pageVar('id', siteCore::VARTYPE_INT);
$pdctInfo = $catalog->getProductInfo(array($pID));

$page['content'] = "<h2><a href=\"category.php?catID=" . $pdctInfo[$pID]['category']['id'] . "\">" . $pdctInfo[$pID]['category']['name'] . "</a> > <a href=\"subcategory.php?sCatID=" . $pdctInfo[$pID]['subcategory']['id'] . "\">". $pdctInfo[$pID]['subcategory']['name'] . "</a> > " . $pdctInfo[$pID]['name'];
$page['content'] .= "</h2>\n<img src=\"Images/Product Images/" . $pdctInfo[$pID]['picture'] . "\" />";

$page['content'] .= "<product>" . $pdctInfo[$pID]['name'] . "<br>";
if($pdctInfo[$pID]['weight'] !== NULL) $page['content'] .= " " . $pdctInfo[$pID]['weight'] . " " . $pdctInfo[$pID]['unit'] . "<br>";
$page['content'] .= "$" . $pdctInfo[$pID]['price'] . "</product>";
//$page['content'] .= "<a href=\
print_page();
?>

Link to comment
https://forums.phpfreaks.com/topic/130212-problems-with-shopping-carthelp/
Share on other sites

I changed to this

 


<?php
require_once('library/init.php');

$page['products'] = $catalog->getCategories();
$scInfo = $catalog->getSubCategoryInfo($core->pageVar('sCatID', siteCore::VARTYPE_INT));

$page['content'] = "<h2><a href=\"category.php?catID=" . $scInfo['category']['id'] . "\">" .
					$scInfo['category']['name'] . "</a> > " . $scInfo['name'] .
					"</h2>\n<div class=\"mainContent\">\n";
$lastProdID = 0;
$lastWeight = 0;
$lastBrand = 0;
$first = 0;
$last = 0;
if(count($scInfo['products']))
{
	$page['content'] .= "<ul>\n";
	foreach($scInfo['products'] as $productID => $productInfo)
	{
		if(($lastProdID!=$productInfo['ProductIDtwo'] || $lastWeight!=$productInfo['weight']) && $last == 1)
		{
			$page['content'] .= "</table>";
			$last = 0;
		}
		if($lastBrand!=$productInfo['brandID'])
		{
			if($first != 1)
			{
				$page['content'] .= "</table>";
			}
			$first = 2;
			$lastBrand = $productInfo['brandID'];
			$page['content'] .= "<h3><a href=\"brand.php?bID=$lastBrand\">" . $productInfo['brand'] . "</a></h3>";
			$page['content'] .= "<table border=\"0\">";
		}

		if($lastProdID!=$productInfo['ProductIDtwo'] || $lastWeight!=$productInfo['weight'])
		{
			$page['content'] .= "<tr><td>";
			//Delete this & update dB
			if($productInfo['productPic'] == NULL) $productInfo['productPic'] = 'No Image.gif';
			$page['content'] .= "<img src=\"Images/Product Images/" . $productInfo['productPic'] .  "\" />";
			$page['content'] .= "</td><td>";
			$page['content'] .= "<name>" . $productInfo['name'] . "</name><br></a>";
			if($productInfo['numUnits'] !== NULL) $page['content'] .= $productInfo['numUnits'] . "/";
			$page['content'] .= $productInfo['weight'];
			$page['content'] .= " " . $productInfo['unit'] . "<br>";
			$page['content'] .= "$" . $productInfo['price'] . "\n";
			$lastProdID = $productInfo['ProductIDtwo'];
			$lastWeight = $productInfo['weight'];
			if($productInfo['flavor'] == NULL)
			{
				$page['content'] .= "<h8><a href=\"addtocart.php?id=$productID\">" . "  [Order]" . "<br></a></h8>";
			} else {
				$page['content'] .= "<table cellpadding=\"0\" cellspacing=\"0\"><td>";
				$page['content'] .= $productInfo['flavor'] . "&nbsp&nbsp</td>";
				$page['content'] .= "<td><h8><a href=\"addtocart.php?id=$productID\">" . "  [Order]" . "<br></a></h8></td></tr>";
				$last = 1;
			}
		} else {
			$page['content'] .= "<tr><td>";
			$page['content'] .= $productInfo['flavor'] . "&nbsp&nbsp</td>";
			$page['content'] .= "<td><h8><a href=\"addtocart.php?id=$productID\">" . "  [Order]" . "<br></a></h8></td></tr>";
			$last = 1;
		}
	}
}
$page['content'] .= "</td></tr></table></table>";
$page['content'] .= "</div>";

print_page();
?>

 

Here is the addtocart.php and it does not forward to showcart.php all I get is a blank page no errors?

 

<?php
error_reporting(E_ALL);

session_start();

/**
* First things first, get the product id that is to be added.
*/
if (isset($_GET['productID']))
{
  /**
   * By forcing this into int format, we avoid SQL Injection.
   */
  $productID = intval($_GET['product']);
}
else
{
  throw new IllegalProductIDException();
}

/**
* Next, have the CartManager go and add an entry for this pid
* in the shopping cart.  It is smart enough to know to
* see if there is an existing entry in the cart and simply
* increment the number of items desired when it exists.
*
* This method throws if it is not given a valid product id.
*/
$cm = CartManager::getInstance();
$cm->addProductToUserCart($pID);

/**
* Great.  Now redirect them to the page to show them the
* contents of their cart.
*/
} else {
//send them somewhere else
header('Location: showcart.php');
exit;
}



?>


Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.