I want to modify the information Commerce sends to PayPal so that the order description on PayPal describes the product, not the order (users on my site can only order one of two products, so I think that is more useful).

This is what I want to change: This is what I want to change

These strings are in the Commerce Website Payments Standard submodule. I am using the hook_commerce_paypal_wps_order_form_data_alter() function as suggested in the answer to this question.

However, in the API, there is no example for this function (I also looked at the Commerce Examples module but didn't find anything), and I'm a bit lost about how to handle it.

The string I want to override is defined in commerce_paypal_wps_order_form() in this section:

    // Define a single item in the cart representing the whole order
    'amount_1' => commerce_paypal_price_amount(commerce_currency_convert($amount, $order_currency_code, $currency_code), $currency_code),
    'item_name_1' => t('Order @order_number at @store', array('@order_number' => $order->order_number, '@store' => variable_get('site_name', url('<front>', array('absolute' => TRUE))))),
    'on0_1' => t('Product count'),
    'os0_1' => commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()),

I want to change item_name_1 to t('My string') and remove on0_1 and os0_1.

I tried this:

function MYMODULE_commerce_paypal_wps_order_form_data_alter(&$data, $order) {
  $data['item_name_1'] = t('My string');

But nothing is changed, even after clearing the caches. I'm having a really hard time debugging this because it is called immediately before the redirect to PayPal, so even if I use dpm() I'm not able to see it.

  • 3
    use dd() instead of dpm. – hkoosha Oct 23 '14 at 11:21
  • @loolooyyyy Thanks, actually my error turned out to result from failing to clear the caches. (Two versions of Drush, and it was reading from the wrong .drushrc. D'oh!) Since your answer is a good general tip, feel free to add and I will accept. – Patrick Kenny Oct 26 '14 at 3:16
  • I'll add this as an answer. Thanks, that's kind of you but I don't think it's worth 100 points :D – hkoosha Oct 26 '14 at 9:11

When you can not see the HTML output of debugging tools such as dpm(), you should use the utility function dd() instead. The logging data will be stored in a file called drupal_debug.txt which you can inspect later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.