$reply->message = "Product created OK"; // put to an existing Product } else { if ($method === "PUT") { // convert PUTed JSON to an object verifyXsrf(); $requestContent = file_get_contents("php://input"); $requestObject = json_decode($requestContent); $product = new Product($productId, $requestObject->vendorId, $requestObject->description, $requestObject->leadTime, $requestObject->sku, $requestObject->title); $product->update($pdo); $reply->data = "Product updated OK"; // delete an existing Product } else { if ($method === "DELETE") { verifyXsrf(); $productAlerts = ProductAlert::getProductAlertByProductId($pdo, $productId); foreach ($productAlerts as $productAlert) { $productAlert->delete($pdo); } $finishedProducts = FinishedProduct::getFinishedProductByRawMaterialId($pdo, $productId); foreach ($finishedProducts as $finishedProduct) { $finishedProduct->delete($pdo); } $productLocations = ProductLocation::getProductLocationByProductId($pdo, $productId); foreach ($productLocations as $productLocation) { $productLocation->delete($pdo); } $movements = Movement::getMovementByProductId($pdo, $productId); foreach ($movements as $movement) { $movement->delete($pdo); }
/** * test grabbing a ProductAlert by productId that does not exist * * PDOException **/ public function testGetInvalidProductAlertByProductId() { // grab an productId that does not exist $pdoProductAlert = ProductAlert::getProductAlertByProductId($this->getPDO(), InventoryTextTest::INVALID_KEY); $this->assertNull($pdoProductAlert); }