Maybe someone will find it usefull:

$write = Mage::getSingleton("core/resource")->getConnection("core_write");

$query = "insert into mytable "
       . "(field1, field2, field3, field4) values "
       . "(:field1, :field2, :field3, 12)";

$binds = array(
    'field1'   => "value 1",
    'field2' => "value 2",
    'field3'    => "value 3",
);
$write->query($query, $binds);

 

It is a bit different then method showed in previous post – this time its not transactional email sent at demand, but we will catch event fired after invoice is generated. So (I suppose you have your module already) in etc/config.xml add:

<global>	
	<events>
		<sales_order_invoice_save_after>
			<observers>
				<yourvendor_yourmodule_invoice_observer>
					<class>YourVendor_YourModule_Model_Observer</class>
					<method>sendInvoice</method>
				</yourvendor_yourmodule_invoice_observer>
			</observers>
		</sales_order_invoice_save_after>			
	</events>		
</global>

Then create your class at app/code/local/YourVendor/YourModule/Model/Observer.php (or use existing one) and add new method:

public function sendInvoice($observer) {
	try {
		/* @var $order Magento_Sales_Model_Order_Invoice */
		$invoice = $observer->getEvent()->getInvoice();
		$invoice->sendEmail();
	} catch (Mage_Core_Exception $e) {
		Mage::log("Error: " . $e->getMessage());
	}
	return $this;
}

And invoice will be attached to email defined at:

Zrzut ekranu 2015-01-14 o 19.12.17

Seems to be complex, but its not that bad:

$orderModel = Mage::getModel('sales/order')->load($myOrderId);
$invoices = $orderModel->getInvoiceCollection();
$invoicesSet = array();
foreach ($invoices as $_invoice) {
	array_push($invoicesSet, $_invoice);
}
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoicesSet);
$file = $pdf->render();

$senderName = Mage::getStoreConfig('trans_email/ident_support/name');
$senderEmail = Mage::getStoreConfig('trans_email/ident_support/email');
$sender = array('name' => $senderName, 'email' => $senderEmail);

$templateId = 'sales_email_order_template';
$emailTemplate = Mage::getModel('core/email_template')->loadByCode($templateId);
$vars = array('user_name' => 'some user name', 'product_name' => 'some product name');
$emailTemplate->getProcessedTemplate($vars);
$emailTemplate->setSenderEmail($senderEmail);
$emailTemplate->setSenderName($senderName);

$attachment = $emailTemplate->getMail()->createAttachment($file);
$attachment->type = 'application/pdf';
$attachment->filename = 'invoice.pdf';

$res = $emailTemplate->sendTransactional($templateId, $sender, 'user@example.com', "Admin", $vars);

About $vars variable – in this one you can put everything which is set inside email template as variables.

As probably you know (or maybe not) in Magento you can add your own filters to every collection, basically it looks like:

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('myfield', array('eq' => 'test'));

So here is full list of conditions you may use:

1. “eq” – equals (x = 1): addAttributeToFilter(‘status’, array(‘eq’ => 1))
2. “neq” – not equals (x != 1): addAttributeToFilter(‘sku’, array(‘neq’ => ‘test’))
3. “like” – same as in sql, you can use % here: addAttributeToFilter(‘sku’, array(‘like’ => ‘%test%’))
4. “nlike” – not like: addAttributeToFilter(‘sku’, array(‘nlike’ => ‘%test%’))
5. “in” – same as IN() used in sql, accepts array of values: addAttributeToFilter(‘id’, array(‘in’ => array(1,2,3)))
6. “nin” – not in: addAttributeToFilter(‘id’, array(‘nin’ => array(1,2,3)))
7. “null” – field should equal to null: addAttributeToFilter(‘description’, ‘null’)
8. “notnull” – field should be different then null: addAttributeToFilter(‘description’, ‘notnull’)
9. “gt” – greater then (x > 1): addAttributeToFilter(‘id’, array(‘gt’ => 1))
10. “lt” – less then (x < 1): addAttributeToFilter(‘id’, array(‘lt’ =>1))
11. “gteq” – greater or equal (x >= 1): addAttributeToFilter(‘id’, array(‘gteq’ => 1))
12. “lteq” – less or equal (x <= 1): addAttributeToFilter(‘id’, array(‘lteq’ => 1))

If you want to see executed SQL try:

echo $collection->getSelect();

 

Such error happens in 1.7.x branch (I saw it in 1.7.2), when entering database parameters you’re seeing “PHP Extensions “0” must be loaded” instead of next step. This is internal Magento bug, you can correct it by finding file app/code/core/Mage/Install/etc/config.xml  and replacing:

<extensions>
 <pdo_mysql/>
</extensions>

with:

<extensions>
 <pdo_mysql>1</pdo_mysql>
</extensions>

During configuration of Magento 1.7.0.2 (in fact whole 1.7.x branch) you may encounter such error:

Database server does not support InnoDB storage engine

Of course your MySQL server has InnoDB enabled so what to do? Answer is simple but ugly, go to app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php and replace:

public function supportEngine(){
 $variables = $this->_getConnection()->fetchPairs('SHOW VARIABLES');
 return(!isset($variables['have_innodb'])|| $variables['have_innodb']!='YES')?false:true;
 }

with

public function supportEngine(){
 $variables = $this->_getConnection()->fetchPairs('SHOW ENGINES');
 return(isset($variables['InnoDB'])&& $variables['InnoDB']!='NO');
 }

It is a common issue, you added:

$this->setUseAjax(true);

but filtering just shows ajax spinner and not loading content? Check your grid class ([COMPANY]_[MODULE]_Block_Adminhtml_[CONTROLLER]_Grid extending from Mage_Adminhtml_Block_Widget_Grid) and if you don’t have getGridUrl(), it is the reason. Just add as shown:

public function getGridUrl() {
return $this->getUrl('*/[CONTROLLER]/grid', array('_current' => true));
}

keep in mind to match ‘*/[CONTROLLER]/grid’ to your controller, it should be gridAction() method in controllers/Adminhtml/[CONTROLLER]Controller.php with such content:

public function gridAction() {
    $this->loadLayout();
    $this->getResponse()->setBody(
	    $this->getLayout()->createBlock('[COMPANY]_[MODULE]/adminhtml_[CONTROLLER]')->toHtml()
    );
}