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.'<br/>Customer'.wants to be notified when the below product is available in our inventory<br/><p>Item Name :</p><p>SKU :</p><p> Search Code :</p><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.'<br/>Customer'.".$pincode."wants to be notified when the below product is available in our inventory<br/><p>Item Name :".$name."</p><p>SKU :".$sku."</p><p> Search Code :".$scode."</p><p>Bar Code :".$bcode."</p>";
     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.'<br />Customer'.".$pincode."wants to be notified when the below product is available in our inventory<br /><p>Item Name :".$name."</p><p>SKU :".$sku."</p><p> Search Code :".$scode."</p><p>Bar Code :".$bcode."</p>";

     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');
?>
<title>Request Availability Notification</title>
<?php
require_once(Environment::include_path() . '/common/common_css.php');
require_once(Environment::include_path() . '/common/common_js.php');
?>
</head>
<body style="background:#D9DADA;">
<div class="commonPopup">
<div class="popupHead">Request Availability Notification</div>
<div class="floatLeft paddingLft20 paddingRgt20">
<? if ($availabilitynotification->isProcessed()): ?>
<p class="bold">You will be notified - Thank you</p>
<? endif;?>
<p class="floatLeft">
Requesting e-mail availability notification for the following product:
</p>
<span class="floatLeft w90p"> 
<span class="floatLeft">
<? if ($thumb = VDFileAccess::get_item_header_img($image_path)): ?> 
<a href="<?=Environment::webroot()?>/product/item.php?product-id=<?=$product_id?>"  title="">    <span class="displayPic"><img class="css3" alt="" src="<?=Environment::webroot()?>/images/product/<?=$product['as_sub_category_id']?>/<?=$product_id?>/thumbs/<?=$thumb?>" ></span></a>
<? else: ?>
<a href="<?=Environment::webroot()?>/product/item.php?product-id=<?=$product_id?>"  title=""><span class="displayPic"><img class="css3" alt="" src="<?=Environment::webroot()?>/images/product/no_image/thumbs/noimage.jpg" ></span></a>
<? endif;?>
</span>
<span class="floatLeft w70p paddingTop10 marginLft15">
<p class="bold floatLeft nobtmMargin"><?=Environment::encode_char($product['name'])?> <?=iif(strlen($product['description']), '- ' . Environment::encode_char($product['description']), '')?></p> 
<div class="clear"></div>
<p class="bold floatLeft notopMargin">Item #<?=$product_id?></p>
</span>
</span>
<section class="commonform  marginTop15"> 
<p class="bold">Enter your email address in the form below</p>
<form method="post" id="email_product_availability" name="email_product_availability" action="<?=$_SERVER['PHP_SELF']?>">
<?=$availabilitynotification->process->getElement()?>
<?=$availabilitynotification->name->getElement()?>
<?=$availabilitynotification->product_id->getElement()?>
<span class="floatLeft">
<span class="inputLeft-Style3 "></span>
<input 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"/>
<span class="inputRight-Style3"></span>
<? 
if ($availabilitynotification->hasErrors()):
foreach ($availabilitynotification->getErrors() as $error) {
?>
<label class="error cartError width305px"><?=$error->getMessage()?></label>
<? 
}
endif;
?>
</span>
</form>
</section>
<p class="clear"></p>
<p class="floatLeft w100p"> 
<span class="floatLeft paddingTop10"> 
<a class="textGrey" href="#" onClick="parent.$.fn.colorbox.close();"> 
<span class="greyBtnLft-Big font12">Cancel</span> <span class="greyBtnRgt-Big"></span>
</a> 
</span> 
<span class="floatLeft marginLft30 paddingTop10"> 
<a class="textGrey" href="#" onClick="$('#email_product_availability').submit();"> 
<span class="blueBtnLft-Sml font12">Submit</span> 
<span class="blueBtnRgt-Sml"></span>
</a> 
</span> 
<span class="popupLogo floatRight"></span>
</p>
</div>
</div>
</div>
<script>
$(document).ready(function(){
var x = $(document).height() + 30;
var y = $(document).width();
parent.$.fn.colorbox.resize({width:y, height:x});
});
</script>
</body>
</html>
<?php
ob_end_flush();
?>

Answer:

The code given below looks like is not inside of any if/else block.

<p class="floatLeft">
Requesting e-mail availability notification for the following product:
</p>

You might need something like this:

<? if ($availabilitynotification->isProcessed()): ?>
<p class="bold">You will be notified - Thank you</p>
<? else: ?>
<p class="floatLeft">
Requesting e-mail availability notification for the following product:
</p>
<? 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

Leave a Reply