0

I’m trying to join a custom table with order_grid_collection to add new column in admin sales order grid page, its working but the collection loads so slow. how can I join this table correctly to avoid the slow loading Thanks!

  protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->joinLeft('custompayment_nestpay', 'main_table.increment_id = custompayment_nestpay.paymentID', 'card_name');
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
    protected function _prepareColumns()
    {
         $this->addColumn('card_name', array(
             'header' => Mage::helper('sales')->__('Card Name'),
             'index' => 'card_name'
         ));
….
1

In your function the join is fine

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->joinLeft('custompayment_nestpay', 'main_table.increment_id = custompayment_nestpay.paymentID', 'card_name');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

You have used order increment id to join nestpay payment table, and this is the reason behind slow collection loading. If you can convert your query with entity_id then your collection will load more quickly

increment_id is key but not the primary key, and if you observe the table, it's data type is varchar, if you can populate order entity_id in your payment table, then you would be able to join using entity_id

4
  • I used increment_id because in nestpay table I have a column called paymentID which is equal to order increment_id. how can I populate entity_id in nestpay table ?
    – Anass Hl
    Sep 7 '20 at 8:42
  • In most of the payment method, there is a form that submits on payment portal, and after return back to magento payment portal return back all the given variables, you can append entity_id in that form and use it when parameters return back from payment portal Sep 7 '20 at 10:23
  • Thank you so much Shoaib for your help, I solved it by indexing paymentID column in my custom payement table.
    – Anass Hl
    Sep 9 '20 at 7:46
  • Great. Good to hear that you resolved your issue Sep 9 '20 at 13:19
1

I solved the slow loading by indexing paymentID column in my custom payement table.

1

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.