Ok.. long story short...
I would like to send the contents of the shopping cart to another page where i can grab the info then display it so it may be mailed as a form to the owners email address..
what I am trying to accomplish is.. instead of using a payment gateway to finallize the transaction, the owner of the site I am working on just wants the items that a customer orders to be sent to his email address along with some other pieces of info...
so here we go..
right now I am working inside of ViewCart.tpl.
as a test... at the bottom of the file.. i did the following to attempt to send the loaded array $ViewCart[items] to the target page using a form action POST
<form action="http://www.carmelsilver.com/docs/orderform.php" method="post">
<input type="hidden" name="cart" value="{$ViewCart.items}">
<input type="submit" value="Order These Items"/>
</form>
then on the target orderform.php page.. I have this...
<?php
$contents = $_POST[cart];
$many = count($contents);
echo $many;
?>
what is displaying in the browser is 1. I am using the php count() function to see what I have in the array that I shipped from viewcart.tpl to orderform.php as a test
will this method even work? Can I pass variables from a template to an external php page using this method? It seems to me that the var $ViewCart[items] is loaded with all the items that the cart has.. and in the orderform.php file I was going to use that array to fill the orderform with the sent info from viewcart.tpl and then add some other stuff before finally sending it on to the owners email account using phpmail.
what am i doing wrong?
Posts: 7994
{$ViewCart.items} is an array of items and you can't blindly put that into a form field. It'll probably just get sent over as the string "Array", which does you no good. Instead, you should iterate over the items and create an input for each, eg:
This will give you the following result:
I don't know exactly what information you really need. The id is good enough if you're writing code to use G2's api. Otherwise, if you need more information we can show you how to get at it.
This is an easy solution, but it's not durable. When you upgrade G2, it'll break. If you really want to make a good permanent solution, you should code a new module that uses the CartPlugin API so that it can interact with the cart module. Take a look at the ZipCart module to get an idea of how to do that.
Posts: 35
thanks very much bharat... that works perfectly.. I was having trouble to trying to understand how to do this.. and you were right.. it was just printing a string "Array" ...
now that I am having good luck doing this.. I am trying to construct a path to the image on the harddrive so i can get the thumbs to print in the browser along with the other info.... I can see in the array there is a item called "pathComponent" which holds the image name of the photo.. but how can i go about getting the rest of the path? by looking in the database.. in the G2_Item row.. I cannot really see where i may find anything to help me there.. I guess i could write a seperate query in my orderform.php file and use the id that was POSTED to get the other info.. would this be the way to go about it?, or could i send that info along with the form from ViewCart.tpl?
you guys are just plain awesome.... hands down....
Posts: 35
ok.. this works great..
all the info I need is passed along to the next page.. then I loop through the array and do this..
thanks so much bharat... you da man....