# 상품 수정

원문: https://commerce.bootpay.ai/api/catalog/update

> 등록된 상품의 이름 · 가격 · 할인 · 카테고리 같은 정보를 고칩니다. 빠진 숫자 필드는 0 으로 저장되니 상품 상세로 읽은 현재 값을 함께 보냅니다.

v1 API 상세: [상품](https://commerce.bootpay.ai/api/reference/v1/products)

등록된 상품 정보를 수정합니다.

## API 엔드포인트

::: endpoint
method: PUT
url: https://api.bootapi.com/v1/products/:product_id
auth: [Basic Auth](https://commerce.bootpay.ai/api/server/authentication)
scope: user:product_update
:::

## 요청 파라미터

::: parameters

| 파라미터 | 타입 | 필수 | 설명 |
|---------|------|------|------|
| product_id | String | Y | 상품 ID (URL 경로) |
| name | String | N | 상품명 |
| desc | String | N | 상품 요약 설명 |
| content | String | N | 상품 상세 설명 (HTML 지원) |
| category_id | String | N | 카테고리 ID (키를 보내고 값을 비우면 해제) |
| display_price | Integer | N | 판매가 |
| tax_free_price | Integer | N | 비과세 가격 |
| use_stock | Boolean | N | 재고 관리 사용 여부 |
| stock | Integer | N | 재고 수량 |
| use_discount | Boolean | N | 할인 사용 여부 |
| discount_price | Integer | N | 할인 금액 또는 할인율. 판매가에서 이만큼 뺍니다 (`discount_price_type` 참고) |
| discount_price_type | Integer | N | 할인 단위 — `1` 퍼센트 / `2` 정액 |
| use_subscription | Boolean | N | 구독 상품 여부 |
| subscription_setting_id | String | N | 구독 설정 템플릿 ID (`save_by: 3` 필요) |
| status_display | Boolean | N | 쇼핑몰 노출 여부 |
| status_sale | Boolean | N | 판매 상태 |
| save_by | Integer | N | 저장 방식 (`1` 시스템 임시저장 / `2` 사용자 임시저장 / `3` 사용자 저장). **구독 설정 연결·검증은 `3` 일 때만 동작** |

:::

::: warning 카테고리를 비우려면 키를 보냅니다
문자열·Boolean 필드와 `category_id` 는 보내지 않으면 기존 값을 유지합니다. `category_id` 는 키를 보내고 값을 비우면 '카테고리 해제' 로 처리되니, 바꿀 생각이 없으면 키 자체를 빼고 보냅니다. 숫자 필드는 아래 예외를 확인합니다.

구독 설정(`subscription_setting_id`)을 바꿀 때는 `save_by: 3` 을 함께 보내야 반영됩니다.
:::

::: warning 알려진 문제 — 보내지 않은 숫자 필드가 0 으로 저장됩니다
지금은 숫자 필드를 빼고 보내면 기존 값이 아니라 0 으로 저장됩니다. 해당 필드는 `display_price`·`stock`·`stock_safe`·`discount_price`·`discount_price_type`·`tax_free_price`·`tax_type`·`accumulation_point`·`accumulation_point_type`·`setup_fee_value`·`setup_fee_type`·`time_sale_discount_percent`·`type` 입니다. 검색 태그는 비워지고, 심사 상태(`status_review`)는 자동 승인으로 바뀝니다. 일반 상품에서 `display_price` 를 빼면 `SERVER_ERROR`(HTTP 500)로 실패합니다.

수정할 때는 [상품 상세](https://commerce.bootpay.ai/api/catalog/detail)로 현재 값을 읽어 위 숫자 필드를 모두 함께 보냅니다. 상세 응답에서 `type`·`tax_type`·`discount_price_type` 은 문자열로 오니 숫자 값(`discount_price_type` 은 위 표, 나머지는 [커머스 Enum](https://commerce.bootpay.ai/api/reference/enum))으로 바꿔 보냅니다. 상세에 나오지 않는 `accumulation_point`·`accumulation_point_type`·`time_sale_discount_percent` 는 설정했던 값을 다시 보냅니다.
:::

## 코드 예제

::: code-group

```bash [cURL]
curl -X PUT "https://api.bootapi.com/v1/products/67c95e64d01640bb9859c629" \
  -H "Authorization: Basic {base64(client_key:secret_key)}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Enterprise 플랜",
    "display_price": 59900,
    "desc": "기업용 구독 서비스"
  }'
```

```javascript [Node.js]
import { BootpayCommerce } from '@bootpay/backend-js'

const commerce = new BootpayCommerce({
    client_key: 'your-commerce-client-key',
    secret_key: 'your-commerce-secret-key',
    mode: 'production'
})

const response = await commerce.product.update({
    product_id: '67c95e64d01640bb9859c629',
    name: 'Enterprise 플랜',
    display_price: 59900,
    desc: '기업용 구독 서비스'
})
console.log(response)
```

```python [Python]
from bootpay_backend import BootpayCommerce

commerce = BootpayCommerce(
    client_key='your-commerce-client-key',
    secret_key='your-commerce-secret-key',
    mode='production'
)

response = commerce.product.update({
    'product_id': '67c95e64d01640bb9859c629',
    'name': 'Enterprise 플랜',
    'display_price': 59900,
    'desc': '기업용 구독 서비스'
})
print(response)
```

```php [PHP]
use Bootpay\ServerPhp\BootpayCommerceApi;

$commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
$response = $commerce->product->update([
    'product_id' => '67c95e64d01640bb9859c629',
    'name' => 'Enterprise 플랜',
    'display_price' => 59900,
    'desc' => '기업용 구독 서비스'
]);
print_r($response);
```

```java [Java]
import kr.co.bootpay.store.BootpayStore;
import kr.co.bootpay.store.model.request.TokenPayload;
import kr.co.bootpay.store.model.response.BootpayStoreResponse;
import kr.co.bootpay.store.model.pojo.SProduct;

TokenPayload tp = new TokenPayload(
    "your-commerce-client-key",
    "your-commerce-secret-key"
);
BootpayStore commerce = new BootpayStore(tp).withToken();

SProduct product = new SProduct();
product.productId = "67c95e64d01640bb9859c629";
product.name = "Enterprise 플랜";
product.displayPrice = 59900.0;
// ⚠️ SProduct 의 int · boolean 필드(statusDisplay · statusSale · useStock · stock · taxType 등)는
//    비워 둬도 false · 0 으로 함께 전송되고, 서버는 그 값을 그대로 저장합니다. 바꾸지 않을 필드도
//    지금 값으로 채워야 전시 · 판매가 꺼지거나 재고가 0 이 되지 않습니다 (상품 상세로 먼저 조회).
product.statusDisplay = true;
product.statusSale = true;
product.taxType = 1;
// ⚠️ 상품 설명은 Java SDK 로 보낼 수 없습니다 — SProduct.description 은 description 키로 나가는데
//    커머스 API 는 desc 를 읽으므로 값이 버려집니다. 설명은 관리자 화면이나 REST 직접 호출로 넣습니다.

BootpayStoreResponse response = commerce.product.update(product);
System.out.println(response);
```

```ruby [Ruby]
require 'bootpay'

commerce = BootpayStore::RestClient.new(
  client_key: 'your-commerce-client-key',
  secret_key: 'your-commerce-secret-key'
)

response = commerce.product_update(
  product_id: '67c95e64d01640bb9859c629',
  name: 'Enterprise 플랜',
  display_price: 59900,
  desc: '기업용 구독 서비스'
)
puts response.data
```

```go [Go]
import "github.com/bootpay/backend-go/v2"

commerce := bootpay.NewCommerceAPI("your-commerce-client-key", "your-commerce-secret-key", nil, "production")
// Go SDK 의 CommerceProduct 에는 desc 칸이 없어 범용 Put 으로 보냅니다
response, err := commerce.Put("products/67c95e64d01640bb9859c629", map[string]interface{}{
    "name":          "Enterprise 플랜",
    "display_price": 59900,
    "desc":          "기업용 구독 서비스",
})
fmt.Println(response, err)
```

```csharp [.NET]
using Bootpay.Commerce;
using System.Net.Http;
var commerce = new BootpayCommerceApi("your-commerce-client-key", "your-commerce-secret-key");
// .NET SDK 의 CommerceProduct 에는 desc 속성이 없어 SendAsync 로 보냅니다
var response = await commerce.SendAsync("products/67c95e64d01640bb9859c629", HttpMethod.Put, new {
    name = "Enterprise 플랜",
    display_price = 59900,
    desc = "기업용 구독 서비스"
});
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

:::

## 응답

#### 성공 응답

```json
{
  "product_id": "67c95e64d01640bb9859c629",
  "save_by": 3
}
```

수정된 전체 값이 필요하면 [상품 상세](https://commerce.bootpay.ai/api/catalog/detail)를 다시 불러옵니다.

## 에러 코드

::: info 공통 에러
인증·권한 관련 에러는 [에러 코드표](https://commerce.bootpay.ai/api/reference/codes#커머스-api-인증-에러)를 참고합니다.
:::

::: error-codes

| 코드 | 메시지 | 대처 방법 |
|------|--------|-----------|
| `PRODUCT_NOT_FOUND` | 존재하지 않는 상품입니다 | product_id를 확인합니다 |
| `PRODUCT_FROZEN` | 판매금지된 상품은 편집/저장 안됩니다. 관리자에게 문의 바랍니다 | 관리자에게 문의합니다 |

:::

::: tip
문자열·Boolean 필드는 변경할 값만 보내도 됩니다. 숫자 필드는 위 초기화 동작을 확인합니다.
:::
