# 기본 커스터마이징 방법

{% hint style="danger" %} <mark style="color:red;">**개발 가이드를 준수하지 않아 발생하는 모든 문제는 전적으로 이용자에게 책임이 있습니다!**</mark>
{% endhint %}

## 📌 기능 확장

**고도몰에서 제공하는 기본적인 기능을 기반으로 기능 확장이 필요한 경우** \
커스터마이징 전 `개발소스관리 > 원본소스보기` 에서 고도몰 원본소스를 참고하시기 바랍니다.&#x20;

{% hint style="warning" %} <mark style="color:orange;">**아래 사항을 반드시 지켜주셔야 자동패치를 지원받으실 수 있습니다.**</mark>
{% endhint %}

* `Component/Cart/Cart.php`를 예로 들어 설명드리겠습니다.

1. 자동패치를 지원받기 위해서는 **개발소스관리 > 원본소스 보기**에서 커스터마이징 하고자 하는 소스를 다운로드 받거나 복사하기 버튼을 이용해 `data/module/Component/Cart` 디렉토리로 `Cart.php`를 복사합니다.
2. 복사한 파일의 내용은 원본과 다르며 원본 소스의 class를 **상속**받아서 사용할 수 있도록 아래와 같이 Wrapping 처리하여 제공됩니다.

   ```php
   <?php
   namespace Component\Cart;

   class Cart extends \Bundle\Component\Cart\Cart
   {
   }
   ```
3. 원본 소스의 메소드를 확장 개발하실 때, 반드시 원본 소스의 부모 메서드를 상속 받아야 자동패치가 지원됩니다.

   단, 원본 소스에 없는 사용자가 정의한 Method를 추가할 때는 해당되지 않습니다.

   ```php
   public function __construct()
   {
      parent::__construct();
   }

   public function helloWorld()
   {
      parent::helloWorld();

      /**
       * 원본 소스의 부모 메소드에서 return 값이 있을 경우
       * 자식 메소드에서도 동일하게 return 처리를 하는 것을 권장합니다.
       */ 
      return parent::helloWorld();
   }
   ```
4. 개발모드(`data/module`)에서 개발이 완료되었다면, **`개발소스관리 > 개발작업소스 보기`**&#xC5D0;서 운영소스로 적용하기 버튼을 눌러 운영 소스에 반영합니다.

{% hint style="danger" %} <mark style="color:red;">`Wrapping`</mark> <mark style="color:red;"></mark><mark style="color:red;">처리를 하지 않고 원본 그대로 사용할 경우 자동 패치가 적용되지 않습니다.</mark>
{% endhint %}

## 📌 클래스 호출

커스텀 개발 시 다른 클래스를 사용하는 경우에는\
`namespace와 class 사이에 use를 이용하여 사용하려는 class를 추가`해야 합니다.

{% code fullWidth="false" %}

```php
<?php
namespace Component\Cart;

/**
 * use 를 이용하여 추가하지 않으면
 * Component\Cart\DBTableField 라는 class 를 찾게 되며
 * 해당 class 는 존재하지 않기때문에 오류가 발생합니다.
 *
 * 실제 아래 함수의 중략된 부분에서는
 * Component\Member\Util\MemberUtil 과 Component\Mall\Mall 도 함께 사용하기 때문에
 * 모두 use 를 이용하여 추가하여야 합니다.
 */
use Component\Database\DBTableField;

class Cart extends \Bundle\Component\Cart\Cart
{
    /**
     * 아래는 Cart::saveInfoCart 함수의 일부를 커스터마이징한 예제 입니다.
     * 커스터마이징 시 해당 함수에서 DBTableField 를 사용하기 때문에 use 로 추가해야 합니다.
     */
    public function saveInfoCart($arrData)
    {
        // ... 중략

        // 장바구니 테이블 필드
        $arrExclude = [
            'memNo',
            'directCart',
        ];
        /**
         * 방법 1: use 를 통한 class 추가
         * 
         * use 를 추가하면 해당 클래스 내부에서는 DBTableField class 를 찾을 때
         * use 에 선언된 namespace 기반으로 찾습니다
         */
        $fieldData = DBTableField::setTableField('tableCart', null, $arrExclude);

        /**
         * 방법 2: namespace 를 붙여서 사용
         *
         * 1번 방법을 추천합니다. 
         * 2번을 사용하게 되면 사용할 때마다 namespace 를 작성해야합니다
         */
        $fieldData = \Component\Database\DBTableField::setTableField('tableCart', null, $arrExclude);

        // ... 중략
    }
}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devcenter-help.nhn-commerce.com/guide/tuning/source-code/basic-tuning.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
