0

Onclick custom button "Register" (present in product view page), we are trying 3 things:

  1. Register user to site. (Working)
  2. Create new product programtically. (Working)
  3. Redirect to newly created product url (Not Working Instead, its redirecting to same Product's url)

public function createSimpleProductAndRedirect1Action()
{
    $originalProductId = $this->getRequest()->getParam('id');
    $originalProduct = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($originalProductId);

    if ($product = $this->_createit(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE, true, $originalProduct)) {
        if (Mage::getSingleton('customer/session')->isLoggedIn()) {
            $result['redirect'] = $product->getProductUrl();
            return $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
        }
    }
}

protected function _createit($type, $doSave = true, $originalProduct, $newImagePath = '')
{
    $res = '';
    $login = '';
    $productId = '';

    $session = Mage::getSingleton('customer/session');
    try {
        $errors = $this->_getCustomerErrors($customer);
        if (empty($errors)) {
            $res = $this->saveProduct($type, $doSave, $originalProduct, $newImagePath);
            $productId = $this->getRequest()->getPost('product_id');

            if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                return $res = $this->saveProduct($type, $doSave, $originalProduct, $newImagePath);
            }
        }
    } catch (Mage_Core_Exception $e) {
    }
}

public function saveProduct()
{
    // Product creation code
}

For "Login" . all 3 steps are working.

3
  • Have you tried with $this->_redirectUrl($product->getProductUrl());. Commented May 23, 2017 at 7:07
  • No, comment $result['redirect'] = $product->getProductUrl(); and return $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); and use $this->_redirectUrl($product->getProductUrl()); Commented May 23, 2017 at 7:12
  • @SaravananDS in Response tab its directing to new url, but onclick button its keep on showing `loading symbol......
    – user52996
    Commented May 23, 2017 at 7:18

1 Answer 1

0

Try replacing your line

$result['redirect'] = $product->getProductUrl();

With this one

Mage::getSingleton('customer/session')->setBeforeAuthUrl($product->getProductUrl());
4
  • tried with $result['redirect'] = Mage::getSingleton('customer/session')->setBeforeAuthUrl($product->getProductUrl()); , still its redirecting to current page only.....
    – user52996
    Commented May 23, 2017 at 11:46
  • At which moment are you calling createSimpleProductAndRedirect1Action Commented May 23, 2017 at 14:45
  • i am submitting form createSimpleProductAndRedirect1Action once i click on submit button.....
    – user52996
    Commented May 23, 2017 at 16:09
  • that 3rd part extension we were using, in that they used location.reload(); in code , changing this to document.location = response.redirect; worked for me.....
    – user52996
    Commented May 24, 2017 at 12:35

Your Answer

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