Virtuemart Repeat Order - php

The thing is that I would like to implement the following functionality to my site:
In the account settings - order details I would like to add a button that would add all the products from that very order to cart.
Now, I pretty much get it how the add to cart functionality is implemented on the flypage and browse page. I can't really get how should I pass multiple items to the add to cart function on order details page and how it'll be processed by ps_cart if an item is out of stock or is unpublished.
Here's the code of the add to cart form from browse page:
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
<?php echo $ps_product_attribute->show_quantity_box($product_id,$product_id); ?><br />
<input type="submit" class="<?php echo $button_cls ?>" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
<input type="hidden" name="category_id" value="<?php echo #$_REQUEST['category_id'] ?>" />
<input type="hidden" name="product_id" value="<?php echo $product_id ?>" />
<input type="hidden" name="prod_id[]" value="<?php echo $product_id ?>" />
<input type="hidden" name="page" value="shop.cart" />
<input type="hidden" name="func" value="cartadd" />
<input type="hidden" name="Itemid" value="<?php echo $sess->getShopItemid() ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="set_price[]" value="" />
<input type="hidden" name="adjust_price[]" value="" />
<input type="hidden" name="master_product[]" value="" />
</form>
I wonder if I'd need to pass all of these to ps_cart?
I don't expect from any of you a completely ready extension, it would be great if you could point me in the right direction.
Thanks!
EDIT:
I was able to set up the add to cart button, now I have to pass the needed data.
It would be great if it would work with at least one item, then I'd start thinking how to alter the code.
EDIT 2:
I was able to make it work flawlessly for one product. But how can I pass multiple Product Id's and their quantities to the add to cart function?

The current code in ps_cart already has a loop to iterate through multiple product IDs that are sent to the cart. From the look of the code there, I would simple put all of the product IDs you want to add to the cart in to prod_id array. You will notice that prod_id, set_price, adjust_price, and master_product are all arrays in the form. My guess is that you will need to put in those values for each product you want to add and ps_cart will do the rest.

Related

Display all cart items in Paypal checkout

I want to list all the items purchased in Paypal checkout. I have tried the following code but it does not show items there. It just show the input field in checkout. I am adding snapshot of paypal also. I am first time trying to integrate my site with Paypal.
Code
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="testaddabusiness#shop.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<?php
if(isset($_SESSION['cart'])){
foreach($_SESSION['cart'] as $id => $value){
$count=1;
?>
<input type="text" name="item_name_<?php echo $count ?>" value="<?php echo $value['name'] ?>">
<input type="text" name="item_qty_<?php echo $count ?>" value="<?php echo $value['quantity'] ?>">
<input type="text" name="amount_<?php echo $count ?>" value="<?php echo $value['price'] ?>">
<input type="text" name="color_<?php echo $count ?>" value="<?php echo $value['color'] ?>">
<input type="text" name="size_<?php echo $count ?>" value="<?php echo $value['size'] ?>">
<input type="text" name="currency_code_<?php echo $count ?>" value="USD">
<?php
$count++;
}}
?>
<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
item_name_x only applies to Cart Upload command.
You need to change cmd value to "_cart", and add another variable called upload and value of 1.
Here is an example:
cmd = _cart
upload = 1
amount_1 = 0.01
item_name_1 = Test Item
item_number_1 = 123
currency_code = USD
...
After that, your code should work.
For more information, visit HTML Variables of PayPal Payment Standard.

Passing variable values over to paypal's cart to carry out payment

I have created a basket where a customer can add to and update etc. The product itself is grabbed from the database and displayed in a table in the basket. How do I use Paypal from here? I now want a button called 'pay' that the user can click and then it takes them to Paypal to pay. But I want the details of the items to be reciprocated in the Paypal receipt.
I have signed up to paypals web standard payment. I think I just need the buy button but as mentioned, I am not sure how to get products over to Paypal. I have noticed that the steps are similar for third party carts but the code provided is this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="seller#dezignerfotos.com">
<input type="hidden" name="item_name_1" value="Item Name 1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="shipping_1" value="1.75">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="2.00">
<input type="hidden" name="shipping_2" value="2.50">
<input type="submit" value="PayPal">
But I dont see how this can relate to my cart. This shows that the cart has 2 items (item_name_1 & item_name_2) but what if the customer has 3? How am I suppose to know how many items the customer has added?
Same issue with the amount - how do I know that an item is going to cost £1.00 or £2.00?
This does not appear to by dynamic depending on what the customer selects? Can somebody explain
You just connect to your database and loop the values from your database to the form's input types.
SELECT * from customer where customer_id = $customer_id
You say that you've already created their shopping cart? I'm not sure how you've stored this, but loop through it, adding these hidden inputs for each item. If for example, your cart was in a PHP array:
$i = 0;
foreach($cart as $item) {
?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $item['name']; ?>">
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $item['cost']; ?>">
<input type="hidden" name="shipping_<?php echo $i; ?>" value="<?php echo $item['shipping']; ?>">
<?php
$i++;
}
unset($i);
Obviously you would need to rename the variables to match how you've stored the values in your cart.

