public function action_delete($id = false) { if (is_numeric($id)) { // Get news item to edit if ($item = Model_Attribute_Option::find_one_by_id($id)) { // Delete item try { $item->delete(); // NRB-Gem: remove from product_attributes and product_attribute_price $a_attr = \Product\Model_Attribute::find_by(array(array('attributes', 'like', '%"' . $item->attribute_id . '":"' . $id . '"%'))); $a_attr_id = array(); foreach ($a_attr as $o_attr) { $a_attr_id[] = $o_attr->id; } if (count($a_attr_id)) { $s_ids = '(' . implode(',', $a_attr_id) . ')'; \DB::delete('product_attributes')->where('id', 'IN', \DB::expr($s_ids))->execute(); \DB::delete('product_attribute_price')->where('product_attribute_id', 'IN', \DB::expr($s_ids))->execute(); } \Messages::success('Attribute option successfully deleted.'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to delete attribute option</strong>'); // Uncomment lines below to show database errors //$errors = $e->getMessage(); //\Messages::error($errors); } } } if (\Request::is_hmvc()) { \Messages::reset(); } else { \Response::redirect(\Input::referrer(\Uri::create('admin/attribute/list'))); } }