/** * Responds with information about deleted record * * @method delete * @return json/xml data */ public function delete($id) { $results = array(); $product = Products::findFirstById($id); if ($product != false) { $productsCollection = ProductsCollection::findFirst(array(array('id' => $id))); if ($productsCollection != false) { $productsCollection->status = $product->status; $productsCollection->active = $product->active; $productsCollection->modified = $product->modified; $productsCollection->modifiedBy = $product->modifiedBy; $productsCollection->save(); $results['id'] = $product->id; } } return $results; }
/** * @api {put} /products/upload/:id PUT /products/upload/:id * @apiExample Example usage: * curl --upload-file /home/moneymax/bpi.png "http://apibeta.compargo.com/v1/products/upload/96b3d052-3716-11e4-b18a-fe7344fb1ea4/?language=en&countryCode=ph * -H "X-COMPARE-REST-API-KEY: 1234567890" * * @apiDescription Upload a Product Image * @apiName Delete * @apiGroup Products * * @apiHeader {String} X-COMPARE-REST-API-KEY Products unique access-key. * * @apiParam {String} language Mandatory Language. * @apiParam {String} countryCode Mandatory Country Code. * @apiParam {String} id Mandatory Product Unique ID. * @apiParam {String} file Mandatory File. * * @apiSuccess {String} id The ID of Product. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "id": "96b3d052-3716-11e4-b18a-fe7344fb1ea4" * } * * @apiError InvalidAccessToken The access token is invalid. * * @apiErrorExample Error-Response: * HTTP/1.1 401 Unauthorized * { * "error": "InvalidAccessToken" * } * * @apiError MissingAuthenticationCredentials The authentication credentials are missing. * * @apiErrorExample Error-Response: * HTTP/1.1 401 Unauthorized * { * "error": "MissingAuthenticationCredentials" * } * @apiError ProductNotFound The id of the Product was not found. * * @apiErrorExample Error-Response: * HTTP/1.1 404 Not Found * { * "error": "ProductNotFound" * } * * @apiError RouteNotFound That route was not found on the server. * * @apiErrorExample Error-Response: * HTTP/1.1 404 * { * "error": "RouteNotFound" * } */ public function upload($id) { $parameters = $results = array(); $requestBody = file_get_contents("php://input"); $request = $this->di->get('request'); $language = $request->get()['language']; if (!empty($requestBody)) { $product = Products::findFirstById($id); if ($product) { $width = isset($request->get()['width']) ? $request->get()['width'] : ''; $height = isset($request->get()['height']) ? $request->get()['height'] : ''; $quality = isset($request->get()['quality']) ? $request->get()['quality'] : 85; $parameters = array('prefix' => $id . '_', 'basename' => $product->name, 'uploadpath' => $language . '/products/', 'max_width' => $width, 'max_height' => $height, 'quality' => $quality); $image = new ImageUpload(); if ($filename = $image->save($requestBody, $parameters)) { $product->icon = $filename; if ($product->save()) { $productCollection = ProductsCollection::findFirst(array('condition' => array('id' => $id))); $productCollection->icon = $filename; if ($productCollection->save()) { $results[] = $productCollection; } } } } } else { throw new HTTPException("The request cannot be fulfilled due to bad syntax.", 400, array('dev' => 'A required field is missing.', 'internalCode' => 'P1000', 'more' => '')); } return $results; }
/** * @api {put} /products_options/:id PUT /products_options/:id * @apiExample Example usage: * curl -i -X PUT "http://apibeta.compargo.com/v1/products_options/e8227346-3a61-11e4-b18a-fe7344fb1ea4/?countryCode=ph&language=en" * -H "X-COMPARE-REST-API-KEY: 1234567890" * -d "areaId=0b412a0e-397a-11e4-b18a-fe7344fb1ea4& * value=1& * status=0" * * @apiDescription Update a Products Option * @apiName Put * @apiGroup Products Options * * @apiHeader {String} X-COMPARE-REST-API-KEY Products Options unique access-key. * * @apiParam {String} language Mandatory Language. * @apiParam {String} countryCode Mandatory Country Code. * @apiParam {String} id Mandatory Products Option Unique ID. * @apiParam {String} productId Mandatory Product ID of the Products Option. * @apiParam {String} areaId Mandatory Area ID of the Products Option. * @apiParam {String} name Mandatory Name of the Products Option. * @apiParam {String} value Mandatory Value of the Products Option. * @apiParam {String} [label] Optional Label of the Products Option. * @apiParam {String} [editable] Optional Editable Flag of the Products Option. * @apiParam {String} [visibility] Optional Visibility Flag of the Products Option. * @apiParam {String} [status] Optional Status of the Products Option. * @apiParam {String} [createdBy] Optional ID of the User who created the Products Option. * @apiParam {String} [modifiedBy] Optional ID of the User who modified the Products Option. * * @apiSuccessExample Success-Response: * HTTP/1.1 200 OK * { * "id": "e8227346-3a61-11e4-b18a-fe7344fb1ea4" * } * * @apiError BadInputParameter The request cannot be fulfilled due to bad syntax. * * @apiErrorExample Error-Response: * HTTP/1.1 400 * { * "error": "BadInputParameter" * } * * @apiError InvalidAccessToken The access token is invalid. * * @apiErrorExample Error-Response: * HTTP/1.1 401 Unauthorized * { * "error": "InvalidAccessToken" * } * * @apiError MissingAuthenticationCredentials The authentication credentials are missing. * * @apiErrorExample Error-Response: * HTTP/1.1 401 Unauthorized * { * "error": "MissingAuthenticationCredentials" * } * @apiError ProductsOptionNotFound The id of the Products Option was not found. * * @apiErrorExample Error-Response: * HTTP/1.1 404 Not Found * { * "error": "ProductsOptionNotFound" * } */ public function put($id) { $results = array(); $request = $this->di->get('request'); $data = $request->getPut(); if (!empty($data)) { $productsOptions = ProductsOptions::findFirstById($id); if (!$productsOptions) { throw new HTTPException("Not found", 404, array('dev' => 'Products option does not exist', 'internalCode' => 'P1000', 'more' => '')); } else { $data['productId'] = isset($data['productId']) ? $data['productId'] : $productsOptions->productId; $data['areaId'] = isset($data['areaId']) ? $data['areaId'] : $productsOptions->areaId; $data['name'] = isset($data['name']) ? $data['name'] : $productsOptions->name; $data['value'] = isset($data['value']) ? $data['value'] : $productsOptions->value; $data['label'] = isset($data['label']) ? $data['label'] : $productsOptions->label; $data['status'] = isset($data['status']) ? $data['status'] : $productsOptions->status; if (isset($data['status'])) { $data['active'] = $data['status'] != ProductsOptions::ACTIVE ? 0 : 1; $data['editable'] = $data['status'] != ProductsOptions::ACTIVE ? 0 : $productsOptions->editable; $data['visibility'] = $data['status'] != ProductsOptions::ACTIVE ? 0 : $productsOptions->visibility; } $data['createdBy'] = isset($data['createdBy']) ? $data['createdBy'] : $productsOptions->createdBy; $data['modifiedBy'] = isset($data['modifiedBy']) ? $data['modifiedBy'] : $productsOptions->modifiedBy; $products = Products::findFirstById($data['productId']); if ($products) { $channels = Channels::findFirstById($products->channelId); if ($channels) { $params[$data['name']] = $data['value']; $valid = $productsOptions->validateProperty($params, $this->schemaDir . $this->getDI()->getConfig()->application->jsonSchema->{$channels}->alias); if (!empty($valid)) { $errors = implode(", ", $valid); throw new HTTPException("Request unable to be followed due to semantic errors.", 422, array('dev' => ucfirst($errors), 'internalCode' => 'P1000', 'more' => '')); } } } if ($productsOptions->save($data)) { $results['id'] = $productsOptions->id; } else { throw new HTTPException("Request unable to be followed due to semantic errors", 422, array('dev' => $productsOptions->getMessages(), 'internalCode' => 'P1000', 'more' => '')); } } } else { throw new HTTPException("The request cannot be fulfilled due to bad syntax.", 400, array('dev' => 'A required field is missing.', 'internalCode' => 'P1000', 'more' => '')); } return $results; }