News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Send Product Name and Attributes to Paypal

Started by kontrolfreek, December 20, 2008, 08:12:49 AM

Previous topic - Next topic

cinos

Hi AJ

Yeah. It's so that I can modify all the products in one go. For instance when VAT goes back up to 17.5% I can just change the 15% tax rate to 17.5% and all the prices will update themselves.

I am however not allowed to charge tax, which means to say that my prices can be the same as if they had tax on them, but I cannot show any tax in my invoices, products and checkout.

So ideally it would be grand if say someone bought a product for £9.99, it then went through to Paypal and the price of the product still remained at £9.99 with no mention of tax whatsoever.

Is this possible?

It would be great if you also managed to find a cause behind the homepage redirect, as that one has me completely stumped. :? Not to mention the fact that the notify.php (automated status update from Paypal) doesn't work with this new code. I've trawled through the code that you have written and I can't find a suitable cause for either. :/

If you can help I would be very grateful. :)

parrahouse

#16
Hello all --

okay, the last script that ajredding posted came closer than anything I've tried yet at passing everything necessary to paypal --all the cart details are coming through fine

Except a shipping address.  Or more accurately the address is kinda-sorta getting passed.  If I click to pay with a credit card (instead of logging in) the bill-to address is populating the cc form:


Click for full size

But if I login to paypal no address is displayed --just an email.  This results in an order with no shipping address -- denying seller protection to the purchase and making label printing a pain:


Click for full size

What's going on?  I've heard that paypal will ignore addresses that are missing or otherwise imperfect. Where should I start troubleshooting this?

Any help appreciated.

Big thanks to ajredding for the great work.

PS -- my shop is configured for NO REGISTRATION. Does this have anything to do with the problems passing shipping info?

ajredding

Quote from: cinos on March 30, 2009, 16:47:39 PM
Hi AJ

Yeah. It's so that I can modify all the products in one go. For instance when VAT goes back up to 17.5% I can just change the 15% tax rate to 17.5% and all the prices will update themselves.

I am however not allowed to charge tax, which means to say that my prices can be the same as if they had tax on them, but I cannot show any tax in my invoices, products and checkout.

So ideally it would be grand if say someone bought a product for £9.99, it then went through to Paypal and the price of the product still remained at £9.99 with no mention of tax whatsoever.

Is this possible?


Ok lets try this post again...

Couple of quick questions...

  • Are you setting the "tax mode" to "based on vendor address"?
  • did you modify your checkout pages to hide the tax from those pages also?  They just show how much tax is added to the final price of the products
  • are you concerned about coupons/discounts being applied correctly? (that way I know how to test this code)
  • Is this the only payment processor you are using?

But quickly looking at how a few things are stored in the DB, it looks like this can be done but it's going to require editing the paypal config file also to add a variable in there to toggle this ability on and off. 

I'll rough something together and give it a few test runs.
RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com

cinos

In answer to your questions:


  • Tax mode is set to vendor address.
  • I have modified the checkout pages so that the tax doesn't show there (simply removed the part that called it to display).
  • I would like coupons/discount to still work.
  • This is the only payment processor I am using. :)

Thankyou so much for your help with this. It means alot.  :D

ajredding

#19
Ok I've got it worked out, but instead of posting all the code changes I'm going to post a zipped file that you can just extract to your site root.  The files are in the correct path for the site. 

AS A WARNING: I would suggest backing up your site before uploading these just in case! 

What I did is added an option in the paypal config to allow for this to be turned off and on.  So once you have uploaded the code you will need to open the payment method and click over the configuration and change the new option to "yes"

Below is the new "Payment Extra Info" code to take advantage of the new option.

<?php
$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);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

$url "https://www.paypal.com/cgi-bin/webscr";
if(
PAYPAL_CHARGE_TAX == 1) {
$tax_total '0.00';

else {
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
}


$discount_total $db->f("coupon_discount") + $db->f("order_discount");&#160; //New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
if($discount_totalCP 0) {
$disc_perItem round($discount_totalCP $t_quantity2);
}
else {
$disc_perItem 0;
}
}
else {
$disc_perItem 0;
}

