0

I'm trying to implement a custom payment module and have added a few custom colums to the sales_flat_order_payment table. After the customer places the order, these fields should be updated and some of the inserted information needs to pre presented simultaneously. I do all of this in a custom block, that should display a custom template file or an error message if something went wrong. The problem I'm having now is, that the database information doesn't get updated. I don't know if this is the right way to do it but here is my code:

 $this->orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();         
 $this->order = Mage::getModel('sales/order')->loadByIncrementId($this->orderId);
 $this->payment = $this->order->getPayment();

then later I try to assign my data to the fields, for example:

 $this->payment->setMyData(time());

the column names are all correct, in this case it would be my_data. I do the same with the appropriate get() methods, which seem to work ok.

Also there seems to be another problem, the error message in the constructor doesn't get displayed every time:

if($this->establishGateway() == true)
            {
              $this->setTemplate('mypayment/gateway.phtml');  
            }
            else
            {
               Mage::getSingleton('core/session')->addError(__('There was a Problem with the Payment Gateway.')); 

            }

loadlayout and renderlayout get called from the controller that loads this block. Any suggestions?

2
  • Did you clear cache after adding the fields to the table? Did you save after $this->order->getPayment();? – Renon Stewart Sep 13 '15 at 18:50
  • It seems like I had to call save() on the object to update the actual database content, now it's working I think. But I still can't the error messages don't show up in that block. What do I have to call in the constructor if the template doesn't get loaded when there was an error? – user1563232 Sep 13 '15 at 20:28
1

In order to save the data to the database you need the call the save() method.

$this->orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();         
$this->order = Mage::getModel('sales/order')->loadByIncrementId($this->orderId);
$this->payment = $this->order->getPayment();
$this->payment->setMyData(time());
....
$this->payment->save();

Also

 Mage::getSingleton('core/session')->addError(__('There was a Problem with the Payment Gateway.'));

will only display the error message on redirect/page reload

1
  • Ok I got it, but how can I display an error now within my block? I tried overriding the _prepareLayout() method and calling something like $this->getLayout()->getMessagesBlock()->addError("myError"); but it doesn't show up. Do I have to load a template just to output a message or is there another way? – user1563232 Sep 14 '15 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.