Reputation: 1791
We have a quote module that will submit a quote request then redirect to a certain page. We would like to return to the product page but after trying a few things it's still not working.
The code below shows the processor for the quote and at the end shows: $this->_redirect('Quotation/Quote/List/');
I've tried a couple of ideas in terms of trying to fetch a URL but nothing is working as of yet.
What would I need to add to fetch the product URL when it processes and then redirect to that page rather than the Quotation/Quote/List page?
/**
* Create a quote inquiry with cart's products
*
*/
public function CreateRequestAction()
{
$this->loadLayout();
$this->renderLayout();
}
/**
* Create a quote inquiry with cart's products
*
*/
public function CreateIndividualRequestAction()
{
$this->loadLayout();
$this->renderLayout();
}
/**
* Post a new quote request Individual
*
*/
public function SendIndividualRequestAction()
{
$CustomerId = mage::Helper('customer')->getCustomer()->getId();
$storeId = mage::getModel('customer/customer')->load($CustomerId)->getStoreId();
$defaultValidityDuration = Mage::getStoreConfig('quotation/general/default_validity_duration', $storeId);
$defaultExpirationDate = time() + $defaultValidityDuration * 24 * 3600;
//Create new quotation
$NewQuotation = mage::getModel('Quotation/Quotation')
->setcustomer_id($CustomerId)
->setcaption($this->__('New request'))
->setcreated_time(date("Y/m/d"))
->setcustomer_msg($this->getRequest()->getPost('description'))
->setcustomer_request(1)
->setstatus(MDN_Quotation_Model_Quotation::STATUS_CUSTOMER_REQUEST)
->setvalid_end_time(date('Y/m/d', $defaultExpirationDate))
->save();
$NewQuotation->setincrement_id($NewQuotation->GenerateIncrementId())->save();
//Add selected product
$product = mage::getModel('catalog/product')->load($this->getRequest()->getPost('product_id'));
if ($product->getId())
{
//add product to quotation
$quotationItem = mage::getModel('Quotation/Quotationitem')
->setquotation_id($NewQuotation->getId())
->setorder(1)
->setproduct_id($product->getId())
->setqty(1)
->setprice_ht($product->getPrice())
->setcaption($product->getName())
->setsku($product->getSku())
->setcost($product->getCost())
->setweight($product->getWeight())
->save();
//compute quotation price & weight
$NewQuotation->CalculateWeight();
$NewQuotation->CalculateQuotationPriceHt();
}
//Notify admin
$NewQuotation->NotifyCreationToAdmin();
//confirm
$this->_redirect('Quotation/Quote/List/');
}
Upvotes: 1
Views: 2114
Reputation: 37700
Instead of ._redirect()
use _redirectReferer()
It looks like _redirect()
works the same as getUrl()
(in fact, it is used as-is).
$this->_redirect('catalog/product/view', array(
'id'=>$product->getId(),
'_use_rewrite'=>true
));
NB: Because of the way products can be identified this will redirect to the page with no category in the URL. If you know the category ID from which the product was chosen/submitted then include it in the array as category
.
Upvotes: 4