Top 5 Programming Questions and Answers Regarding Magento Out of Stock Notification Emails - Part 1

March 6, 2017,
Top 5 Programming Questions and Answers Regarding Magento Out of Stock Notification Emails - Part 1
In eCommerce, sending stock alert emails to your customers is an effective and powerful marketing strategy. It helps you to manage a better relationship with your customers in a productive way. Sending stock notification emails to customers once the product is back in the stock, helps the business owners sell more products. This functionality on your e-store allows you to engage existing customers with your store and take more successful business leads from them. Looking on its importance, Magento out of stock notification is a must have tool for any e-business. Our Magento developers answer tons of queries regarding different angels of coding including out of stock notification on regular basis. From this huge number of useful questions, we have collected some of the most frequently asked questions which are answered by the top community developers. We have taken these questions and answers from the top expert's community hence it not represents us. Hope this small effort from our side will help you to resolve your issues regarding Magento out of stock notification. Question No. 1 Out of Stock Notification is not working in Magento 1.8.1 User is getting error in notification email in the form given below
Hello Admin.'
Customer'
.wants to be notified when the below product is available in our inventory<br/><p>Item Name :</p>

SKU :p><p> Search Code :</p>

Bar Code :p>

And nothing showed beside this, but when the user checks in \app\code\local\Adodis\Pincodecheck\controllers it shows:
    $to = "sales@abcd.com";
     $subject = "Product in demand";
    $txt = "Hello Admin.'
Customer'."
.$pincode."wants to be notified when the below product is available in our inventory

Item Name :".$name."

SKU :".$sku."

Search Code :".$scode."

Bar Code :".$bcode."

"
; mail($to,$subject,$txt);
Where does need fix to get a proper email? You can resolve the issue by adding these headers and pass it.
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$to = "sales@abcd.com";
     $subject = "Product in demand";
    $txt = "Hello Admin.'
Customer'."
.$pincode."wants to be notified when the below product is available in our inventory

Item Name :".$name."

SKU :".$sku."

Search Code :".$scode."

Bar Code :".$bcode."

"
; mail($to,$subject,$txt, $headers);
Question No. 2 If condition not returning correct results once an email sent. The user has a pop-up window on product pages, currently, it loads perfectly and works fine, but when you fill out the form it shows the default statement which is "Requesting email availability notification for the following product: product name". The user just wants the form to show a confirmation message instead of default message i.e. "You will be notified - Thank You". The current code is:
php
ob_start();
require_once('Ambiance/Environment/envi.php');
require_once('Ambiance/Modules/Product.php');
Environment::InitializeVDDB(Environment::dsn());
$product_id = strtoupper($_REQUEST['product_id']);
if (!$db->getOneEx(SQL::checkProductExists($product_id))):
die('Invalid Product ID');
endif;
// Select product info
$product = $db->getRowEx(SQL::getProductInfo($product_id));
$prod = new Product($product);
$image_path = Environment::main_docroot() . '/images/' . $product['as_sub_category_id'] . '/' .                 $product_id;
$prod_details = get_cart_info($prod);
Environment::LoadForms(array('AvailabilityNotification'));
require_once(Environment::include_path() . '/common/common_page_top.php');
?>
</span><span class="pln">Request Availability Notification</span><span class="tag">
php
require_once(Environment::include_path() . '/common/common_css.php');
require_once(Environment::include_path() . '/common/common_js.php');
?>

 style="background:#D9DADA;">
 class="commonPopup">
 class="popupHead">Request Availability Notification
class="floatLeft paddingLft20 paddingRgt20"> if ($availabilitynotification->isProcessed()): ?> class="bold">You will be notified - Thank you

endif;?> class="floatLeft"> Requesting e-mail availability notification for the following product:

