1

With PayPal "Transfer cart line items" set to Yes, is there a way to also transfer some of product attributes?

I've had a look at Paypal/Model/Api and Payment Details Item Type Fields, but Paypal extension's internal cart only seems to be storing only title, qty and amount.

I also tried to test with paypal_prepare_line_items event. Interestingly enough, the whole thing would crash without an error each time I try to var_dump or in any way read content of $observer->getPaypalCart() in the observer method. I haven't been able to move from there.

I was wondering if anyone's had luck adding product attributes to Paypal line items.

1

Without any real information from the 'crash' you receive from the Paypal transfer line items event we can't really provide actual support. However, this is how I would do it:

<?php

class YourCompany_YourModule_Model_Observer
{
    public function addAttributeToPaypalItem(Varien_Event_Observer $observer)
    {
        $paypalCart = $observer->getEvent()->getPaypalCart();

        if(!$paypalCart){
            return;
        } elseif(!$paypalCart->getSalesEntity() instanceof Mage_Sales_Model_Quote) {
            return;
        }

        //loop through all paypal cart items
        foreach($paypalCart->getAllItems() as $item){
            //loop through all quote items
            foreach($paypalCart->getSalesEntity()->getAllItems() as $quoteItem){
                //if we have a match of quote items and paypal items, update paypal item name
                if($quoteItem->getSku()==$item->getId()){
                    $item->setName($item->getName() . ' ' . $quoteItem->getYourAttributeCodeHere());
                }
            }
        }
    }

}

What the above does is loop through all items in the quote and all items in the paypal 'cart' and when it finds a match it changes the name of the product in the Paypal cart to append a custom attribute of your choice.

HTH. Cheers.

  • FWIW I don't like nested loops - but it's good enough for gov't work for the sake of this question. – philwinkle Jan 7 '14 at 14:21

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.