Forums / Addon Payment Modules / PayPal - Passing properly all items to PayPal cart!

PayPal - Passing properly all items to PayPal cart!

Views: 9,176

Results 1 to 1 of 1
28 Mar 2019, 11:17 PM
#1
web_project avatar

web_project

New Zenner

Join Date:
Oct 2007
Location:
Stevenage, GB
Posts:
73
Plugin Contributions:
0

PayPal - Passing properly all items to PayPal cart!

As it seems to me developers never worked out properly such paypal _cart function, here just thought to share update with everyone:

Just open your paypal.php file which is located in /included/modules/payment/paypal.php

Find the following pointless code (who want the store name as items on PayPal?):

if (sizeof($optionsLineItems) > 0) {
      $optionsLineItems['cmd'] = '_cart';
//      $optionsLineItems['num_cart_items'] = sizeof($order->products);
      if (isset($optionsLineItems['shipping'])) {
        $optionsLineItems['shipping_1'] = $optionsLineItems['shipping'];
        unset($optionsLineItems['shipping']);
      }
      unset($optionsLineItems['subtotal']);
      // if line-item details couldn't be kept due to calculation mismatches or discounts etc, default to aggregate mode
      if (!isset($optionsLineItems['item_name_1']) || $optionsLineItems['creditsExist'] == TRUE) $optionsLineItems = array();
      //if ($optionsLineItems['amount'] != $this->transaction_amount) $optionsLineItems = array();
      // debug:
      //ipn_debug_email('Line Item Details (if blank, this means there was a data mismatch or credits applied, and thus bypassed): ' . "\n" . print_r($optionsLineItems, true));
      unset($optionsLineItems['creditsExist']);
    }
      
    $optionsAggregate = array(
                   'cmd' => '_cart',
                   'item_name' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_TITLE,
                  'item_number' => MODULE_PAYMENT_PAYPAL_PURCHASE_DESCRIPTION_ITEMNUM,
                   'num_cart_items' => sizeof($order->products),
                   'amount' => round($this->transaction_amount, $currencies->get_decimal_places($my_currency)),
                   'shipping' => $oshipping,
                    );

and replace it with the following:

 $optionsLineItems['cmd'] = '_cart';
      $optionsLineItems['num_cart_items'] = sizeof($order->products);
      for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
          $item = $i+1;
          $tax_value = ($order->products[$i]['tax'] / 100) * $order->products[$i]['final_price'];
          $optionsLineItems['item_name_' . $item] = $order->products[$i]['name'];
          $optionsLineItems['item_number_' . $item] = $order->products[$i]['model'];
          $optionsLineItems['quantity_' . $item] = $order->products[$i]['qty'];          
          $optionsLineItems['amount_' . $item] = number_format($order->products[$i]['final_price'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
          $optionsLineItems['tax_' . $item] = number_format($tax_value * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
      }
      $optionsLineItems['handling_cart'] = number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency)) - $shipping_added;

the upgrade is complete!

  • Freelance Software Developer