3

I have the collection for transaction and I added a line to get customer_firstname:

  protected function _prepareCollection()
    {
        $collection = ($this->getCollection())
            ? $this->getCollection() : Mage::getResourceModel('sales/order_payment_transaction_collection');
        $order = Mage::registry('current_order');
        if ($order) {
            $collection->addOrderIdFilter($order->getId());
        }
        $collection->addOrderInformation(array('increment_id'));
        $collection->addPaymentInformation(array('method'));
       $collection->joinAttribute('customer_firstname','sales_order/customer_firstname','sales_flat_order.increment_id=sales_payment_transaction.order_id', null,'inner',null);
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

here are the parameters for join attribute function:

joinAttribute(
    $alias, 
    $attribute, 
    $bind, 
    $filter = null, 
    $joinType = 'inner', 
    $storeId = null
)

so it seems I did not do anything wrong

and then when preparing columns I did this:

    protected function _prepareColumns()
    {
             $this->addColumn('customer_firstname', array(
            'header' => Mage::helper('sales')->__('First Name'),
            'index'=>'customer_firstname',
            'type'  => 'text'
        ));
}

It doesn't show me anything.how can i achieve this? I want to have the join

I don't want to go through the renderer because I know how to do it and I need to do it this way because I need to have filter in this new column

2

1 Answer 1

4

I'm noticing this.

sales_flat_order.increment_id = sales_payment_transaction.order_id

increment_id does not equate to order_id. Rather, it should like below.

sales_flat_order.entity_id = sales_payment_transaction.order_id

I typically prefer Zend methods.

$collection->getSelect()->join(
    array('s' => $collection->getTable('sales/order')),
    'main_table.order_id = s.entity_id',
    array('customer_firstname' => 's.customer_firstname')
);

You should have customer_firstname available as a column on your collection now. Give it a shot!

1
  • Glad I could help!
    – laketuna
    Jul 12, 2015 at 5:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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