--- commerce_paypal_wps.module Fri Nov 11 11:17:51 2011 +++ commerce_paypal_wps.module Tue Jan 10 21:29:16 2012 @@ -46,6 +46,7 @@ 'server' => 'sandbox', 'payment_action' => 'sale', 'ipn_logging' => 'notification', + 'paypal_cart_type' => 'send_cart', ); $form['business'] = array( @@ -95,6 +96,15 @@ ), '#default_value' => $settings['ipn_logging'], ); + $form['paypal_cart_type'] = array( + '#type' => 'select', + '#title' => t('Send full cart list to Paypal'), + '#options' => array( + 'send_cart' => t('Yes'), + 'send_overview' => t('No'), + ), + '#default_value' => $settings['paypal_cart_type'], + ); return $form; } @@ -133,6 +143,9 @@ // Specify the current payment method instance ID in the notify_url 'payment_method' => $payment_method['instance_id'], + + // Setting to send full cart list to Paypal + 'paypal_cart_type' => variable_get('paypal_cart_type'), ); return commerce_paypal_wps_order_form($form, $form_state, $order, $payment_method['settings'] + $settings); @@ -309,13 +322,28 @@ // Use the timestamp to generate a unique invoice number 'invoice' => commerce_paypal_ipn_invoice($order), - - // Define a single item in the cart representing the whole order - 'amount_1' => round(commerce_currency_amount_to_decimal($amount, $currency_code), 2), - 'item_name_1' => t('Order @order_number at @store', array('@order_number' => $order->order_number, '@store' => variable_get('site_name', url('', array('absolute' => TRUE))))), - 'on0_1' => t('Product count'), - 'os0_1' => commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()), ); + + // Append items in cart to the $data array if setting is enabled. + if ($settings['paypal_cart_type'] == 'send_cart') { + $product_count = 0; + foreach ($wrapper->commerce_line_items as $delta => $line_item_wrapper) { + if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) { + $product_count++; + $data['item_name_' . $product_count] = $line_item_wrapper->line_item_label->value(); + // Divide price by 100 to add decimal point. + $data['amount_' . $product_count] = $line_item_wrapper->commerce_unit_price->amount->value() / 100; + $data['quantity_' . $product_count] = round($line_item_wrapper->quantity->value(), 2); + } + } + } + // Define a single item in the cart representing the whole order + else { + $data['on0_1'] = t('Product count'); + $data['os0_1'] = commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()); + $data['amount_1'] = round(commerce_currency_amount_to_decimal($amount, $currency_code), 2); + $data['item_name_1'] = t('Order @order_number at @store', array('@order_number' => $order->order_number, '@store' => variable_get('site_name', url('', array('absolute' => TRUE))))); + } $form['#action'] = commerce_paypal_wps_server_url($settings['server']);