4

How can we display the "Sign up to get notified when this product is back in stock" link for associated products of a configurable product.

Say, we have a T-Shirt (a configurable product) and we sell it in 3 sizes - Medium, Large and Xtra-Large (simple - associated products).

When the Large size goes out of stock, how can we make user subscribe for it for notification when it is back in stock.

Please note I have already set this setting in admin:

System > Configuration > Catalog > Allow Alert When Product Comes Back in Stock - Yes

I noticed that the url for this alert is like (it is for one of the simple products in my store):

http://localhost/mystore/index.php/productalert/add/stock/product_id/1/[some key]/[some key],,/

Is there any way we can call this url directly, passing the product id of our associated product in question? If so, what about those keys at the end of the url?

please guide.

thanks

Prashant
  • 5,331
  • 10
  • 44
  • 59

3 Answers3

7

I added this link beside the out-of-stock associated product:

http://localhost/mysite/index.php/productalert/add/stock/product_id/[associated_product_id]/uenc/[any_key]/

For e.g.

http://localhost/mysite/index.php/productalert/add/stock/product_id/17/uenc/MTM0MzcyMDk0Mw==/

It does my job.

Only thing is, after successfully adding the alert record, it redirects to home page, instead of same page as in normal case.

This is due to [any_key], if we could somehow encrypt current page url [the any_key] just like magento does, we can have it redirect to same page also, after successful saving of alert record. Any ideas?

Thanks

Ok I got it finally!

The uenc key [any_key] is actually base64 encoding of current url.

So with the help of https://github.com/carlo/jquery-base64, I did:

var encodedUrl = $.base64.encode(window.location);

var redirectTo = 'http://localhost/mysite/index.php/productalert/add/stock/product_id/[associated_product_id]/uenc/' + encodedUrl + '/';

Hope this helps!

Prashant
  • 5,331
  • 10
  • 44
  • 59
3

The Magento way to get the url would be:

Mage::helper('productalert')->setProduct($_product)->getSaveUrl('stock')

The Ape
  • 303
  • 2
  • 7
1

Magento already avails the functionality to set out of stock from admin panel, unfortunately it is limited to some instances therefore we can not set this from admin panel, either way you can do it in code as above mentioned but its a manual task and can not be done again and again with links. So i think its better to use ready made extension in case you have specific requirement to set product stock alert functionality for customer and they can subscribe for it. Here is the well managed extension for Magento 2 which can help you to set Product alert and sign-up / subscription functionality with many more admin manageable features. Link to Out of stock notification extension for Magento 2 - https://www.mconnectmedia.com/out-of-stock-alert-magento2.html