/** * @covers Mozu\Api\Resources\Commerce\Catalog\Admin\ProductResource::getProducts * @todo Implement testGetProducts(). */ public function testAddProductTypeAsync() { $apiContext = new ApiContext($this->tenantId, 0, 1, 1); //$type_resource = new ProductTypeResource($apiContext, DataViewMode::LIVE); $product_type = new ProductType(); $product_type->goodsType = 'Physical'; $product_type->masterCatalogId = 1; $product_type->productUsages = array('Standard', 'Configurable', 'Component'); $product_type->name = "test3"; $product_type->isBaseProductType = False; $result = $this->object->addProductTypeAsync($product_type)->wait(); var_dump($result); }
public function populateProductResources($p_id, $resource_type = '', $is_downloadable = 'No') { $d_arr = ProductResource::where('product_id', '=', $p_id)->where('resource_type', '=', $resource_type)->where('is_downloadable', '=', $is_downloadable)->orderBy('display_order', 'ASC')->get(array('id', 'resource_type', 'filename', 'ext', 'title', 'is_downloadable', 'width', 'height', 't_width', 't_height', 'l_width', 'l_height'))->toArray(); $resources_arr = array(); $download_filename = ''; $download_url = ''; foreach ($d_arr as $data) { if ($is_downloadable == 'Yes') { $download_filename = preg_replace('/[^0-9a-z\\.\\_\\-]/i', '', $data['title']); if (empty($download_filename)) { $download_filename = md5($p_id); } $download_url = \URL::action('Agriya\\Webshoppack\\AdminProductAddController@getProductActions') . '?action=download_file&product_id=' . $p_id; } $product_preview_url = ''; if ($data['resource_type'] == 'Audio' || $data['resource_type'] == 'Video') { $product_preview_url = ''; } $resources_arr[] = array('resource_id' => $data['id'], 'resource_type' => $data['resource_type'], 'filename_thumb' => $data['filename'] . 'T.' . $data['ext'], 'filename_large' => $data['filename'] . 'L.' . $data['ext'], 'filename_original' => $data['filename'] . '.' . $data['ext'], 'download_filename' => $download_filename . '.' . $data['ext'], 'download_url' => $download_url, 'width' => $data['width'], 'height' => $data['height'], 't_width' => $data['t_width'], 't_height' => $data['t_height'], 'l_width' => $data['l_width'], 'l_height' => $data['l_height'], 'ext' => $data['ext'], 'title' => $data['title'], 'is_downloadable' => $data['is_downloadable'], 'product_preview_url' => $product_preview_url); } return $resources_arr; }
public function postProductActions() { $action = \Input::get('action'); $p_id = \Input::get('product_id'); switch ($action) { case 'save_product_thumb_image_title': $title = \Input::get('product_image_title'); echo $this->productService->saveProductImageTitle($p_id, 'thumb', $title) ? 'success' : 'error'; $this->productService->updateProductStatus($p_id, 'Draft'); exit; break; case 'save_product_default_image_title': $title = \Input::get('product_image_title'); echo $this->productService->saveProductImageTitle($p_id, 'default', $title) ? 'success' : 'error'; $this->productService->updateProductStatus($p_id, 'Draft'); exit; break; case 'upload_product_thumb_image': $title = \Input::get('product_image_title'); $this->productAddService->product_media_type = 'image'; $this->productAddService->setAllowedUploadFormats('thumb'); $this->productAddService->setMaxUploadSize('thumb'); $file_info = array(); $file = \Input::file('uploadfile'); $upload_file_name = $file->getClientOriginalName(); $upload_status = $this->productAddService->uploadMediaFile('uploadfile', 'image', $file_info); if ($upload_status['status'] == 'success') { $this->productService->updateItemProductImage($p_id, $title, $file_info); $image_dim = CUtil::DISP_IMAGE(145, 145, $file_info['t_width'], $file_info['t_height'], true); echo json_encode(array('status' => 'success', 'server_url' => $file_info['server_url'], 'filename' => $file_info['filename_no_ext'] . 'T.' . $file_info['ext'], 't_width' => $image_dim['width'], 't_height' => $image_dim['height'], 'title' => $file_info['title'])); $this->productService->updateProductStatus($p_id, 'Draft'); } else { echo json_encode(array('status' => 'error', 'error_message' => $upload_status['error_message'], 'filename' => $upload_file_name)); } exit; break; case 'upload_item_default_image': $title = \Input::get('product_image_title'); $this->productAddService->product_media_type = 'image'; $this->productAddService->setAllowedUploadFormats('default'); $this->productAddService->setMaxUploadSize('default'); $file_info = array(); $file = \Input::file('uploadfile'); $upload_file_name = $file->getClientOriginalName(); $upload_status = $this->productAddService->uploadMediaFile('uploadfile', 'image', $file_info); if ($upload_status['status'] == 'success') { $this->productService->updateProductDefaultImage($p_id, $title, $file_info); $image_dim = CUtil::DISP_IMAGE(578, 385, $file_info['l_width'], $file_info['l_height'], true); echo json_encode(array('status' => 'success', 'server_url' => $file_info['server_url'], 'filename' => $file_info['filename_no_ext'] . 'L.' . $file_info['ext'], 't_width' => $image_dim['width'], 't_height' => $image_dim['height'], 'title' => $file_info['title'])); $this->productService->updateProductStatus($p_id, 'Draft'); } else { echo json_encode(array('status' => 'error', 'error_message' => $upload_status['error_message'], 'filename' => $upload_file_name)); } exit; break; case 'remove_default_thumb_image': echo $this->productService->removeProductThumbImage($p_id) ? 'success' : 'error'; $this->productService->updateProductStatus($p_id, 'Draft'); exit; break; case 'remove_default_image': echo $this->productService->removeProductDefaultImage($p_id) ? 'success' : 'error'; $this->productService->updateProductStatus($p_id, 'Draft'); exit; break; case 'upload_resource_preview': // images on the image tab $resource_type = \Input::get('resource_type'); $this->productAddService->setProductPreviewType($p_id); $this->productAddService->setAllowedUploadFormats('preview'); $this->productAddService->setMaxUploadSize('preview'); $resource_count = ProductResource::whereRaw('product_id = ? AND resource_type = ? ', array($p_id, $this->productAddService->product_media_type))->count(); if ($resource_count < \Config::get('webshoppack::preview_max')) { $file_info = array(); $file = \Input::file('uploadfile'); $upload_file_name = $file->getClientOriginalName(); $upload_status = $this->productAddService->uploadMediaFile('uploadfile', $this->productAddService->product_media_type, $file_info); if ($upload_status['status'] == 'success') { $resource_arr = array('product_id' => $p_id, 'resource_type' => $resource_type, 'filename' => $file_info['filename_no_ext'], 'ext' => $file_info['ext'], 'title' => $file_info['title'], 'width' => $file_info['width'], 'height' => $file_info['height'], 't_width' => $file_info['t_width'], 't_height' => $file_info['t_height'], 'l_width' => $file_info['l_width'], 'l_height' => $file_info['l_height'], 'server_url' => $file_info['server_url'], 'is_downloadable' => $file_info['is_downloadable']); $resource_id = $this->productService->insertResource($resource_arr); $image_dim = CUtil::DISP_IMAGE(74, 74, $file_info['t_width'], $file_info['t_height'], true); $this->productService->updateProductStatus($p_id, 'Draft'); echo json_encode(array('status' => 'success', 'resource_type' => ucwords($resource_type), 'server_url' => $file_info['server_url'], 'filename' => $file_info['file_thumb'], 't_width' => $image_dim['width'], 't_height' => $image_dim['height'], 'title' => $file_info['title'], 'resource_id' => $resource_id)); } else { echo json_encode(array('status' => 'error', 'error_message' => $upload_status['error_message'], 'filename' => $upload_file_name)); } } else { echo json_encode(array('status' => 'error', 'error_message' => trans('webshoppack::products_max_file'), 'filename' => '')); } exit; break; case 'save_resource_title': $row_id = \Input::get('row_id'); $resource_title = \Input::get('resource_title'); echo $this->productService->updateProductResourceImageTitle($row_id, $resource_title) ? 'success' : 'error'; $this->productService->updateProductStatus($p_id, 'Draft'); exit; break; case 'delete_resource': $row_id = \Input::get('row_id'); if ($this->productService->deleteProductResource($row_id)) { $this->productService->updateProductStatus($p_id, 'Draft'); echo json_encode(array('result' => 'success', 'row_id' => $row_id)); } else { echo json_encode(array('result' => 'failed', 'row_id' => $row_id)); } exit; break; case 'order_resource': $resourcednd_arr = \Input::get('resourcednd'); $this->productService->updateProductResourceImageDisplayOrder($resourcednd_arr); // set status is not called since only re-ordering exit; break; case 'upload_resource_file': // the download file in zip format $resource_type = 'Archive'; $this->productAddService->product_media_type = 'archive'; $this->productAddService->setAllowedUploadFormats('archive'); $this->productAddService->setMaxUploadSize('archive'); $resource_count = ProductResource::whereRaw('product_id = ? AND resource_type = ? ', array($p_id, $this->productAddService->product_media_type))->count(); if ($resource_count == 0) { $file_info = array(); $file = \Input::file('uploadfile'); $upload_file_name = $file->getClientOriginalName(); $upload_status = $this->productAddService->uploadMediaFile('uploadfile', $this->productAddService->product_media_type, $file_info, true); if ($upload_status['status'] == 'success') { $resource_arr = array('product_id' => $p_id, 'resource_type' => $resource_type, 'server_url' => $file_info['server_url'], 'filename' => $file_info['filename_no_ext'], 'ext' => $file_info['ext'], 'title' => $file_info['title'], 'width' => $file_info['width'], 'height' => $file_info['height'], 't_width' => $file_info['t_width'], 't_height' => $file_info['t_height'], 'l_width' => $file_info['l_width'], 'l_height' => $file_info['l_height'], 'is_downloadable' => $file_info['is_downloadable']); $resource_id = $this->productService->insertResource($resource_arr); if ($file_info['title'] != '') { $download_filename = preg_replace('/[^0-9a-z\\.\\_\\-)]/i', '', $file_info['title']) . '.' . $file_info['ext']; } else { $download_filename = md5($p_id) . '.' . $file_info['ext']; } echo json_encode(array('status' => 'success', 'server_url' => $file_info['server_url'], 'download_url' => \URL::action('Agriya\\Webshoppack\\AdminProductAddController@getProductActions') . '?action=download_file&product_id=' . $p_id, 'filename' => $download_filename, 't_width' => $file_info['t_width'], 't_height' => $file_info['t_height'], 'title' => $file_info['title'], 'resource_id' => $resource_id, 'is_downloadable' => $file_info['is_downloadable'])); $this->productService->updateProductStatus($p_id, 'Draft'); } else { echo json_encode(array('status' => 'error', 'error_message' => $upload_status['error_message'], 'filename' => $upload_file_name)); } } else { echo json_encode(array('status' => 'error', 'error_message' => trans('webshoppack::product.products_max_file'), 'filename' => '')); } exit; break; case 'check_user': $user_code = \Input::get('user_code'); $user_id = CUtil::getUserId($user_code); if ($user_id != "") { $user_details = CUtil::getUserDetails($user_id); if (count($user_details) > 0) { if (!$this->productAddService->checkIsShopOwner($user_id)) { echo json_encode(array('status' => 'error', 'message' => trans('webshoppack::product.invalid_seller_usercode'))); } else { $section_options = $this->productAddService->getProductUserSections($user_id); echo json_encode(array('status' => 'success', 'section_options' => $section_options)); } } else { echo json_encode(array('status' => 'error', 'message' => trans('webshoppack::product.invalid_user_code'))); } } else { echo json_encode(array('status' => 'error', 'message' => trans('webshoppack::product.invalid_user_code'))); } exit; break; } }
public function updateProductResourceImageDisplayOrder($resourcednd) { foreach ($resourcednd as $display_order => $resource_id_str) { $temp = explode("_", $resource_id_str); $resource_id = isset($temp[1]) && $temp[1] ? (int) $temp[1] : false; if ($resource_id) { ProductResource::whereRaw('id = ?', array($resource_id))->update(array('display_order' => $display_order)); } } }