Skip to content

Commit

Permalink
refactor: remove prefix because new api endpoint not start with same …
Browse files Browse the repository at this point in the history
…f@king prefix
  • Loading branch information
Jin committed Apr 1, 2023
1 parent 6181a6f commit 2ed0fe2
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/Resources/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

class Product extends Resource
{
protected $prefix = 'products';

public function uploadFile($file, $file_name = 'uploaded_file')
{
if ($file instanceof SplFileInfo) {
$file_name = $file->getFilename();
}

return $this->call('POST', 'upload_files', [
return $this->call('POST', 'products/upload_files', [
RequestOptions::JSON => [
'file_name' => $file_name,
'file_data' => static::dataTypeCast('file', $file),
Expand All @@ -34,7 +32,7 @@ public function uploadFile($file, $file_name = 'uploaded_file')

public function uploadImage($image, $scene = 1 /* PRODUCT_IMAGE */)
{
return $this->call('POST', 'upload_imgs', [
return $this->call('POST', 'products/upload_imgs', [
RequestOptions::JSON => [
'img_data' => static::dataTypeCast('image', $image),
'img_scene' => $scene,
Expand All @@ -44,21 +42,21 @@ public function uploadImage($image, $scene = 1 /* PRODUCT_IMAGE */)

public function createProduct($data = [])
{
return $this->call('POST', '', [
return $this->call('POST', 'products', [
RequestOptions::JSON => $data
]);
}

public function createDraftProduct($data = [])
{
return $this->call('POST', 'save_draft', [
return $this->call('POST', 'products/save_draft', [
RequestOptions::JSON => $data
]);
}

public function deleteProduct($product_ids = [])
{
return $this->call('DELETE', '/', [
return $this->call('DELETE', 'products', [
RequestOptions::JSON => [
'product_ids' => static::dataTypeCast('array', $product_ids)
]
Expand All @@ -69,7 +67,7 @@ public function editProduct($product_id, $data = [])
{
$data['product_id'] = $product_id;

return $this->call('PUT', '/', [
return $this->call('PUT', 'products', [
RequestOptions::JSON => $data
]);
}
Expand All @@ -81,7 +79,7 @@ public function updateStock($product_id, $skus = [])
'skus' => $skus
];

return $this->call('PUT', 'stocks', [
return $this->call('PUT', 'products/stocks', [
RequestOptions::JSON => $data
]);
}
Expand All @@ -93,14 +91,14 @@ public function getProductList($params = [])
'page_size' => 20,
], $params);

return $this->call('POST', 'search', [
return $this->call('POST', 'products/search', [
RequestOptions::JSON => $params
]);
}

public function getProductDetail($product_id, $need_audit_version = false)
{
return $this->call('GET', 'details', [
return $this->call('GET', 'products/details', [
RequestOptions::QUERY => [
'product_id' => $product_id,
'need_audit_version' => static::dataTypeCast('bool', $need_audit_version),
Expand All @@ -110,7 +108,7 @@ public function getProductDetail($product_id, $need_audit_version = false)

public function deactivateProduct($product_ids = [])
{
return $this->call('POST', 'inactivated_products', [
return $this->call('POST', 'products/inactivated_products', [
RequestOptions::JSON => [
'product_ids' => static::dataTypeCast('array', $product_ids),
]
Expand All @@ -119,7 +117,7 @@ public function deactivateProduct($product_ids = [])

public function activateProduct($product_ids = [])
{
return $this->call('POST', 'activate', [
return $this->call('POST', 'products/activate', [
RequestOptions::JSON => [
'product_ids' => static::dataTypeCast('array', $product_ids),
]
Expand All @@ -128,7 +126,7 @@ public function activateProduct($product_ids = [])

public function recoverDeletedProduct($product_ids = [])
{
return $this->call('POST', 'recover', [
return $this->call('POST', 'products/recover', [
RequestOptions::JSON => [
'product_ids' => static::dataTypeCast('array', $product_ids),
]
Expand All @@ -142,26 +140,26 @@ public function updatePrice($product_id, $skus)
'skus' => $skus
];

return $this->call('PUT', 'prices', [
return $this->call('PUT', 'products/prices', [
RequestOptions::JSON => $data
]);
}

public function getCategories()
{
return $this->call('GET', 'categories');
return $this->call('GET', 'products/categories');
}

public function getBrands(array $params)
{
return $this->call('GET', 'brands', [
return $this->call('GET', 'products/brands', [
RequestOptions::QUERY => $params
]);
}

public function createBrand(string $brand_name)
{
return $this->call('POST', 'brand', [
return $this->call('POST', 'products/brand', [
RequestOptions::JSON => [
'brand_name' => $brand_name
]
Expand All @@ -170,7 +168,7 @@ public function createBrand(string $brand_name)

public function getAttributes($category_id)
{
return $this->call('GET', 'attributes', [
return $this->call('GET', 'products/attributes', [
RequestOptions::QUERY => [
'category_id' => static::dataTypeCast('string', $category_id),
]
Expand All @@ -179,7 +177,7 @@ public function getAttributes($category_id)

public function getCategoryRule($category_id)
{
return $this->call('GET', 'categories/rules', [
return $this->call('GET', 'products/categories/rules', [
RequestOptions::QUERY => [
'category_id' => $category_id
]
Expand Down

0 comments on commit 2ed0fe2

Please sign in to comment.