4

I am trying to create a "Notify me" feature if the stock is unavailable.

On search on admin panel, I could find only that a user should sign up / log in to get notified about the stock availability.

But I just want to let the user (a guest) enter only his/her email address to get notified.

How should I do this?

Please give suggestions..

EDIT:

I have got this link, which gives me a way to start.

Till now what I did is added the following code in my template file which is creating a url for redirect (thinking to do it in ajax way, to stop page refreshing).

<?php
      $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
      $base64 = strtr(base64_encode($actual_link), '+/=', '-_,'); 
      $postUrl = "http://$_SERVER[HTTP_HOST]/efk/productalert/add/stock/product_id/" . $simpleProduct->getId() . "/uenc/". $base64; 
?>

In the above code, efk is my project folder name.

After this, I have gone to productalert/add/stock controller method i.e stockAction() which is calling sign up / login form (I think so) using $model->save();.

How should I disable this save calling and add my own small overlay which holds a textbox to enter a email address?

Community
  • 1
  • 1
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
  • `$base64 = strtr(base64_encode($actual_link), '+/=', '-_,'); ` Oh wow why? – Brad Nov 24 '13 at 05:55
  • @Brad I saw this way in some post here on SO.. btw I am new to php.. I think this is not needed may be magento provides the same as built-in method.. I couldn't find it. – Mr_Green Nov 24 '13 at 05:55
  • It looks like you're trying to do some really hackish form of URL encoding... Unless you have to do that to be compatible with something (I'm not familiar with Magento), use `urlencode()`. – Brad Nov 24 '13 at 05:56
  • Just a note: If you haven't considered it already, do make sure that you verify notification requests via email (similar to verifying account signups by clicking a link). Otherwise, your service could get abused and your mail may be identified as spam. – Bailey Parker Nov 28 '13 at 09:03

5 Answers5

4

Magento has "Notify me when product is back in stock" feature out of the box. It can be configured in admin panel: system / configuration / catalog / product alerts and product alerts run settings.

You're right, it works only for registred customers. To make it working for guest users some coding is required. I'd say you need to do the following steps:

  1. Add email column to product_alert_stock table
  2. Create new controller and action (believe me, it's better than you override existing one via config.xml) which extends Mage_ProductAlert_AddController::stockAction(). Your method will have to set guest's email to productalert/stock model.
  3. Create subscription form and make sure it submits data to your new controller/action.
  4. Update (override) Mage_ProductAlert_Model_Observer::_processStock() method to make it respect situations when "customer" has no ID but has email.

When you'll be testing, I suggest you to install SMTP Pro Email extension and mailcatcher to ease the testing process.

vsushkov
  • 2,445
  • 1
  • 19
  • 28
2

We have done this (http://www.alfresia.co.uk/sorrento-side-table.html/). Here we ended up creating a custom module as when we did this magento did not support any product alert system for the guest users (i do not know if this is supported now).

We first created a text box which would appear on product page where the product is out of stock. We were saving this info in one of our custom tables where we the schema was {id, email, product_sku, status} (status had three values Awaiting Stock, In Stock, and Already Notified).

We then wrote an observer which was hooked to cataloginventory_stock_item_save_after event, this helped us get the product sku which has been back in stock, and update all entries in our custom table with status In Stock and send a mail to the user.

This is how we did it, surely there will be a much cleaner way doing this.

Munjal
  • 936
  • 1
  • 8
  • 19
0

You could have work with plugins. MagentoCommerce has loads of plugins/extensions which does the same

Free Version - http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html

Shiva
  • 316
  • 1
  • 4
0

I too had similar requirement, and have installed 'http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html' this plugin. Well this plugin does the job, But they have override complete product view page template instead of simply adding a new block. By this your custom development on product view page development might get reflected on frontend.

Or else this plugin definitely does the job.

Rakesh
  • 77
  • 11
  • I installed this extension. this works if the complete configurable product is set as "out of stock" only. please help. please go through the comments in below post where I explained clearly about my issue.. – Mr_Green Nov 29 '13 at 10:33
  • Check modules view.phtml files once. And see if you can figure out the bug. – Rakesh Nov 29 '13 at 10:50
0

This http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html plugin is really good but it breaks for configurable product types and it completely overrides the product controller which makes your system vulnerable to future upgrades. I think observers should be hooked to events where the product is back in stock and should update the users.

  • I installed this extension. this works if the complete configurable product is set as "out of stock" only. – Mr_Green Nov 29 '13 at 10:13
  • so when the configurable product is in stock, does it render from the default magento controller?? – user2790350 Nov 29 '13 at 10:25
  • yes... If I manually set in admin config that the configurable product is out of stock then only I can see the out of stock notification. This is completely different from what I want actually. What I want is I have three simple products in each configurable product. and if any of the simple product has quantity as `0` then the out of stock notification should be visible automatically. Can you please install this extension and try to synchonize with what I am trying to explain here? that would be really helpful for me. thanks.. :) – Mr_Green Nov 29 '13 at 10:32
  • I misunderstood your first comment, now I get your point. I think in that case you will have to write some code, in order to get this working or just rewrite the plugin to make sure it works for you. I reckon just write observer methods they are easy implementation, it might be just neater than rewrting an extension and then debugging. Also I am travelling over the weekend and does not seem to be possible for me to install it. Sorry !!! – user2790350 Nov 29 '13 at 14:34