News:

Support the VirtueMart project and become a member

Main Menu

how to have cart items fully displayed in paypal with details

Started by Axel, October 26, 2006, 16:54:43 PM

Previous topic - Next topic

Axel

Here's the code I use i n order to have all items listed in the cart. It allows to have a fully described cart on many lines, and no more only one line with the total amount.

tax & tax_cart are both defined. I think only tax_cart is enough, I didn't take time to check that.
Off course, adapt the code to fit your needs!

I think it would be great if this code would be insert in a wiki or examples, or doc.


<?php
//"item_name" => $VM_LANG->_PHPSHOP_ORDER_PRINT_PO_NUMBER.": ". $db->f("order_id")
$order_id $db->f("order_id");
$dboi = new ps_DB;
$q_oi "SELECT * FROM #__vm_order_item ";
$q_oi .= "WHERE #__vm_order_item.order_id='$order_id'";
$dboi->query($q_oi);
$description "Inscriptions";
$row_num $dboi->num_rows();
$i=1;
while(
$dboi->next_record()) {
    
    
$supp_var['item_name_' $i] = $dboi->f("order_item_name");
    
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
    
$supp_var['amount_' $i] = round($dboi->f("product_item_price"),2);
    
$i++;
}


$dbb = new ps_DB;
$q "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();
/*
"cmd" => "_ext-enter",
"redirect_cmd" => "_xclick",

*/

$url "https://www.sandbox.paypal.com/cgi-bin/webscr";
$tax_total round($db->f("order_tax") + $db->f("order_shipping_tax"),2);
$discount_total $db->f("coupon_discount") + $db->f("order_discount");
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"business" => PAYPAL_EMAIL,
"item_name" => $description,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"receiver_email" => PAYPAL_EMAIL,
"order_id" => $db->f("order_id"),
"invoice" => $db->f("order_number"),
"shipping" => sprintf("%.2f"$db->f("order_shipping")),
"image_url" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"undefined_quantity" => "0",
"test_ipn" => PAYPAL_DEBUG,
"pal" => "NRUBJXESJTY24",
"no_shipping" => "1",
"no_note" => "0",

"email" => $dbb->f("user_email"),
"first_name" => $dbb->f("first_name"),
"last_name" => $dbb->f("last_name"),
"address1" => $dbb->f("address_1"),
"address2" => $dbb->f("address_2"),
"city" => $dbb->f("city"),
"state" => $dbb->f("state"),
"zip" => $dbb->f("zip"),
"H_PhoneNumber" => $dbb->f("phone_1")
);
if( 
$page == "checkout.thankyou" ) {
$query_string "?";

foreach( 
$post_variables as $name => $value ) {
$query_string .= $name"=" urlencode($value) ."&";
}
if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
$query_string .= $name"=" urlencode($value) ."&";
}
}


mosRedirect$url $query_string );
} else {

echo 
'<form action="'.$url.'" method="post" target="_blank">';
echo 
'<input type="image" name="submit" src="http://images.paypal.com/images/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';


foreach( 
$post_variables as $name => $value ) {
echo 
'<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}

if(
is_array($supp_var) && count($supp_var)) {
foreach($supp_var as $name => $value) {
echo '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
}
}

echo 
'</form>';

}
?>



Feel free to make any suggestions!
Axel

nzeone


MyMusicVid

nzeone

Go to Components/Virtuemart

Then Store/List Payment Methods. Click on Paypal, then on the configuration tab. Copy and paste the code above into that configuration screen. Save and that'll do it.

Note that the code above is set up to use the Paypal sandbox.


Grady

Hey Axel,

First of all, let me say what you did here was awesome.

I have noticed a small problem, though.  Now my customized header/logo for PayPal doesn't appear.  I noticed it seems to have *something* to do with you using "cmd" => "_cart" instead of "cmd" => "_xclick"

I would be very happy if I could use your modification to show detailed items in PayPal and have my customized PayPal header/logo continue to show.

Any ideas?

Grady

Michael

Axel,

Awesome Script really Appreciate it I too have the Question about the _xclick?

Thansk Again

Eliyahna

Axl,

I tried this and it didn't work for me. Paypal came with an error saying missing information. I would be glad to pay you if you would consider helping me fix my cart?

http://www.torahwomen.com
eliyahna@torahwomen.com

Stephen Giguere

Hey Eliyahna,

In the example above Axel put

<pre>
$q = "SELECT * FROM jos_vm_user_info ";
</pre>

That's kind of slack.  He's assuming we all use the default 'jos' database prefix.  He should have stuck to the standard and used the line


<pre>
$q = "SELECT * FROM #__vm_user_info ";
</pre>

to keep it independent of the database being used.  You'll see the syntax used at the top for the original database query.  Stuff like this is annoying because it's just sloppy stuff that ends up costing people time.  If you're going to post stuff on the forum please make sure you don't cripple an otherwise excellent solution like this with hardcoded stuff like that. 

All that said...that code should be put in a glass case under armed guard if not made part of the standard VM release.  Great work.

salbini

I've changed the address from "https://www.sandbox.paypal.com/cgi-bin/webscr  to "https://www.paypal.com/cgi-bin/webscr and everything works great, logo included and everything else.

thanks, great suggestion