public function action_delete($id = false) { if (is_numeric($id)) { // Get news item to edit if ($item = Model_Group::find_one_by_id($id)) { // Delete item try { // Delete all relations of this group with products $groups = Model_Product_To_Groups::find_by_group_id($item->id); if (!empty($groups)) { foreach ($groups as $group) { $group->delete(); } } $groups = Model_Group_Options::find_by_product_group_id($item->id); if (!empty($groups)) { foreach ($groups as $group) { $group->delete(); } } if (!empty($item->images)) { foreach ($item->images as $image) { $this->delete_image($image->image); $image->delete(); } } // Delete group $item->delete(); \Messages::success('Group successfully deleted.'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to delete group</strong>'); // Uncomment lines below to show database errors //$errors = $e->getMessage(); //\Messages::error($errors); } } } \Response::redirect(\Input::referrer()); }