Esempio n. 1
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get attribute options
                 $item->get_options = static::lazy_load(function () use($item) {
                     return Model_Attribute_Option::find(array('where' => array('attribute_id' => $item->id), 'order_by' => array('sort' => 'asc')), 'id');
                 }, $item->id, 'options');
             }
         }
     }
     // return the result
     return $result;
 }
Esempio n. 2
0
 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')));
     }
 }