Hi Mazhar. It looks like the trigger approach as outlined may not work because of a coding semi-deficiency in core AC Code. My trigger tries to insert a record into OrderItemInputs when a record is added to OrderItems. When it does that, I get the following error:
Code: Select all
Error running SQL: INSERT INTO ac_OrderItemInputs (OrderItemId, Name, InputValue) VALUES (@OrderItemId, @Name, @InputValue); SELECT @@IDENTITY
System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "ac_OrderItems_ac_OrderItemInputs_FK1". The conflict occurred in database "StorkGiftsDev", table "dbo.ac_OrderItems", column 'OrderItemId'.
My first thought is that this is because the OrderItems record isn't "committed" yet so the OrderItemInputs record isn't finding the correct OrderItemId. Even if this is the case, my trigger will still cause problems because of how the calling AC code is written using SELECT @@IDENTITY. Any trigger that causes an identity record to be inserted will through off the value returned by @@IDENTITY which is just the last identity value,
not the last identity value for ac_OrderItems. A better choice would be SELECT SCOPE_IDENTITY() which would produce the correct value for AC code without being affected by most trigger code. (For those who want info on alternative IDENTITY functions, see this link:
http://www.sqlteam.com/article/alternat ... erver-2000).
I wanted to mention this since you may want to modify your core code to be more customizable in a future release.
I think I can still do what I want with product templates and triggers. I just need to always include a standard template field for every product. That way it will always exist in BasketItemInputs and OrderItemInputs and I can just put a trigger in on those two tables and update the value. No need to insert records and create nasty identity side effects.
While I am glad that AC is customizable and lets us developers make changes, there are definitely areas where having generic Developer fields would be a huge help. Or even a Visibility flag on certain entities. I've seen posts about custom input fields due to the fact that inputs are either Customer or Merchant and visible by default. It would be great to have a third type for us developers or at least the Visibility flag. Please know this is intended as constructive criticism. I way prefer having a product that might delivers 90% of what I need but 100% with customization than one that delivers 99% of what I need but no way to get that last 1%.
Regards.