I need to get all email at once which are all click notify about back in stock condition. How can I get that?
2 Answers
When a customer clicks on Sign up to get notified when this product is back in stock, the customer id is saved in the product_alert_stock
table.
You can get the customer id using this model:
$model = Mage::getModel('productalert/stock');
Here is code to get a customer's email address:
$collection = Mage::getModel('productalert/stock')->getCollection();
$collection->getSelect()->join( array('customer'=> customer_entity), 'customer.entity_id = main_table.customer_id', array('customer.email'));
You need to create an event that checks if the product quantity is updated or not.
Add this code in the configuration file:
<catalog_product_save_before>
<observers>
<catalog_product_save_after_action_handler>
<type>model</type>
<class>module/observer</class>
<method>backinstock</method>
</catalog_product_save_after_action_handler>
</observers>
</catalog_product_save_before>
Create an Observer, make a backinstock function and add this code:
public function checkchange($observer)
{
$product = $observer->getProduct();
$id = $product->getId();
$oldproduct = Mage::getModel('catalog/product')->load($id);
// Get old price and quantity
$oldPrice = $oldproduct->getPrice();
$productname = $oldproduct->getName();
$url = $oldproduct->getProductUrl();
$oldQty = $oldproduct->getStockItem()->getQty();
// Get new price and quantity
$newPrice = $_POST['product']['price'];
$newQty = $_POST['product']['stock_data']['qty'];
if($oldQty == 0 && $newQty > $oldQty)
{
if($available == 1)
{
$emailTemplateVariables = array('price' => $newPrice,'name'=>$productname, 'url' =>$url);
// Appending the Custom Variables to Template.
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
$mail = Mage::getModel('core/email')
->setToName('test')
->setToEmail('[email protected]')
->setBody($processedTemplate)
->setSubject('Regarding your product back in stock')
->setFromEmail('[email protected]')
->setFromName('Store')
->setType('html');
$mail->send();
}
}
}
You can get email for your product back in stock.