Jump to content

Newbie question - Shopping Cart


steam.roy

Recommended Posts

Hello, I would like to know; how would I code a php script that shows how many items in the shopping cart. What API functions I would have to use?

 

I would also like to be able to add other about the cart, such as:

Subtotal

Total Due Today

Empty Cart button

Checkout button

List of items and prices

 

I would be very thankful for any help on this question.

 

Thanks :)

Link to comment
Share on other sites

how would I code a php script that shows how many items in the shopping cart.

 

Something fast dirty code like that for smartytemplate:

{php}
$itemcount = count($this->get_template_vars('products')) + count($this->get_template_vars('domains')) + count($this->get_template_vars('addons'));
$this->assign('myitemcount', $itemcount);
{/php}
<table>
<tr><td>Artikel im Warenkorb:</td><td>{$myitemcount}</td></tr>
</table>

 

Of Course you can add servers and all the other producttypes.

Or recursively run through the $_SESSION['cart'] array and count all the stuff savely.

 

 

I would also like to be able to add other about the cart, such as:

Subtotal

Total Due Today

Empty Cart button

Checkout button

List of items and prices

which "other"?

Link to comment
Share on other sites

ah, you want to code a minicart.

 

the cart data is stored in $_SESSION['cart'];

read out this data in session and complete missing data with mysql querys.

 

the following is a VERY REDUCED idea for coding an whmcs minicart/shoppingbasket for global use:

if ($_SESSION['cart'])
{
// there is someth. in the shoppingcart
// mysql productquerys/(and maybe other) to an array

if ($_SESSION['cart']['products'])
{
	foreach ($_SESSION['cart']['products'] as $k)
	{
		// ... work with $k data and your mysql array ... output
	}
}
if ($_SESSION['cart']['domains'])
{
	foreach ($_SESSION['cart']['domains'] as $k)
	{
		// ... (maybe here sth.) ...output
	}
}
// the other loops for products you want to have in minibasket ...
}

 

hope you like/understand

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated