I have a cakephp web app, and for this specific controller checkout function (which is a view with some inputs and a list of products) for some reason the setFlash I intend to show after the data is saved isn't working as it should be. It should show on the indexstock.ctp view which is where I'm redirecting the user if save is successfully but instead it gets loaded on this very checkout.ctp view. I've reviewed this code countless times and can't find where the error is, despite the atipical logic of this function the rsetflash and redirect part is the same I use on every other function of this project.
This is my function:
public function checkout() {
$this->loadModel('Sale');
if (!empty($this->data))
{
$this->Sale->create();
if ($this->Sale->save($this->data))
{
session_start();
foreach($_SESSION["shopping_cart"] as $values)
{
$this->Sale->ProductsSale->create();
$this->Sale->ProductsSale->saveField('sale_id', $this->Sale->id);
$this->Sale->ProductsSale->saveField('product_id', $values['product_id']);
$this->Sale->ProductsSale->saveField('cant', $values['product_quantity']);
$this->Sale->ProductsSale->saveField('price', $values['product_price']);
$this->Sale->ProductsSale->saveField('shipping_id', $values['product_shipping']);
$this->Product->ProductsShipping->id = $values['product_psid'];
$this->Product->ProductsShipping->saveField('sold',$values['product_quantity']);
}
$this->Sale->Transaction->create();
$this->Sale->Transaction->saveField('date',$this->data['Sale']['date']);
$this->Sale->Transaction->saveField('concept',$this->data['Sale']['details']);
$this->Sale->Transaction->saveField('sign','+');
$this->Sale->Transaction->saveField('amount',$_SESSION["total_price"]);
$this->Sale->Transaction->saveField('sale_id', $this->Sale->id);
unset($_SESSION["shopping_cart"]);
//THIS GUY HERE IS THE ONE NOT BEHAVING CORRECTLY
$this->Session->setFlash('<strong>Exito!</strong> El producto se ha guardado', 'Flash/success');
$this->redirect(array('action'=>'indexstock'),null, true);
} else {
$this->Session->setFlash('<strong>Error!</strong> El producto no se ha guardado', 'Flash/error');
}
}
$clients = $this->Sale->Client->find('list');
$this->set(compact('clients'));
}
How do I solve this problem?