コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
 /**
  * Responds with information about updated inserted products option
  *
  * @method post
  * @return json/xml data
  */
 public function put($id)
 {
     $results = array();
     $productsOption = ProductsOptions::findFirstById($id);
     if ($productsOption) {
         $productsOptionCollection = ProductsOptionsCollection::findFirst(array(array('id' => $id)));
         if ($productsOptionCollection != false) {
             $productsOptionCollection->id = $productsOption->id;
             $productsOptionCollection->productId = $productsOption->productId;
             $productsOptionCollection->areaId = $productsOption->areaId;
             $productsOptionCollection->name = $productsOption->name;
             $productsOptionCollection->value = $productsOption->value;
             $productsOptionCollection->label = $productsOption->label;
             $productsOptionCollection->status = $productsOption->status;
             $productsOptionCollection->active = $productsOption->active;
             $productsOptionCollection->editable = $productsOption->editable;
             $productsOptionCollection->visibility = $productsOption->visibility;
             $productsOptionCollection->created = $productsOption->created;
             $productsOptionCollection->modified = $productsOption->modified;
             $productsOptionCollection->createdBy = $productsOption->createdBy;
             $productsOptionCollection->modifiedBy = $productsOption->modifiedBy;
             $success = $productsOptionCollection->save();
             if ($success) {
                 if (1 == $productsOption->status) {
                     $products = Products::findFirst(array(array('id' => $productsOption->productId)));
                     if ($products) {
                         $name = $productsOption->name;
                         $products->{$name} = $productsOption->value;
                         $products->save();
                         $results['id'] = $productsOption->id;
                     }
                 }
             }
         }
     }
     return $results;
 }