Onclick custom button "Register" (present in product view page), we are trying 3 things:
- Register user to site. (Working)
- Create new product programtically. (Working)
- 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.
$this->_redirectUrl($product->getProductUrl());
.$result['redirect'] = $product->getProductUrl();
andreturn $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
and use$this->_redirectUrl($product->getProductUrl());
Response tab
its directing tonew url
, but onclick button its keep on showing `loading symbol......