Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Created August 13, 2013 01:39
Show Gist options
  • Save amacgregor/6217086 to your computer and use it in GitHub Desktop.
Save amacgregor/6217086 to your computer and use it in GitHub Desktop.
Original actions for the IndexController
<?php
....
public function newPostAction()
{
try {
$data = $this->getRequest()->getParams();
$registry = Mage::getModel('mdg_giftregistry/entity');
$customer = Mage::getSingleton('customer/session')->getCustomer();
if($this->getRequest()->getPost() && !empty($data)) {
$registry->updateRegistryData($customer, $data);
$registry->save();
$successMessage = Mage::helper('mdg_giftregistry')->__('Registry Successfully Created');
Mage::getSingleton('core/session')->addSuccess($successMessage);
}else{
throw new Exception("Insufficient Data provided");
}
} catch (Mage_Core_Exception $e) {
Mage::getSingleton('core/session')->addError($e->getMessage());
$this->_redirect('*/*/');
}
$this->_redirect('*/*/');
}
public function editPostAction()
{
try {
$data = $this->getRequest()->getParams();
$registry = Mage::getModel('mdg_giftregistry/entity');
$customer = Mage::getSingleton('customer/session')->getCustomer();
if($this->getRequest()->getPosts() && !empty($data) )
{
$registry->load($data['registry_id']);
if($registry){
$registry->updateRegistryData($customer, $data);
$registry->save();
$successMessage = Mage::helper('mdg_giftregistry')->__('Registry Successfully Saved');
Mage::getSingleton('core/session')->addSuccess($successMessage);
}else {
throw new Exception("Invalid Registry Specified");
}
}else {
throw new Exception("Insufficient Data provided");
}
} catch (Mage_Core_Exception $e) {
Mage::getSingleton('core/session')->addError($e->getMessage());
$this->_redirect('*/*/');
}
$this->_redirect('*/*/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment