_init('orange35_custominvoicesgenerator/order'); } public function getPaymentSumAndCount() { $paymentsTable = Mage::getResourceModel('orange35_custominvoicesgenerator/invoice')->getMainTable(); $paymentStatus = Mage_Paypal_Model_Info::PAYMENTSTATUS_COMPLETED; $this->getSelect()->columns( array( 'paid_sum' => new Zend_Db_Expr("(SELECT sum(paid) FROM " . $paymentsTable . " WHERE order_id=main_table.id AND payment_status='" . $paymentStatus . "')"), 'payments_count' => new Zend_Db_Expr("(SELECT COUNT(*) FROM " . $paymentsTable . " WHERE order_id=main_table.id AND payment_status='" . $paymentStatus . "')"), )); return $this; } }