@@ -93,6 +93,15 @@ type ProductItemPropType = {
9393 startPurchaseProcess : ( oneItemOrderData : ShopSchemas . CartItemAppendRequest ) => void ;
9494} ;
9595
96+ /**
97+ * 상품 가격과 옵션 가격을 합산하여 상품의 총 가격이 0인지 확인합니다.
98+ * @param p 상품 객체
99+ * @returns 상품의 가격이 0 이하인 경우 true, 그렇지 않으면 false
100+ */
101+ const isZeroPriceProduct = ( p : ShopSchemas . Product ) : boolean => {
102+ return p . price + p . option_groups . reduce ( ( sum , group ) => sum + group . options . reduce ( ( s , o ) => s + ( o . additional_price || 0 ) , 0 ) , 0 ) === 0 ;
103+ } ;
104+
96105const ProductItem : React . FC < ProductItemPropType > = ( { disabled : rootDisabled , language, product, startPurchaseProcess, onAddToCartSuccess } ) => {
97106 const navigate = useNavigate ( ) ;
98107 const [ , forceRender ] = React . useReducer ( ( x ) => x + 1 , 0 ) ;
@@ -210,7 +219,7 @@ const ProductItem: React.FC<ProductItemPropType> = ({ disabled: rootDisabled, la
210219
211220 const addItemToCart = ( ) => {
212221 const formData = getCartAppendRequestPayload ( product , getValues ( ) ) ;
213- if ( getTotalProductPrice ( getValues ( ) ) <= 0 ) {
222+ if ( ! isZeroPriceProduct ( product ) && getTotalProductPrice ( getValues ( ) ) <= 0 ) {
214223 alert ( cannotAddToCartZeroPriceProductStr ) ;
215224 return ;
216225 }
@@ -238,7 +247,7 @@ const ProductItem: React.FC<ProductItemPropType> = ({ disabled: rootDisabled, la
238247 } ;
239248 const onOrderOneItemButtonClick = ( ) => {
240249 const formData = getCartAppendRequestPayload ( product , getValues ( ) ) ;
241- if ( getTotalProductPrice ( getValues ( ) ) <= 0 ) {
250+ if ( ! isZeroPriceProduct ( product ) && getTotalProductPrice ( getValues ( ) ) <= 0 ) {
242251 alert ( cannotPurchaseZeroPriceProductStr ) ;
243252 return ;
244253 }
0 commit comments