I'm working on an ajax module and I have to create a product alert button block. I'm using this code to create the block:

$stockAlertBlock = $this->getLayout()->createBlock(
            array('template' => 'productalert/product/view.phtml')

        $stockAlertBlock->setHtmlClass('alert-stock link-stock-alert');
        $stockAlertBlock->setSignupLabel('Register to receive stock alert');

The block will be created but the link is not working because I'm not able to set correctly the product.

I've tried

$stockAlertBlock->setSignupUrl('productalert/add/stock/product_id/' . $simpleProduct->getId().'/uenc/'.Mage::helper('core/url')->getEncodedUrl().'/');

but it's not working.

Do you have any suggestion? thanks

  • What is not working? Where is the second code from? NEVER tell someone it is not working, always describe "it" :-) Commented Jun 1, 2015 at 16:54
  • is the last parameter I miss to make it works. I guess I'm wrong generating the uenc part.
    – apedic
    Commented Jun 1, 2015 at 16:59

2 Answers 2


The product is set here:

protected function _prepareLayout()
    $product = Mage::registry('current_product');
    if ($product && $product->getId()) {
        $this->_product = $product;

    return parent::_prepareLayout();

I'm not sure whether _prepareLayout() is called if you create the block this way. So you can try to set it in the registry beforehand, the alternative is to either extend the block to make _product accessable or use reflection.

  • I just have to setSignupUrl. I'm using $stockAlertBlock->setSignupUrl('productalert/add/stock/product_id/' . $simpleProduct->getId().'/uenc/'.Mage::helper('core/url')->getEncodedUrl().'/'); But doesn't work. can you help please?
    – apedic
    Commented Jun 1, 2015 at 16:45
  • Can you please edit your question and add the information, so it is readable? Commented Jun 1, 2015 at 16:45

You can do this by a simple way.

Rewrite helper class Mage_ProductAlert_Helper_Data of Mage_ProductAlert module and create a custom function and on this funtion write code for custom url for product alert.

class Amit_CustomProductAlert_Helper_Data extends Mage_ProductAlert_Helper_Data
    public function getStockSimpleSaveUrl($type=stock,$product_id)
        return $this->_getUrl('productalert/add/' . $type, array(
            'product_id'    => $product_id,
            Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl()



Now using the function you can get product stock alert url at any where


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.