class="floatLeft w90p"> class="floatLeft"> if ($thumb = VDFileAccess::get_item_header_img($image_path)): ?> Environment::webroot()?>/product/item.php?product-id=$product_id?>" title=""> class="displayPic">Environment::webroot()?>/images/product/$product['as_sub_category_id']?>/$product_id?>/thumbs/$thumb?>" > else: ?> Environment::webroot()?>/product/item.php?product-id=$product_id?>" title=""> class="displayPic">Environment::webroot()?>/images/product/no_image/thumbs/noimage.jpg" > endif;?> class="floatLeft w70p paddingTop10 marginLft15"> class="bold floatLeft nobtmMargin">Environment::encode_char($product['name'])?> iif(strlen($product['description']), '- ' . Environment::encode_char($product['description']), '')?>

class="clear">
class="bold floatLeft notopMargin">Item #$product_id?>

class="commonform marginTop15"> class="bold">Enter your email address in the form below

$_SERVER['PHP_SELF']?>"> $availabilitynotification->process->getElement()?> $availabilitynotification->name->getElement()?> $availabilitynotification->product_id->getElement()?> class="floatLeft"> class="inputLeft-Style3 "> type="text" name="email" onBlur="if (this.value == '') {this.value = 'E-mail address';}" onFocus="if(this.value == 'E-mail address') {this.value = '';}" value="E-mail address" class="inputMiddle-Style3 width305px"/> class="inputRight-Style3"> if ($availabilitynotification->hasErrors()): foreach ($availabilitynotification->getErrors() as $error) { ?> class="error cartError width305px">$error->getMessage()?> } endif; ?> class="clear">

class="floatLeft w100p"> class="floatLeft paddingTop10"> class="textGrey" href="#" onClick="parent.$.fn.colorbox.close();"> class="greyBtnLft-Big font12">Cancel class="greyBtnRgt-Big"> class="floatLeft marginLft30 paddingTop10"> class="textGrey" href="#" onClick="$('#email_product_availability').submit();"> class="blueBtnLft-Sml font12">Submit class="blueBtnRgt-Sml"> class="popupLogo floatRight">

php ob_end_flush(); ?> Answer: The code given below looks like is not inside of any if/else block.
 class="floatLeft">
Requesting e-mail availability notification for the following product:

You might need something like this:
 if ($availabilitynotification->isProcessed()): ?>
 class="bold">You will be notified - Thank you

else: ?> class="floatLeft"> Requesting e-mail availability notification for the following product:

endif; ?>
Question No. 3 How to retrieve product subscription alerts from a customer in Magento? A user wants to add a new section in the "My Account" section that will show all the products to which a customer is subscribed, but product will be shown on the button "Sign Up to get notified when this product is back in stock" on the product page. When a customer clicks on the button, it should disappear. How to make this button disappear when a customer has already clicked on it? Answer: Use the following code to get products to which a customer is subscribed
$customer_product_alerts = Mage::getModel('productalert/stock')
                           ->getCollection()
                           ->addFieldToFilter('customer_id', $customer_id);
Question No. 4 A user is asking "If a customer wants to buy products greater than the current stock they should receive a message like "The requested quantity is not available". Is there any way to either log or email (to the site admin or business owner) this type of event? Will it help the store owners to identify drop sales? Answer: Yes, it is possible with the help of code. You can make an observer event to check this behavior and sent the email to the admin. The only thing you need is to create and observer for chekout_cart_add_before event and put your logic to this observer. Another way is to use Magento Backorders feature. This feature can be found on the Inventory Tab. When this feature gets enabled, then the customer can order even requested quantity. Question No. 5 A user wants to add automatic email alert to customers on the addition of new products in Magento based online store. Is there any plugin/extension or something else available for this in Magento? Answer: Magento provides email alerts for when a product stock status changes or changes price. You can find this feature by following the path:
System>Config>Catalog>Product Alerts
If you look on Mage_ProductAlert, you will be able to use it for the new products arrival. If you want to offer product subscription, you should add a new model for product alert/category and extend the AddController with a categoryAction()

Download Magento Out of Stock Notification Extension

out-of-stock-notification