while(
$dboi->next_record()) {

&
#160; &#160; $prod_attrib = $dboi->f("product_attribute");
&#160; &#160; &#160; &#160; &#160; &#160; &#160; 
&#160; &#160; $supp_var['item_name_' . $i] = strip_tags($dboi->f("order_item_name"));

&#160; &#160; if($prod_attrib > ''){
&#160; &#160; &#160; $attributes_array = explode('<br/>',$prod_attrib);
&#160; &#160; &#160; $v = 0;
&#160; &#160; &#160; $z = 1;
&#160; &#160; &#160; foreach ( $attributes_array as $attributes_value){
&#160; &#160; &#160; &#160; $attrib_name = trim(substr($attributes_value, 0, strpos($attributes_value, ':')), " ");
&#160; &#160; &#160; &#160; $supp_var['on' . $z . '_' . $i] = $attrib_name;
&#160; &#160; &#160; &#160; $attrib_sel = trim(substr_replace(substr_replace($attributes_value, "", 0, strrpos($attributes_value, ': ')), "", 0, 2));
&#160; &#160; &#160; &#160; $supp_var['os' . $z . '_' . $i] = $attrib_sel;
&#160; &#160; &#160; &#160; $v++;
&#160; &#160; &#160; &#160; $z++;
&#160; &#160; &#160; &#160; unset($attributes_value);
&#160; &#160; &#160; }
&#160; &#160; }
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
&
#160; &#160; $supp_var['quantity_' . $i] = $dboi->f("product_quantity");
if(PAYPAL_CHARGE_TAX == 1) {
$supp_var['amount_' $i] = round(($dboi->f("product_final_price") - $disc_perItem),2);

else {
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
}
&
#160; &#160; $i++;
}
//End New Code

//Start New Code - Ship to Address Versus Bill To Address

$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
&
#160; $first_name = $dbb->f("first_name");
&#160; $last_name = $dbb->f("last_name");
&#160; $address1 = $dbb->f("address_1");
&#160; $address2 = $dbb->f("address_2");
&#160; $city = $dbb->f("city");
&#160; $state = $dbb->f("state");
&#160; $address_country = $dbbt->f("country");
&#160; $zip = $dbb->f("zip");
&#160; $H_PhoneNumber = $dbb->f("phone_1");
}
else
{
&
#160; $first_name = $dboui->f("first_name");
&#160; $last_name = $dboui->f("last_name");
&#160; $address1 = $dboui->f("address_1");
&#160; $address2 = $dboui->f("address_2");
&#160; $city = $dboui->f("city");
&#160; $state = $dboui->f("state");
&#160; $address_country = $dboui->f("country");
&#160; $zip = $dboui->f("zip");
&#160; $H_PhoneNumber = $dboui->f("phone_1");
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$db->f("order_tax")-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"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",
"no_shipping" => "1",
"no_note" => "1",
//"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip
);

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) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';

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 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
echo 
'</form>';
}
?>


On the "administration / configuration" board I posted a topic about implementing a change like this at the cart level. 

Ok so the attachments isn't working on the board right now so I've posted them right in the post.

Configuration Option


If the option is set to "NO"


If the option is set to "YES"


If the option is set to "YES" and a Discount/Coupon is applied

Hope this is what you are looking for.

Oh Yeah one last note the Original price of the product is 6.95 and the "tax" is 8.25% which totals $7.52.

Crap forgot to link to the files since the attachments isn't working.
http://www.rawmediagroup.com/download/VirtueMart/Tax-Hack.zip

One Last Edit here @parrahouse  I found that in one of the SQL statements it was declaring a table instead of using the "prefix" variable.  I've been doing this on my dev server and I didn't use the standard Joomla table prefix so that's how I discovered this mistake.

If you don't want to implement all of the changes above here is what you need to do

BAD CODE SECTION

$dbb = new ps_DB;
$q = "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();


Should Read

$dbb = new ps_DB;
$q = "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();


It's near the top.
RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com

ads4it

#20
hey

thx you for aj.

i just fixed little bit of your code.
so in paypal, it can obtain address, phone#, email.

here it is.

always backup ur original file before do something.

<?php
$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);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

$dbb = new ps_DB;
$q "SELECT * FROM jos_vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

$url "https://www.paypal.com/cgi-bin/webscr";
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  //New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
if($discount_totalCP 0)
{
$disc_perItem round($discount_totalCP $t_quantity2);
}
else
{
$disc_perItem 0;
}
}
else
{
$disc_perItem 0;
}

while(
$dboi->next_record()) {

    
$prod_attrib $dboi->f("product_attribute");
              
    
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name"));
    if(
$prod_attrib ''){
      
$attributes_array explode('<br/>',$prod_attrib);
      
$v 0;
      
$z 1;
      foreach ( 
$attributes_array as $attributes_value){
        
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
        
$supp_var['on' $z '_' $i] = $attrib_name;
        
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value': ')), ""02));
        
$supp_var['os' $z '_' $i] = $attrib_sel;
        
$v++;
        
$z++;
        unset(
$attributes_value);
      }
    }
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
    
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
    
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
    
$i++;
}
//End New Code

//Start New Code - Ship to Address Versus Bill To Address

$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$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");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else
{
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"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",
"no_shipping" => "1",
"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $dbbt->f('first_name'),
"last_name" => $dbbt->f('last_name'),
"address1" => $dbbt->f('address_1'),
"address2" => $dbbt->f('address_2'),
"zip" => $dbbt->f('zip'),
"city" => $dbbt->f('city'),
"state" => $dbbt->f('state'),
"address_country" => $address_country,
"night_phone_b" => $dbbt->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) ."&";
}
}

