USE [impresario] GO /****** Object: StoredProcedure [dbo].[LWP_VALIDATE_CART] Script Date: 12/02/2024 13:55:15 ******/ SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO ALTER Procedure [dbo].[LWP_VALIDATE_CART]( @sessionkey varchar(64) = null, @validate_point int = null) AS Set NoCount On /***************************************************************************************************************************** New Procedure CWR 10/25/2004 This procedure is a place to store localized code to validate web order information. It either returns an -101 error message with some error text or it simply returns. There is no resultset. The optional validate_point parameter allows code to be written for various purposes. Sample code is included. ******************************************************************************************************************************/ Declare @errmsg varchar(200), @customer_no int, @cart_count int -- validate sessionkey parameter If @sessionkey is null OR not exists (select * from t_web_session_session where sessionkey = @sessionkey) Begin select @errmsg = 'Invalid Session ID' RAISERROR(@errmsg, 11, 2) WITH SETERROR return -101 End Else Select @customer_no = customer_no from t_web_session_session where sessionkey = @sessionkey -- example of validating that the customer for this session has donated money in the past year: If @validate_point = 1 Begin If Not Exists (select * from t_contribution where customer_no = @customer_no and cont_dt > dateadd(yy, -1, getdate())) Begin select @errmsg = 'This constituent has not made a contribution in the last year' RAISERROR(@errmsg, 11, 2) WITH SETERROR return -101 End End -- example of validating that the customer for this session has put more than 3 different performances in the current session cart: If @validate_point = 2 Begin Select @cart_count = count(distinct a.perf_no) From t_web_lineitem a JOIN t_web_order b ON a.order_no = b.order_no Where b.sessionkey = @sessionkey and a.pkg_no = 0 -- only count single performances If IsNull(@cart_count, 0) < 3 Begin select @errmsg = 'Buy at least three different performances and get a special discount.' RAISERROR(@errmsg, 11, 2) WITH SETERROR return -101 End End RETURN