protected function post() { $json = array(); $userName = $this->user->getUserName(); $tmpFileName = $this->request->files['file']['tmp_name']; $srcFileName = urldecode($this->request->files['file']['name']); $tmpfilesize = filesize($this->request->files['file']['tmp_name']); $vendorId = $this->user->getVP(); //file type must be acceptable $imageType = exif_imagetype($this->request->files['file']['tmp_name']); if (IMAGETYPE_GIF != $imageType && IMAGETYPE_JPEG != $imageType && IMAGETYPE_PNG != $imageType) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_FILE_ERROR, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_FILE_ERROR)); } //file size must be >0 if (0 >= $tmpfilesize) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_FILE_ERROR, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_FILE_ERROR)); } //append timestamp to all uploaded image filenames to ensure uniqueness $path_parts = pathinfo($srcFileName); $fileNameTimestamped = $path_parts['filename'] . "_" . time() . "." . $path_parts['extension']; $destination = "catalog/" . $userName . "/" . $fileNameTimestamped; //move tmpfile to proper vendor-specific location if (!rename($tmpFileName, DIR_IMAGE . $destination)) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_FILE_ERROR, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_FILE_ERROR)); } $this->load->model('catalog/vdi_vendor_profile'); //ask model to associate image in db, providing vendor id and destination filename $this->model_catalog_vdi_vendor_profile->setVendorProfileImage($vendorId, $destination); $json['filename'] = $fileNameTimestamped; $this->response->setOutput($json); }
public function index($args = array()) { if ($this->request->isPostRequest()) { $this->post(); } else { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_NOT_FOUND, ErrorCodes::ERRORCODE_METHOD_NOT_FOUND, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_METHOD_NOT_FOUND)); } }
public function index($args = array()) { $id = isset($args['id']) ? $args['id'] : null; if ($this->request->isGetRequest()) { $this->get($id); } else { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_NOT_FOUND, ErrorCodes::ERRORCODE_METHOD_NOT_FOUND, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_METHOD_NOT_FOUND)); } }
public function redirect($url, $status = 302) { switch ($url) { case 'account/login': // User not logged in throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_USER_NOT_LOGGED_IN, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_USER_NOT_LOGGED_IN)); break; } }
public function post() { $this->load->model('catalog/vendor'); $vendor = $this->model_catalog_vendor->getVendor($this->user->getVP()); if (empty($vendor)) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_NOT_FOUND, ErrorCodes::ERRORCODE_VENDOR_NOT_FOUND, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_VENDOR_NOT_FOUND)); } if (isset($this->request->post['company'])) { $vendor['company'] = $this->request->post['company']; if (!isset($this->request->post['vendor_name'])) { $vendor['vendor_name'] = $this->request->post['company']; } } if (isset($this->request->post['vendor_name'])) { $vendor['vendor_name'] = $this->request->post['vendor_name']; if (!isset($this->request->post['company'])) { $vendor['company'] = $this->request->post['vendor_name']; } } if (isset($this->request->post['vendor_description'])) { $vendor['vendor_description'] = $this->request->post['vendor_description']; } if (isset($this->request->post['telephone'])) { $vendor['telephone'] = $this->request->post['telephone']; } if (isset($this->request->post['email'])) { $vendor['email'] = $this->request->post['email']; } if (isset($this->request->post['firstname'])) { $vendor['firstname'] = $this->request->post['firstname']; } if (isset($this->request->post['lastname'])) { $vendor['lastname'] = $this->request->post['lastname']; } if (isset($this->request->post['address_1'])) { $vendor['address_1'] = $this->request->post['address_1']; } if (isset($this->request->post['address_2'])) { $vendor['address_2'] = $this->request->post['address_2']; } if (isset($this->request->post['city'])) { $vendor['city'] = $this->request->post['city']; } if (isset($this->request->post['postcode'])) { $vendor['postcode'] = $this->request->post['postcode']; } if (isset($this->request->post['country_id'])) { $vendor['country_id'] = (int) $this->request->post['country_id']; } if (isset($this->request->post['zone_id'])) { $vendor['zone_id'] = (int) $this->request->post['zone_id']; } $this->model_catalog_vendor->editVendor($vendor); }
public function redirect($url, $status = 302) { switch ($url) { case 'checkout/checkout': // Order process not finished throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_ORDER_PROCESS_NOT_FINISHED, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_ORDER_PROCESS_NOT_FINISHED)); break; case 'checkout/cart': // No products in cart, no stock for 1 or more product(s) or minimum quantity requirement of product not met throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_NO_PRODUCTS_STOCK_OR_MIN_QUANTITY, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_NO_PRODUCTS_STOCK_OR_MIN_QUANTITY)); break; } }
/** * Resource methods */ public function post() { // Validate if customer is logged in. This is needed because in the parent::validate the checkout/checkout route serves two purposes. if (!$this->customer->isLogged()) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_USER_NOT_LOGGED_IN, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_USER_NOT_LOGGED_IN)); } $this->request->setDefaultParameters($this->defaultParameters); $data = parent::getInternalRouteData('checkout/shipping_address/save', true); if (isset($data['redirect'])) { $this->redirect($data['redirect']); } ApiException::evaluateErrors($data); }
public function redirect($url, $status = 302) { switch ($url) { case 'checkout/checkout': // Customer is logged in or guest checkout is not allowed. throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_USER_IS_LOGGED_IN_GUEST_CHECKOUT_NOT_ALLOWED, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_USER_IS_LOGGED_IN_GUEST_CHECKOUT_NOT_ALLOWED)); break; case 'checkout/cart': // There are no products in the cart or there is no stock for 1 or more product(s). throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_NO_PRODUCTS_STOCK, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_NO_PRODUCTS_STOCK)); break; } }
protected function getVendors() { $this->load->model('catalog/vendor'); $vendors_info = $this->model_catalog_vendor->getVendors(); $vendors = array(); if (empty($vendors_info)) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_NOT_FOUND, ErrorCodes::ERRORCODE_VENDORS_NOT_FOUND, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_VENDORS_NOT_FOUND)); } foreach ($vendors_info as $data) { $vendors[] = $this->processVendor($data); } return $vendors; }
public function redirect($url, $status = 302) { switch ($url) { case 'checkout/checkout': // No shipping address is set or shipping isn't required throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_SHIPPING_ADDRESS_NOT_SET_OR_SHIPPING_NOT_NEEDED, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_SHIPPING_ADDRESS_NOT_SET_OR_SHIPPING_NOT_NEEDED)); break; case 'checkout/cart': // No products in cart, no stock for 1 or more product(s) or minimum quantity requirement of product not met throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_NO_PRODUCTS_STOCK_OR_MIN_QUANTITY, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_NO_PRODUCTS_STOCK_OR_MIN_QUANTITY)); break; } }
public function redirect($url, $status = 302) { switch ($url) { case 'checkout/checkout': // Customer not logged in throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_USER_NOT_LOGGED_IN, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_USER_NOT_LOGGED_IN)); break; case 'checkout/cart': // No products in cart, no stock for 1 or more product(s) or minimum quantity requirement of product not met throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_NO_PRODUCTS_STOCK_OR_MIN_QUANTITY, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_NO_PRODUCTS_STOCK_OR_MIN_QUANTITY)); break; } }
/** * Helper methods */ protected function getCountry($id) { $this->load->model('localisation/country'); $this->load->model('localisation/zone'); $country = $this->model_localisation_country->getCountry($id); if (empty($country)) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_NOT_FOUND, ErrorCodes::ERRORCODE_COUNTRY_NOT_FOUND, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_COUNTRY_NOT_FOUND)); } $country = $this->processCountry($country); $zones = $this->model_localisation_zone->getZonesByCountryId($id); $zones = $this->processZones($zones); $country['zones'] = $zones; return $country; }
public function redirect($url, $status = 302) { switch ($url) { case 'account/account': // Customer is already logged in throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_USER_ALREADY_LOGGED_IN, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_USER_ALREADY_LOGGED_IN)); break; case 'account/login': // Success $this->response->setHttpResponseCode(ApiResponse::HTTP_RESPONSE_CODE_OK); $this->response->output(); exit; break; } }
/** * Resource methods */ public function post() { $oldAccessToken = isset($this->request->post['access_token']) ? $this->request->post['access_token'] : NULL; $accessToken = $this->oauth->generateAccessToken($oldAccessToken); $data = array(); if ($accessToken !== false) { $data['token_type'] = 'bearer'; $data['access_token'] = $accessToken; $expiresIn = $this->config->has('api_access_token_ttl') ? (int) $this->config->get('api_access_token_ttl') : 0; $data['expires_in'] = $expiresIn; } else { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_UNAUTHORIZED, ErrorCodes::ERRORCODE_INVALID_CLIENT, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_INVALID_CLIENT)); } $this->response->setOutput($data); }
public function getRecurringDescription($id = NULL) { $this->request->post['product_id'] = $id; $this->request->post['recurring_id'] = $this->request->get['recurring_id']; if (isset($this->request->get['quantity'])) { $this->request->post['quantity'] = $this->request->get['quantity']; } $data = parent::getInternalRouteData('product/product/getRecurringDescription', true); ApiException::evaluateErrors($data); if (isset($data['success'])) { $product = array('recurring_description' => $data['success']); $this->response->setOutput($product); } else { // No description found. throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_NOT_FOUND, ErrorCodes::ERRORCODE_RECURRING_DESCRIPTION_NOT_FOUND, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_RECURRING_DESCRIPTION_NOT_FOUND)); } }
public function redirect($url, $status = 302) { switch ($url) { case 'account/login': // User not logged in throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_USER_NOT_LOGGED_IN, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_USER_NOT_LOGGED_IN)); break; case 'account/wishlist': // Success delete $this->response->setInterceptOutput(false); $this->request->get = array(); $this->get(); $this->response->setHttpResponseCode(ApiResponse::HTTP_RESPONSE_CODE_OK); $this->response->output(); exit; break; } }
/** * Helper methods */ protected function setRequestParams() { // sort if (isset($this->request->get['sort'])) { if (in_array($this->request->get['sort'], array_keys(ControllerProductManufacturerBaseAPI::$allowedSort))) { $this->request->get['sort'] = ControllerProductManufacturerBaseAPI::$allowedSort[$this->request->get['sort']]; } else { $message = sprintf(ErrorCodes::getMessage(ErrorCodes::ERRORCODE_SORT_NOT_ALLOWED), implode(', ', array_keys(self::$allowedSort))); throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_SORT_NOT_ALLOWED, $message); } } // order if (isset($this->request->get['order'])) { if (!in_array($this->request->get['order'], ControllerProductManufacturerBaseAPI::$allowedOrder)) { $message = sprintf(ErrorCodes::getMessage(ErrorCodes::ERRORCODE_ORDER_NOT_ALLOWED), implode(', ', array_keys(self::$allowedOrder))); throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_ORDER_NOT_ALLOWED, $message); } } }
public function redirect($url, $status = 302) { switch ($url) { case 'account/account': // Customer is already logged in throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_USER_ALREADY_LOGGED_IN, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_USER_ALREADY_LOGGED_IN)); break; case 'account/success': // Success // Get account data $this->response->setInterceptOutput(false); $this->request->post = array(); $this->request->server['REQUEST_METHOD'] = 'GET'; $action = new ApiAction('account/account'); $action->execute($this->registry); $this->response->setHttpResponseCode(ApiResponse::HTTP_RESPONSE_CODE_CREATED); $this->response->output(); exit; break; } }
/** * Helper methods */ protected function setRequestParams() { // sort if (isset($this->request->get['sort'])) { if (in_array($this->request->get['sort'], array_keys(ControllerProductSearchBaseAPI::$allowedSort))) { $this->request->get['sort'] = ControllerProductSearchBaseAPI::$allowedSort[$this->request->get['sort']]; } else { $message = sprintf(ErrorCodes::getMessage(ErrorCodes::ERRORCODE_SORT_NOT_ALLOWED), implode(', ', array_keys(self::$allowedSort))); throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_SORT_NOT_ALLOWED, $message); } } // order if (isset($this->request->get['order'])) { if (!in_array($this->request->get['order'], ControllerProductSearchBaseAPI::$allowedOrder)) { $message = sprintf(self::getMessage(ErrorCodes::ERRORCODE_ORDER_NOT_ALLOWED), implode(', ', array_keys(self::$allowedOrder))); throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_BAD_REQUEST, ErrorCodes::ERRORCODE_ORDER_NOT_ALLOWED, $message); } } // Empty this parameter because 'false' will give the same results as true. $this->request->convertBoolToCheckbox('description'); $this->request->convertBoolToCheckbox('sub_category'); }
public function index($args = array()) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_UNAUTHORIZED, ErrorCodes::ERRORCODE_INVALID_ACCESS_TOKEN, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_INVALID_ACCESS_TOKEN)); }
public function deleteSingleImage($id, $imageFile, $userName) { //to make it easier for caller, we accept the 500x500 cached filename too $imageFile = preg_replace('/-500x500.jpg$/', '.jpg', $imageFile); //check this vendor owns specified product $this->load->model('catalog/vdi_product'); $product = $this->model_catalog_vdi_product->getProduct((int) $id); if (!array_key_exists('vendor_id', $product) || $this->user->getVP() != (int) $product['vendor_id']) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_UNAUTHORIZED, ErrorCodes::ERRORCODE_VENDOR_NOT_ALLOWED, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_VENDOR_NOT_ALLOWED)); } //if $imageFile is main image, then set property to default ("" / null ?) if (array_key_exists('image', $product)) { $mainImageBaseName = pathinfo($product['image'])['basename']; if ($mainImageBaseName === $imageFile) { $this->model_catalog_vdi_product->setMainProductImage($id, ""); } } //remove any instance of $imageFile in aux images for this product $userFile = 'catalog/' . $userName . '/' . $imageFile; $this->model_catalog_vdi_product->removeAuxProductImage($id, $userFile); //check image is not used for any other product if (!$this->model_catalog_vdi_product->isImageInUse($userFile)) { //remove file from image catalog if (file_exists(DIR_IMAGE . $userFile)) { unlink(DIR_IMAGE . $userFile); } //don't clean up image cache - assume cleared periodically by routine maintenance } }
public function index($args = array()) { throw new ApiException(ApiResponse::HTTP_RESPONSE_CODE_NOT_FOUND, ErrorCodes::ERRORCODE_METHOD_NOT_FOUND, ErrorCodes::getMessage(ErrorCodes::ERRORCODE_METHOD_NOT_FOUND)); }