mercredi 6 mai 2015

Magento: if statement not functioning correctly

I am having an issue getting my if statement to function the way I want it. I have an Appointment Maker that shows up on the bottom of every page. Say they submit the form on the homepage/contact/about page, I want that to direct them to the /success/ page. Now say they are on a product detail page, which they more than likely will, I just want it to revert the success indicator back onto that specific product page they were on to begin with.

This is the coding I have at the moment:

$product = Mage::getModel('catalog/product')->load($data['product_id']);
   Mage::getSingleton('catalog/session')->addSuccess(Mage::helper('appointmentmaker')->getSuccessMessage());
    if($product) {
        $this->_redirectUrl($product->getProductUrl());
    } else {
        $this->_redirectUrl('/success/');
    }
    return; 

I can get the product redirect to work. But if they submit from the homepage, it will try to find the product detail page which of course there isn't one. It doesn't try to use the /success/ page instead.

Aucun commentaire:

Enregistrer un commentaire