spLoadRecord_ShoppingCart_ByClientUsersID
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ShoppingCartPartID | int | IN | |
@ClientUsersID | int | IN | |
@MergeCookieID | uniqueidentifier | IN |
Definition
Copy
CREATE procedure [dbo].[spLoadRecord_ShoppingCart_ByClientUsersID](@ShoppingCartPartID int, @ClientUsersID int, @MergeCookieID uniqueidentifier) as
exec dbo.[spPurgeExpiredShoppingCarts]
declare @OldShoppingCartID int;
select top 1
@OldShoppingCartID = ID
from dbo.ShoppingCart
where CookieID = @MergeCookieID
and ClientUsersID is null
and ShoppingCartPartID = @ShoppingCartPartID;
declare @NewShoppingCartID int;
select top 1
@NewShoppingCartID = ID
from dbo.ShoppingCart
where ClientUsersID = @ClientUsersID
and ShoppingCartPartID = @ShoppingCartPartID;
if @OldShoppingCartID is not null begin
if @NewShoppingCartID is null begin
set @NewShoppingCartID = @OldShoppingCartID;
update dbo.ShoppingCart set
ClientUsersID = @ClientUsersID,
CookieID = '00000000-0000-0000-0000-000000000000'
where ID = @OldShoppingCartID;
end else begin
update dbo.ShoppingCartDonation set ShoppingCartID = @NewShoppingCartID where ShoppingCartID = @OldShoppingCartID;
update dbo.ShoppingCartEvent set ShoppingCartID = @NewShoppingCartID where ShoppingCartID = @OldShoppingCartID;
update dbo.ShoppingCartMembership set ShoppingCartID = @NewShoppingCartID where ShoppingCartID = @OldShoppingCartID;
end
end
-- try to keep the columns returned consistent across these SPs:
-- spLoadRecord_ShoppingCart, spLoadRecord_ShoppingCart_ByClientUsersID, spLoadRecord_ShoppingCart_ByCookieID
select
ID,
ShoppingCartPartID,
ClientUsersID,
CreateDate,
UpdateDate,
CookieID
from dbo.ShoppingCart
where ID = @NewShoppingCartID;
return;