Hi Daveb
Been along time since I have had to re-adress this. Knowing that I have more experience with Nop it self and this companies inhouse db. I was hoping you would be able to help me on this small part of the project......??
To insert products from one db to the other we are using the Product SKU/Stockcode I have updated all the nessercay Classes to insert using the SKU. I have devised a 1-4 rule to insert a single product form one db to the other. I can manage to trigger an Insert Update and delete with a multiple product's. This is the insert trigger. I have highlighted in bold where I'm having problems on this script.
USE [cccsql]
GO
/****** Object: Trigger [dbo].[tr_insert_product_details_Stock] Script Date: 11/28/2012 12:19:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[tr_insert_product_details_Stock]
ON [dbo].[STOCK]
AFTER INSERT
AS
DECLARE @newDESCRIPTION varchar(36)
DECLARE @newPACK smallint
DECLARE @newLANE varchar(2)
DECLARE @newWHOLESALE_PRICE money
DECLARE @newRETAIL_PRICE money
DECLARE @newMRP money
DECLARE @newQTYINSTOCK float
DECLARE @newBAY varchar(3)
DECLARE @newSOURCEBARCODE varchar(13)
DECLARE @newRETAILBARCODE varchar(13)
DECLARE @newWEIGHT float
DECLARE @newQTYPACKSPERLAYER smallint
DECLARE @newQTYLAYERSPERPALLET smallint
DECLARE @newPACKTOTALPERPALLET smallint
DECLARE @newANALCODE varchar(8)
DECLARE @newSTOCKCODE varchar(9)
DECLARE @productId int
DECLARE @categoryId int
SET @newSTOCKCODE = (SELECT [STOCK CODE] FROM Inserted)
SET @newDESCRIPTION = (SELECT [DESCRIPTION] FROM Inserted)
SET @newPACK = (SELECT PACK FROM Inserted)
SET @newLANE = (SELECT LANE FROM Inserted)
SET @newWHOLESALE_PRICE = (SELECT [WHOLESALE PRICE] FROM Inserted)
SET @newRETAIL_PRICE = (SELECT [RETAIL PRICE] FROM Inserted)
SET @newMRP = (SELECT MRP FROM Inserted)
SET @newQTYINSTOCK = (SELECT [QTY IN STOCK] FROM Inserted)
SET @newBAY = (SELECT [BAY] FROM Inserted)
SET @newSOURCEBARCODE = (SELECT [SOURCE BAR CODE] FROM Inserted)
SET @newRETAILBARCODE = (SELECT [RETAIL BAR CODE] FROM Inserted)
SET @newWEIGHT = (SELECT [WEIGHT] FROM Inserted)
SET @newQTYPACKSPERLAYER = (SELECT [QTY PACKS PER LAYER] FROM Inserted)
SET @newQTYLAYERSPERPALLET = (SELECT [QTY LAYERS PER PALLET] FROM Inserted)
SET @newPACKTOTALPERPALLET = (SELECT [PACK TOTAL PER PALLET] FROM Inserted)
SET @newANALCODE = (SELECT [ANAL CODE] FROM Inserted)
IF TRIGGER_NESTLEVEL() > 1
RETURN
INSERT INTO [ConcordWholesales_new].[dbo].[Product]
([Name]
,[ShortDescription]
,[FullDescription]
,[AdminComment]
,[ProductTemplateId]
,[ShowOnHomePage]
,[MetaKeywords]
,[MetaDescription]
,[MetaTitle]
,[SeName]
,[AllowCustomerReviews]
,[ApprovedRatingSum]
,[NotApprovedRatingSum]
,[ApprovedTotalReviews]
,[NotApprovedTotalReviews]
,[Published]
,[Deleted]
,[CreatedOnUtc]
,[UpdatedOnUtc]
,[SKU]
,[CCCPack]
,[CCCLane]
,[CCCWholesalePrice]
,[CCCRetailPrice]
,[CCCMRP]
,[CCCQTYINSTOCK]
,[CCCBay]
,[CCCSourceBarcode]
,[CCCRetailBarcode]
,[CCCWeight]
,[CCCQTYPacksPerLayer]
,[CCCQTYLayersPerPallet]
,[CCCQTYTotalPerPallet]
,[CCCAnalCode])
VALUES
( @newDESCRIPTION,
NULL,
NULL,
NULL,
'3',
'0',
NULL,
NULL,
NULL,
NULL,
'1',
'0',
'0',
'0',
'0',
'1',
'0',
GETUTCDATE(),
GETUTCDATE(),
@newSTOCKCODE,
@newPACK,
@newLANE,
@newWHOLESALE_PRICE,
@newRETAIL_PRICE,
@newMRP,
@newQTYINSTOCK,
@newBAY,
@newSOURCEBARCODE,
@newRETAILBARCODE,
@newWEIGHT,
@newQTYPACKSPERLAYER,
@newQTYLAYERSPERPALLET,
@newPACKTOTALPERPALLET,
@newANALCODE)
SELECT @productId = SCOPE_IDENTITY()
SELECT @categoryId = @@IDENTITY
INSERT INTO [ConcordWholesales_new].[dbo].[Product_Category_Mapping]
([ProductId]
,[CategoryId]
,[IsFeaturedProduct]
,[DisplayOrder]
,[CCCAnalCode]
,[CCCSKU])
VALUES
(@productId
,@categoryId
,'False'
,'1'
,@newANALCODE
,@newSTOCKCODE)
SELECT @productId = SCOPE_IDENTITY()
INSERT INTO [ConcordWholesales_new].[dbo].[ProductVariant]
([ProductId]
,[Name]
,[Sku]
,[Description]
,[AdminComment]
,[ManufacturerPartNumber]
,[Gtin]
,[IsGiftCard]
,[GiftCardTypeId]
,[RequireOtherProducts]
,[RequiredProductVariantIds]
,[AutomaticallyAddRequiredProductVariants]
,[IsDownload]
,[DownloadId]
,[UnlimitedDownloads]
,[MaxNumberOfDownloads]
,[DownloadExpirationDays]
,[DownloadActivationTypeId]
,[HasSampleDownload]
,[SampleDownloadId]
,[HasUserAgreement]
,[UserAgreementText]
,[IsRecurring]
,[RecurringCycleLength]
,[RecurringCyclePeriodId]
,[RecurringTotalCycles]
,[IsShipEnabled]
,[IsFreeShipping]
,[AdditionalShippingCharge]
,[IsTaxExempt]
,[TaxCategoryId]
,[ManageInventoryMethodId]
,[StockQuantity]
,[DisplayStockAvailability]
,[DisplayStockQuantity]
,[MinStockQuantity]
,[LowStockActivityId]
,[NotifyAdminForQuantityBelow]
,[BackorderModeId]
,[AllowBackInStockSubscriptions]
,[OrderMinimumQuantity]
,[OrderMaximumQuantity]
,[DisableBuyButton]
,[DisableWishlistButton]
,[CallForPrice]
,[Price]
,[OldPrice]
,[ProductCost]
,[SpecialPrice]
,[SpecialPriceStartDateTimeUtc]
,[SpecialPriceEndDateTimeUtc]
,[CustomerEntersPrice]
,[MinimumCustomerEnteredPrice]
,[MaximumCustomerEnteredPrice]
,[Weight]
,[Length]
,[Width]
,[Height]
,[PictureId]
,[AvailableStartDateTimeUtc]
,[AvailableEndDateTimeUtc]
,[Published]
,[Deleted]
,[DisplayOrder]
,[CreatedOnUtc]
,[UpdatedOnUtc]
,[CCCAnalCode])
VALUES
(@productId
,@newDESCRIPTION
,@newSTOCKCODE
,Null
,Null
,@newRETAILBARCODE
,@newSOURCEBARCODE
,'False'
,'0'
,'False'
,Null
,'False'
,'False'
,'0'
,'False'
,'0'
,Null
,'0'
,'False'
,'0'
,'False'
,Null
,'False'
,'0'
,'0'
,'0'
,'True'
,'True'
,'0'
,'False'
,'1'
,'1'
,@newQTYINSTOCK
,'True'
,'True'
,'6'
,'6'
,'2'
,'0'
,'False'
,'1'
,'10000'
,'False'
,'True'
,'False'
,@newWHOLESALE_PRICE
,@newRETAIL_PRICE
,'0'
,NULL
,NULL
,NULL
,'False'
,'0.0'
,'0.0'
,@newWEIGHT
,isnull(@newQTYPACKSPERLAYER,'')
,isnull(@newQTYLAYERSPERPALLET,'')
,isnull(@newPACKTOTALPERPALLET,'')
,'0'
,null
,null
,'True'
,'False'
,'1'
,GETUTCDATE()
,GETUTCDATE()
,isnull(@newANALCODE,''))
The CategoryId is returning the following error
The INSERT statement conflicted with the FOREIGN KEY constraint "ProductCategory_Category". The conflict occurred in database "ConcordWholesales_new", table "dbo.Category", column 'Id'.
Part of the update trigger is as follow's but it keeps returning a null value or constraint error with the column Id.
--Update ConcordWholesales_new.dbo.Product_Category_Mapping set CategoryId=@categoryId where CategoryId in (select Id from ConcordWholesales_new.dbo.Category where @categoryId = CategoryId)
--Update ConcordWholesales_new.dbo.Product_Category_Mapping set CategoryId=@categoryId where CCCSKU=@newSTOCKCODE
--Update ConcordWholesales_new.dbo.Product_Category_Mapping set CategoryId=@categoryId where CCCSKU=@newSTOCKCODE
Hopefully you maybe able to show me where the problem is above.
The Anal Codes have a datatype of Varchar Im aware they can't be converted into Int in Sql 2008 R2. I have started to write a pluggin but Dave I was hoping there could be a quicker way of do this.
If you need me to clarify and explain further they I will humbly appreciate all help
If you could help BTW it would be humbly appreicated.
Richard