Passing custom variables via paypal (IPN) gives me wrong values

I've been trying to figure this out alone. However, there is something odd going on here. I've got a hidden custom field with the e-mail of a user (just in case they use another email at paypal), but - when the IPN request is done, the custom field is strong my IP address? is there any reason for this?
Form,
<input name="description" id="description" type="hidden" value="<?php echo $paypal_product ?>" />
<input name="amount" id="amount" type="hidden" value="<?php echo $paypal_price ?>" />
<input name="product_id" id="product_id" type="hidden" value="<?php echo $paypal_product_id ?>" />
<input name="currency" id="currency" type="hidden" value="NOK" />
<input name="custom" id="custom" type="hidden" value="<?php echo $this->session->userdata('mail') ?>, <?php echo $paypal_product_id ?>" />
From a PayPal point of view there's no reason for this. It simply means $this->session->userdata('mail') doesn't contain what you expect it to. Debug, echo, debug.

Using paypal buy now form in php gallery please help

Basically I just want to turn off the button after people purchase the art and send them a receipt. I would also like to have a copy of their information. This is what I am passing through my array:
<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="email#mydomain.com" />
<input type="hidden" name="item_name" value="<?php echo $title; ?> (ID:#<?php echo " {$p['id']}" ?>)" />
<input type="hidden" name="item_number" value="<?php echo "{$p['id']}" ?>" />
<input type="hidden" name="amount" value="<?php echo "{$p['price']}" ?>" />
<input type="hidden" name="shipping" value="39.99" />
<input type="hidden" name="return" value="http://mydomain.com/thankyou.php" />
<input type="submit" value=" " class="button" />
</form>
How do I setup a sold field in my database and show/hide my button in php?
IPN, API which do I need to use to make it happen?
Cheers!
I would setup the IPN listener to mark the item's status as sold in it's database table (you are generating that form based on a database?) when the IPN comes back "VERFIFIED" and payment_status = 'Complete'. Then, only generate that form when the item is not sold.
If you don't know how to implement an IPN listener, here is a tutorial: PayPal IPN with PHP

Paypal "add to cart" without leaving page

I am trying to integrate a paypal add to cart button on my page. When added per paypal the form included seems to work fine .. but when I use ajax to serialize and submit the form it gives me a 302 error and never populates the Div.
Technically I am trying ot avoid reloading the page, or redirecting/opening a new page when someone clicks the "add to cart" button, and figured i could work around this with Ajax. Apparently a redirect kills that possiblity as the ajax call can't post or load the redirected page?
Any pointers would be apprecaited.
Here is my code:
Javascript:
$(document).ready(function(){
$(".addToCart").click(function(){
var ev = arguments[0] || window.event,
origEl = ev.target || ev.srcElement;
var cartForm = origEl.name;
var formData = $(cartForm).serialize();
$.ajax({
type: "POST",
url: "https://www.paypal.com/cgi-bin/webscr",
cache: false,
data: formData,
success: onSuccess,
error: onError
});
return false;
});
});
HTML:
<a class="addToCart" cartNumber="#paypal<?PHP echo $counter; ?>">
<img name="#paypal<?PHP echo $counter; ?>" src="images/butNowButton.jpg" cartNumber="#paypal<?PHP echo $counter; ?>" border="0" style="text-decoration:none;" />
</a>
<form name="paypal<?PHP echo $counter; ?>" id="paypal<?PHP echo $counter; ?>" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="removed for security">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="<?PHP echo $itemName; ?>">
<input type="hidden" name="item_number" value="<?PHP echo $Row['id']; ?>">
<input type="hidden" name="amount" value="<?PHP echo $amount; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="tax_rate" value="0.000">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-hopCartBF:btn_cart_LG.gif:NonHostedGuest">
</form>
thanks,
Silver Tiger
You can use the add="1" method of the Shopping Cart API to submit multiple items. All you need to do is to include the item_name, item_number and/or amount variables for each product you want to submit, like this.
<!-- item 1 -->
<input type="hidden" name="item_name_1" value="....">
<input type="hidden" name="item_number_1" value="....">
<input type="hidden" name="amount_1" value="....">
<!-- item 2 -->
<input type="hidden" name="item_name_2" value="....">
<input type="hidden" name="item_number_2" value="....">
<input type="hidden" name="amount_2" value="....">
<!-- item x -->
<input type="hidden" name="item_name_x" value="....">
<input type="hidden" name="item_number_x" value="....">
<input type="hidden" name="amount_x" value="....">
Please check HTML Variables for PayPal Payments Standard for more information regarding this API method and the variables you can use.
I have individual buttons for add to cart, and need this process to add multiple items as additionally well.
I did find that you can use a form to submit multiple items using the "upload='1'" method, but when submitted it "overwrites" the current cart items with the newlist ... which won't work as the other items i input with the single "add to cart" button will be lost.
Has anyone had any experience with this? I was hoping that paypal hd an API i could add items with .. but have been unable to find anything like that.

Categories