/** * Updates a product option. * * @param Model_Product_Option $option The product option to update. * @param array $data The data to use to update the product option. * * @return Model_Product_Option */ public static function update(Model_Product_Option $option, array $data = array()) { $option->populate($data); if (!empty($data['meta'])) { $option->metas = array(); foreach ($data['meta'] as $meta_id => $meta_option_id) { if (empty($meta_option_id)) { unset($option->metas[$meta_id]); } else { if ($meta_option = Service_Product_Meta_Option::find_one($meta_option_id)) { $option->metas[] = $meta_option; } } } } try { $option->save(); } catch (FuelException $e) { Log::error($e); return false; } Service_Event::trigger('product.option.update', $option->product->seller, $option->to_array()); return $option; }
/** * Attempts to get a product meta option from a given ID. * * @param int $id Product meta option ID. * @param \Model_Product_Meta $meta Product meta the option should belong to. * * @return \Model_Product_Meta_Option */ protected function get_option($id, \Model_Product_Meta $meta) { if (!$id) { throw new HttpNotFoundException(); } $option = \Service_Product_Meta_Option::find_one($id); if (!$option || $option->meta != $meta || $option->meta->product->seller != \Seller::active()) { throw new HttpNotFoundException(); } return $option; }