Woocommerce: API: μ œν’ˆ/μΉ΄ν…Œκ³ λ¦¬ μ—”λ“œν¬μΈνŠΈ ν•„ν„°κ°€ μž‘λ™ν•˜μ§€ μ•ŠμŒ

에 λ§Œλ“  2018λ…„ 05μ›” 03일  Β·  3μ½”λ©˜νŠΈ  Β·  좜처: woocommerce/woocommerce

μ „μ œ 쑰건

  • [x] 곡개 ν‹°μΌ“κ³Ό λΉ„κ³΅κ°œ ν‹°μΌ“ λͺ¨λ‘μ—μ„œ μœ μ‚¬ν•œ 문제λ₯Ό κ²€μƒ‰ν–ˆλŠ”λ° 쀑볡을 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.
  • [x] Github의 WooCommerce μ΅œμ‹  master λΈŒλžœμΉ˜μ— λŒ€ν•œ λ¬Έμ œκ°€ μ—¬μ „νžˆ μ‘΄μž¬ν•©λ‹ˆλ‹€(WordPress.org와 λ™μΌν•œ 버전이 μ•„λ‹™λ‹ˆλ‹€ !)
  • [x] 문제λ₯Ό μž¬ν˜„ν•˜κΈ° μœ„ν•΄ κ°€λŠ₯ν•œ κ°€μž₯ κ°„λ‹¨ν•œ 단계λ₯Ό 찾으렀고 μ‹œλ„ν–ˆμŠ΅λ‹ˆλ‹€.
  • [ ] μ‹€νŒ¨ν•œ ν…ŒμŠ€νŠΈλ₯Ό pull μš”μ²­μœΌλ‘œ ν¬ν•¨ν–ˆμŠ΅λ‹ˆλ‹€(선택 사항)

문제λ₯Ό μž¬ν˜„ν•˜λŠ” 단계

버그λ₯Ό μˆ˜μ •ν•˜λ €λ©΄ 버그λ₯Ό μž¬ν˜„ν•  수 μžˆμ–΄μ•Ό ν•˜λ―€λ‘œ μ„€λͺ…을 λΆ€νƒλ“œλ¦½λ‹ˆλ‹€!
  1. functions.phpμ—μ„œ woocommerce_rest_prepare_product_cat λŒ€ν•œ μƒˆ ν•„ν„°λ₯Ό λ§Œλ“­λ‹ˆλ‹€.
  2. products/categories API μ—”λ“œν¬μΈνŠΈλ₯Ό λˆ„λ₯΄μ‹­μ‹œμ˜€.

μ˜ˆμƒ/μ‹€μ œ 행동

μ΄λŸ¬ν•œ 단계λ₯Ό μˆ˜ν–‰ν•˜λ©΄ products/categories API 응닡에 μΆ”κ°€λœ 속성이 ν‘œμ‹œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

function prepare_category_images($response, $item, $request)
{

    if (empty($response->data)) {
        return $response;
    }
    $response->hello = 'world';
    return $response;
}
add_filter("woocommerce_rest_prepare_product_cat", "prepare_category_images", 10, 3);

