I would like a php script that when specific products, which I define, have a qty of higher than 0. I automatically receive an e-mail from this.
Anyone have an idea how I can easily make a script out of this? My current script looks like this, but this will always sent a email.
I would only like to sent a email when the foreach got products.
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
ini_set('memory_limit', '4G');
require('app/Mage.php');
Mage::app();
$productIds = array(500004,540603,529536,513045);
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $productIds))->joinField('qty','cataloginventory/stock_item','qty','product_id=entity_id','{{table}}.stock_id=1','left');
$message =
"
<html>
<head></head>
<body>
<table name='contact_seller' style='border-collapse:separate';>
<thead>
<tr>
<th>Productname</th>
<th>Qty</th>
</tr>
</thead>
<tbody>";
foreach($products as $product){
if ($product->getQty() > 0){
$message .="<tr>
<td>" .$product->getSku()."</td>
<td>".round($product->getQty())."</td>
</tr>";
}
}
$message .= "</tbody>
</table>
</body>
</html>";
$to = 'test@test.com';
$subject = 'Subject';
$headers = 'From: test@test.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n".
'Content-type:text/html; charset=iso-8859-1' . "\r\n".
'Reply-To: test@test.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);