def direct_purchase(self, order_info, products, connection): """ [서비스] 바로결제 Author: Ji Yoon Lee Args: order_info(dict) products(dict) Returns: {'data': get_address}; 해당 사용자의 과거 배송지를 'data'라는 키값에 넣어서 반환 """ order_dao = OrderDao() order_id = order_dao.create_order(order_info, connection) order_info['order_id'] = order_id order_log = order_dao.post_order_log(order_info, connection) order_info['order_status_type_id'] = 3 cart = [] for product in products: order_info['color'] = product['color'] order_info['size'] = product['size'] order_info['quantity'] = product['quantity'] order_info['price'] = product['price'] product_option_id = order_dao.find_product_option_id( order_info, connection) if product_option_id is None: raise ApiException(400, PRODUCT_OPTION_NOT_EXISTING) order_info['product_option_id'] = product_option_id['id'] order_info['cart_status_type_id'] = 3 # 바로결제 시도시 cart_status_type_id = 3 cart_id = order_dao.create_cart(order_info, connection) cart.append(cart_id) return {'orderId': order_id, 'items': cart}
def post_cart(self, order_info, products, connection): """ [서비스] 카트 생성하기 Author: Mark Hasung Kim Args: order_info (dict): 유저 주문 관련 정보 products (dict): 카트에 담길 products에대한 정보 (color, size, quantity, price) connection: 커넥션 Returns: True (카트에 상품이 성공적으로 담기면 True를 반환해준다) """ order_dao = OrderDao() #유저가 결제전인 order (order_status_type)를 갖고 있는지 확인 order_info['order_status_type_id'] = CURRENT_ORDER_STATUS_TYPE current_order = order_dao.find_current_order(order_info, connection) #유저가 결제전인 order를 갖고 있으면: if current_order: order_info['order_id'] = current_order['id'] order_info['created_at'] = current_order['created_at'] for product in products: # 유저가 카트에 이미 있는 product를 추가할때 카트 수량(quantity)을 업데이트 한다 order_info['color'] = product['color'] order_info['size'] = product['size'] order_info['quantity'] = product['quantity'] order_info['price'] = product['price'] existing_product_option_cart = order_dao.find_existing_product_option_cart( order_info, connection) if existing_product_option_cart: order_info['cart_id'] = existing_product_option_cart['id'] order_info['added_price'] = order_info[ 'quantity'] * existing_product_option_cart[ 'calculated_price'] order_dao.update_cart(order_info, connection) #카트 수량을 업데이트한다 order_dao.create_cart_log(order_info, connection) order_dao.update_order( order_info, connection) #Order total_price랑 updated_at을 업데이트한다 order_dao.create_order_log(order_info, connection) #create order_log #유저가 새 상품을 카트에 담을때 else: product_option = order_dao.find_product_option( order_info, connection) if not product_option: raise ApiException(400, INVALID_PRODUCT_OPTION) order_info['product_option_id'] = product_option['id'] new_cart = order_dao.create_cart( order_info, connection) #create new cart order_info['cart_id'] = new_cart order_dao.create_cart_log(order_info, connection) #create cart log get_new_cart = order_dao.get_cart(order_info, connection) order_info['added_price'] = order_info[ 'quantity'] * get_new_cart['calculated_price'] order_dao.update_order( order_info, connection) #Order total_price랑 updated_at을 업데이트한다 order_dao.create_order_log(order_info, connection) #create order_log return True #유저가 결제전인 order이 없을때: else: for product in products: order_info['color'] = product['color'] order_info['size'] = product['size'] order_info['quantity'] = product['quantity'] order_info['price'] = product['price'] new_order = order_dao.create_order(order_info, connection) order_info['order_id'] = new_order product_option = order_dao.find_product_option( order_info, connection) if not product_option: raise ApiException(400, INVALID_PRODUCT_OPTION) order_info['product_option_id'] = product_option['id'] new_cart = order_dao.create_cart(order_info, connection) order_info['cart_id'] = new_cart get_new_cart = order_dao.get_cart(order_info, connection) order_dao.create_cart_log(order_info, connection) order_info['added_price'] = order_info[ 'quantity'] * get_new_cart['calculated_price'] order_dao.update_order( order_info, connection) #Order total_price랑 updated_at을 업데이트한다 order_dao.create_order_log(order_info, connection) return True