/** * Edits a product * * @return null */ public function action_edit() { $id = arr::get($_GET, 'id'); $this->request->response = new View_Admin_Product_Form(); $this->request->response->bind('product', $product); $this->request->response->bind('errors', $errors); $product = new Model_Vendo_Product($id); if ($_POST) { $categories = arr::get($_POST, 'category_id', array()); $product->set_fields($_POST); try { $product->save(); $product->remove_all('vendo_product_categories'); foreach ($categories as $cat_id) { $product_category = new Model_Vendo_Product_Category($cat_id); $product_category->vendo_products = $product->id; } $this->request->redirect('admin/product'); } catch (AutoModeler_Exception $e) { $errors = (string) $e; } } }
/** * Tests to ensure that a saved order cannot have new products added to it * * @return null */ public function test_saved_order_is_fixed() { // Create a new product first $product = new Model_Vendo_Product(); $product->set_fields(array('name' => 'Unit Test', 'price' => '9.99', 'description' => 'This is a unit test.', 'order' => '1')); $product->save(); $order = new Model_Order(); $order->user_id = self::$user->id; $order->address_id = self::$user->address_id; $order->contact_id = self::$contact->id; $order->add_product($product, 1); $order->save(); try { $order->add_product($product, 1); } catch (Exception $e) { $this->assertEquals('Saved orders cannot be modified!', $e->getMessage()); $order->delete(); $product->delete(); return; } $order->delete(); $product->delete(); $this->fail('Orders cannot be modified once saved.'); }