vmRedirect$url $query_string );
} else {
echo 
'<form action="'.$url.'" method="post" target="_blank">';

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 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
echo 
'</form>';
}
?>

ajredding

#21
Thanks for pointing that out.

I was working on a different problem for another user and had commented the email line out and well I just totally missed putting the phone line in there.

I've updated my code so that any build from here on out will have that in there.

Ok acutally I went through and did some formatting and found a few other things that needed to be corrected.

So here is an official posting of the latest known working code.


<?php
$url 
"https://www.paypal.com/cgi-bin/webscr";
$order_id $db->f("order_id");
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  

// Query for Order Items
$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);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

// Query to get User Info
$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
  
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
  if(
$discount_totalCP 0) {
    
$disc_perItem round($discount_totalCP $t_quantity2);
  }
  else {
    
$disc_perItem 0;
  }
}
else {
  
$disc_perItem 0;
}

while(
$dboi->next_record()) {

  
$prod_attrib $dboi->f("product_attribute");
  
$supp_var['item_name_' $i] = strip_tags($dboi->f("order_item_name"));
  
  if(
$prod_attrib ''){
    
$attributes_array explode('<br/>',$prod_attrib);
    
$v 0;
    
$z 1;
    foreach ( 
$attributes_array as $attributes_value){
      
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
      
$supp_var['on' $z '_' $i] = $attrib_name;
      
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value':')), ""02));
      
$supp_var['os' $z '_' $i] = $attrib_sel;
      
$v++;
      
$z++;
      unset(
$attributes_value);
    }
  }

  
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
  
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
  
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
  
$i++;
}
//End New Code


//Start New Code - Ship to Address Versus Bill To Address

//Query used to compare Bill to versus Shipp to address
$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$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");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else {
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

// Builds array for the form
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"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",
"no_shipping" => "1",
"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip,
"night_phone_b" => $H_PhoneNumber
);

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) ."&";
    }
  }

  
vmRedirect$url $query_string );

else {
  echo 
'<form action="'.$url.'" method="post" target="_blank">';

  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 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
  echo 
'</form>';
}
?>

RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com

ads4it

AJ last code was really clean and smooth.

this is little add for aj's last code.

i just added little string

so in paypal you can get oder number, product name.

if you don't like order number's to display don't get this one.

and thx to aj for this hack.

and please respect coders!

always backup your original.

<?php
$url 
"https://www.paypal.com/cgi-bin/webscr";
$order_id $db->f("order_id");
$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");  

// Query for Order Items
$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);

$row_num $dboi->num_rows();

//New code Getting Cart Items
$auth $_SESSION['auth'];
$cart $_SESSION['cart'];
$t_quantity 0;
$disc_perItem 0;
$i=1;

// Query to get User Info
$dbb = new ps_DB;
$q "SELECT * FROM #__vm_user_info ";
$q .= "WHERE user_id ='".$my->id."' ";
$dbb->setQuery($q);
$dbb->query();

//New Code
$discount_totalCP $db->f("coupon_discount") + $db->f("order_discount");

while(
$dboi->next_record()) {
  
$t_quantity $t_quantity intval($dboi->f("product_quantity"));
}

$dboi null;
$dboi = new ps_DB;
$dboi->query($q_oi);

if(
$t_quantity 0)
{
  if(
$discount_totalCP 0) {
    
$disc_perItem round($discount_totalCP $t_quantity2);
  }
  else {
    
$disc_perItem 0;
  }
}
else {
  
$disc_perItem 0;
}

while(
$dboi->next_record()) {

  
$prod_attrib $dboi->f("product_attribute");
  
$supp_var['item_name_' $i] = strip_tags("Order #"$db->f("order_id").": "$dboi->f("order_item_name"));
  
  if(
$prod_attrib ''){
    
$attributes_array explode('<br/>',$prod_attrib);
    
$v 0;
    
$z 1;
    foreach ( 
$attributes_array as $attributes_value){
      
$attrib_name trim(substr($attributes_value0strpos($attributes_value':')), " ");
      
$supp_var['on' $z '_' $i] = $attrib_name;
      
$attrib_sel trim(substr_replace(substr_replace($attributes_value""0strrpos($attributes_value':')), ""02));
      
$supp_var['os' $z '_' $i] = $attrib_sel;
      
$v++;
      
$z++;
      unset(
$attributes_value);
    }
  }

  
$supp_var['item_number_' $i] = $dboi->f("order_item_sku");
  
$supp_var['quantity_' $i] = $dboi->f("product_quantity");
  
$supp_var['amount_' $i] = round(($dboi->f("product_item_price") - $disc_perItem),2);
  
$i++;
}
//End New Code