μ΄λŠ” λ‹¨μˆœνžˆ ν‘œμ€€ λ²”μ£Ό API 응닡을 μ΄ˆλž˜ν•©λ‹ˆλ‹€.

    7 => {#349 β–Ό
      +"id": 60
      +"name": "Hooks & Hangers"
      +"slug": "hooks-hangers"
      +"parent": 0
      +"description": ""
      +"display": "default"
      +"image": {#350 β–Ά}
      +"menu_order": 7
      +"count": 27
      +"_links": {#352 β–Ά}
    }

보고 μ‹Άμ—ˆλŠ”λ°...

    7 => {#349 β–Ό
      +"id": 60
      +"name": "Hooks & Hangers"
      +"slug": "hooks-hangers"
      +"parent": 0
      +"description": ""
      +"display": "default"
      +"image": {#350 β–Ά}
      +"menu_order": 7
      +"count": 27
      +"hello": "world"
      +"_links": {#352 β–Ά}
    }

문제 격리

μ™„λ£Œλœ ν•­λͺ©μ— [x] ν‘œμ‹œ

  • [x] 이 λ²„κ·ΈλŠ” WooCommerce ν”ŒλŸ¬κ·ΈμΈμ΄ ν™œμ„±ν™”λœ κ²½μš°μ—λ§Œ λ°œμƒν•©λ‹ˆλ‹€.
  • [x] 이 λ²„κ·ΈλŠ” κΈ°λ³Έ WordPress ν…Œλ§ˆκ°€ ν™œμ„±ν™”λ˜μ–΄ μžˆκ±°λ‚˜ Storefrontμ—μ„œ λ°œμƒν•©λ‹ˆλ‹€.
  • [x] μœ„μ˜ 단계λ₯Ό μ‚¬μš©ν•˜μ—¬ 이 버그λ₯Ό μΌκ΄€λ˜κ²Œ μž¬ν˜„ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ›Œλ“œν”„λ ˆμŠ€ ν™˜κ²½

`
### WordPress Environment ###

Home URL: http://wp.website.test
Site URL: http://wp.website.test
WC Version: 3.3.0
Log Directory Writable: βœ”
WP Version: 4.9.5
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: βœ”
WP Cron: βœ”
Language: en_GB
External object cache: –

### Server Environment ###

Server Info: nginx/1.12.2
PHP Version: 7.1.12
PHP Post Max Size: 128 MB
PHP Time Limit: 60
PHP Max Input Vars: 1000
cURL Version: 7.54.0
LibreSSL/2.0.20

SUHOSIN Installed: –
MySQL Version: 5.7.20
Max Upload Size: 128 MB
Default Timezone is UTC: βœ”
fsockopen/cURL: βœ”
SoapClient: βœ”
DOMDocument: βœ”
GZip: βœ”
Multibyte String: βœ”
Remote Post: βœ”
Remote Get: βœ”

### Database ###

WC Database Version: 3.3.0
WC Database Prefix: wp_
Total Database Size: 49.23MB
Database Data Size: 29.02MB
Database Index Size: 20.21MB
wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB
wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB
wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB
wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.05MB
wp_woocommerce_order_items: Data: 0.30MB + Index: 0.11MB
wp_woocommerce_order_itemmeta: Data: 2.52MB + Index: 3.03MB
wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB
wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.05MB
wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB
wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.05MB
wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB
wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB
wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB
wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB
wp_commentmeta: Data: 0.02MB + Index: 0.03MB
wp_comments: Data: 2.52MB + Index: 1.23MB
wp_links: Data: 0.02MB + Index: 0.02MB
wp_options: Data: 7.47MB + Index: 2.47MB
wp_postmeta: Data: 11.52MB + Index: 11.03MB
wp_posts: Data: 3.52MB + Index: 1.20MB
wp_rac_abandoncart: Data: 0.08MB + Index: 0.00MB
wp_rac_email_logs: Data: 0.02MB + Index: 0.00MB
wp_rac_templates_email: Data: 0.02MB + Index: 0.00MB
wp_termmeta: Data: 0.06MB + Index: 0.03MB
wp_terms: Data: 0.05MB + Index: 0.03MB
wp_term_relationships: Data: 0.34MB + Index: 0.30MB
wp_term_taxonomy: Data: 0.06MB + Index: 0.03MB
wp_usermeta: Data: 0.14MB + Index: 0.14MB
wp_users: Data: 0.02MB + Index: 0.05MB
wp_wc_download_log: Data: 0.02MB + Index: 0.03MB
wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB
wp_woocommerce_termmeta: Data: 0.02MB + Index: 0.03MB
wp_yith_wcwl: Data: 0.02MB + Index: 0.05MB
wp_yith_wcwl_lists: Data: 0.02MB + Index: 0.03MB

### Post Type Counts ###

acf-field: 1
acf-field-group: 1
attachment: 2938
customize_changeset: 1
mc4wp-form: 1
ml-slider: 1
nav_menu_item: 19
page: 25
post: 9
product: 772
product_variation: 341
revision: 82
shop_coupon: 11
shop_order: 2216
shop_order_refund: 8
sidebar: 1

### Security ###

Secure connection (HTTPS): ❌Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates.
Hide errors from visitors: ❌Error messages should not be shown to visitors.

### Active Plugins (5) ###

Advanced Custom Fields PRO: by Elliot Condon – 5.6.10
Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 3.0.2
WooCommerce POS: by kilbot – 0.4.18
WooCommerce Shipping Pro: by WooForce – 2.1.1 – Not tested with the active version of WooCommerce
WooCommerce: by Automattic – 3.4.0-dev

### Settings ###

API Enabled: –
Force SSL: –
Currency: GBP (Β£)
Currency Position: left
Thousand Separator: ,
Decimal Separator: .
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)


### WC Pages ###

Shop base: #4 - /shop/
Cart: #5 - /my-account/cart/
Checkout: #6 - /my-account/checkout/
My account: #7 - /my-account/
Terms and conditions: #254 - /information/terms-conditions/

### Theme ###

Name: Mench Living
Version: 1.0
Author URL: https://youi.design
Child Theme: βœ”
Parent Theme Name: Storefront
Parent Theme Version: 2.2.8
Parent Theme Author URL: https://woocommerce.com/
WooCommerce Support: βœ”

### Templates ###

Overrides: –
`

can't reproduce

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

이 ν•„ν„°λ₯Ό μ‚¬μš©ν•˜μ—¬ μš©μ–΄ 데이터λ₯Ό μˆ˜μ •ν•˜λ €λ©΄ $response μ•„λ‹ˆλΌ $response->data λ₯Ό μ‘°μž‘ν•΄μ•Ό ν•©λ‹ˆλ‹€. μ•„λž˜ μ½”λ“œλŠ” μ œκ³΅ν•œ μ˜ˆμ œμ—μ„œ μ›ν•˜λŠ” 좜λ ₯을 생성해야 ν•©λ‹ˆλ‹€.

function prepare_category_images( $response, $item, $request ) {
    if ( empty( $response->data ) ) {
        return $response;
    }

    $response->data['hello'] = 'world';
    return $response;
}
add_filter( 'woocommerce_rest_prepare_product_cat', 'prepare_category_images', 10, 3 );

cc @claudiosanches ν•„ν„° λ¬Έμ„œλ₯Ό κ°œμ„ ν•˜μ—¬ 이것을 더 λͺ…ν™•ν•˜κ²Œ ν•˜κ±°λ‚˜ λ‚΄κ°€ λˆ„λ½λœ 것이 μžˆλŠ” 경우λ₯Ό λŒ€λΉ„ν•˜μ—¬.

λͺ¨λ“  3 λŒ“κΈ€

참고둜 μ‚¬μ΄νŠΈμ˜ API에 도달할 λ•Œ debug.log에 였λ₯˜κ°€ ν‘œμ‹œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

이 ν•„ν„°λ₯Ό μ‚¬μš©ν•˜μ—¬ μš©μ–΄ 데이터λ₯Ό μˆ˜μ •ν•˜λ €λ©΄ $response μ•„λ‹ˆλΌ $response->data λ₯Ό μ‘°μž‘ν•΄μ•Ό ν•©λ‹ˆλ‹€. μ•„λž˜ μ½”λ“œλŠ” μ œκ³΅ν•œ μ˜ˆμ œμ—μ„œ μ›ν•˜λŠ” 좜λ ₯을 생성해야 ν•©λ‹ˆλ‹€.

function prepare_category_images( $response, $item, $request ) {
    if ( empty( $response->data ) ) {
        return $response;
    }

    $response->data['hello'] = 'world';
    return $response;
}
add_filter( 'woocommerce_rest_prepare_product_cat', 'prepare_category_images', 10, 3 );

cc @claudiosanches ν•„ν„° λ¬Έμ„œλ₯Ό κ°œμ„ ν•˜μ—¬ 이것을 더 λͺ…ν™•ν•˜κ²Œ ν•˜κ±°λ‚˜ λ‚΄κ°€ λˆ„λ½λœ 것이 μžˆλŠ” 경우λ₯Ό λŒ€λΉ„ν•˜μ—¬.

λ„μ™€μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€ @rodrigoprimo

이 μ½”λ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ μΉ΄ν…Œκ³ λ¦¬μ˜ 이미지 썸넀일을 woocommerce API μ—”λ“œν¬μΈνŠΈμ— μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.

/**
 * Add image sizes to product category API index
 *
 */

function prepare_category_images($response, $item, $request)
{
    global $_wp_additional_image_sizes;

    if (empty($response->data)) {
        return $response;
    }

    $id = $response->data['image']['id'];
    foreach ($_wp_additional_image_sizes as $size => $value) {
        $image_info = wp_get_attachment_image_src($id, $size);
        $response->data["image"][$size] = $image_info[0];
    }

    return $response;
}

add_filter("woocommerce_rest_prepare_product_cat", "prepare_category_images", 10, 3);

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