//Start New Code - Ship to Address Versus Bill To Address

//Query used to compare Bill to versus Shipp to address
$dboui = new ps_DB;
$q_oui "SELECT * FROM #__vm_order_user_info ";
$q_oui .= "WHERE #__vm_order_user_info.order_id='$order_id' ORDER BY #__vm_order_user_info.order_info_id DESC";
$dboui->query($q_oui);

$oui_id $dboui->f("order_info_id");

if(
$oui_id == $order_id){
  
$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");
  
$address_country $dbbt->f("country");
  
$zip $dbb->f("zip");
  
$H_PhoneNumber $dbb->f("phone_1");
}
else {
  
$first_name $dboui->f("first_name");
  
$last_name $dboui->f("last_name");
  
$address1 $dboui->f("address_1");
  
$address2 $dboui->f("address_2");
  
$city $dboui->f("city");
  
$state $dboui->f("state");
  
$address_country $dboui->f("country");
  
$zip $dboui->f("zip");
  
$H_PhoneNumber $dboui->f("phone_1");
}
//End New Code

// Builds array for the form
$post_variables = Array(
"cmd" => "_cart",
"upload" => "1",
"page_style" => "paypal",
"business" => PAYPAL_EMAIL,
"currency_code" => $_SESSION['vendor_currency'],
"amount" => round$db->f("order_subtotal")+$tax_total-$discount_total2),
"handling_cart" => sprintf("%.2f"$db->f("order_shipping")),
"tax" => $tax_total,
"tax_cart" => $tax_total,
"invoice" => $db->f("order_id"),
"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",
"no_shipping" => "1",
"no_note" => "1",
"email" => $dbb->f("user_email"),
"address_override" => "1",
"first_name" => $first_name,
"last_name" => $last_name,
"address1" => $address1,
"address2" => $address2,
"city" => $city,
"state" => $state,
"address_country" => $address_country,
"zip" => $zip,
"night_phone_b" => $H_PhoneNumber
);

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) ."&";
    }
  }

  
vmRedirect$url $query_string );

else {
  echo 
'<form action="'.$url.'" method="post" target="_blank">';

  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 
'<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" alt="Make payments with PayPal, it is fast, free, and secure!">';
  echo 
'</form>';
}
?>

cinos

Wow Aj, thankyou so much!

I will test this tonight and let you know how it goes. :)

Thanks again, I really appreciate the effort you went through to help me out. You are the best.

cinos


mackavi

Cheers for this.  But one small problem, the return now goes to index page of the site instead of normal purchase message.  All I did was replace the original code with the PHP above - did I miss something :-?
J1.5 VM 1.13 PHP 5.29

ajredding

I noticed that on the sandbox site but I haven't tested it on a client's live site 100% yet.  So I'm not sure if there is something different between the two.

But here is what I noticed.

When I have ran through a complete order on the sandbox site and you are ready to click on the link to return to your site from paypal the URL string listed has the HTML CODED "&" (&amp;) injected to the URL string.  This is causing problems with virtuemart. 

Like I said I'm not sure if it's just the sandbox site doing this or if it's also a problem on paypal's live site also.

If any of you have all this code and changes implemented on your live site and can run through a sale all the way.  Could you post the URL that gets returned to your browser when you click on the "Return to Merchant" button.

RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com

afink

Nice work AJ. Thanks so much. Everything seems to be working fine when the user logs onto their PayPal account.

However, I am seeing a similar symptom that was posted by parrahouse on April 7th.

If the user decides to pay with a credit card without logging onto a PayPal account, the credit card screen is getting populated with the "alternate shipping address" information (instead of the billing address).

ajredding

There is a slight trade off with this whole thing.

I think this was discussed on another topic but basically what it boils down to is paypal doesn't allow you to send both a billing and ship to address when processing an order. 

So what the code ("Payment Extra Info") is designed to do is send the "ship to" address to paypal.  Once you are at paypal and the user doesn't login to paypal and uses a CC the Billing info has the ship to, but if they just change it to the correct billing info then (if I remember correctly) once they move on to the confirm page it will show the ship to as what was entered as the ship to on VirtueMart. (did that make sense?)

The payment extra info code is looking to see if there is a ship to address entered if so it sends that.  If not it'll send the billing info.

Like I said last time I checked what I have stated above worked.  Programming late at night after working a full time job is sometimes rough and you don't remember everything.
RAW Media Group - Website design - http://www.rawmediagroup.com
Cubed Hosting - Website Hosting - http://www.cubedhosting.com

afink

Got it. That makes perfect sense.

Too bad PayPal doesn't allow for passing both a billing and a shipping address.

Thanks again for your good work (and late night coding).