ALTER TABLE ProductsCustomData ADD INDEX (ResourceId);

INSERT INTO ItemTypes VALUES (13, 'In-Commerce', 'ord', 'Orders', 'OrderNumber', 'PortalUserId', NULL, NULL, '', 0, '', '', 'Order');

INSERT INTO PermissionConfig (PermissionName, Description, ErrorMessage, ModuleId) VALUES ('PRODUCT.ADD', 'lu_PermName_Product.Add_desc', 'lu_PermName_Product.Add_error', 'In-Commerce');
INSERT INTO PermissionConfig (PermissionName, Description, ErrorMessage, ModuleId) VALUES ('PRODUCT.DELETE', 'lu_PermName_Product.Delete_desc', 'lu_PermName_Product.Delete_error', 'In-Commerce');
INSERT INTO PermissionConfig (PermissionName, Description, ErrorMessage, ModuleId) VALUES ('PRODUCT.MODIFY', 'lu_PermName_Product.Modify_desc', 'lu_PermName_Product.Modify_desc', 'In-Commerce');
INSERT INTO PermissionConfig (PermissionName, Description, ErrorMessage, ModuleId) VALUES ('PRODUCT.VIEW', 'lu_PermName_Product.View_desc', 'lu_PermName_Product.View_error', 'In-Commerce');

UPDATE ItemTypes SET ClassName = 'OrdersItem', CreatorField = '' WHERE ItemType = 13;
UPDATE ItemTypes SET ClassName = 'ProductsItem' WHERE ItemType = 11;

INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.advanced:approve', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.advanced:deny', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.advanced:archive', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.advanced:place', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.advanced:process', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.advanced:ship', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:orders.advanced:reset_to_pending', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:discounts.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:discounts.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:discounts.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:discounts.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:discounts.advanced:approve', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:discounts.advanced:decline', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:coupons.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:coupons.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:coupons.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:coupons.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:coupons.advanced:approve', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:coupons.advanced:decline', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:manufacturers.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:manufacturers.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:manufacturers.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:manufacturers.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:currencies.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:currencies.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:currencies.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:currencies.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:currencies.advanced:move_up', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:currencies.advanced:move_down', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:currencies.advanced:update_rate', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:currencies.advanced:set_primary', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping.advanced:approve', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping.advanced:decline', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping_quote_engines.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping_quote_engines.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping_quote_engines.advanced:approve', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:shipping_quote_engines.advanced:decline', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:payment_types.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:payment_types.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:payment_types.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:payment_types.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:taxes.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:taxes.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:taxes.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:taxes.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliates.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliates.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliates.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliates.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliates.advanced:approve', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliates.advanced:decline', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_plans.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_plans.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_plans.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_plans.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_plans.advanced:approve', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_plans.advanced:decline', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_plans.advanced:set_primary', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.advanced:approve', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.advanced:decline', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.advanced:set_primary', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.advanced:move_up', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:affiliate_payment_types.advanced:move_down', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:general.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:general.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:output.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:output.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:search.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:search.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:incommerce_configemail.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:incommerce_configemail.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:contacts.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:contacts.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:configuration_custom.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:configuration_custom.add', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:configuration_custom.edit', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:configuration_custom.delete', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:paymentlog.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:downloadlog.view', 11, 1, 1, 0);
INSERT INTO Permissions (Permission, GroupId, PermissionValue, Type, CatId) VALUES ('in-commerce:downloadlog.delete', 11, 1, 1, 0);

UPDATE ConfigurationAdmin SET ValueList = '0=lu_none,<SQL>SELECT DestName AS OptionName, DestAbbr AS OptionValue FROM <PREFIX>StdDestinations WHERE DestParentId IS NULL Order BY OptionName</SQL>' WHERE VariableName IN ('Comm_Country', 'Comm_Shipping_Country');
UPDATE ConfigurationAdmin SET ValueList = '=la_none,Name=la_fld_Title,SKU=la_fld_SKU,Manufacturer=la_fld_Manufacturer,Price=la_fld_Price,CreatedOn=la_fld_CreatedOn,Modified=la_fld_Modified,Qty=la_fld_Qty,<SQL>SELECT Prompt AS OptionName, CONCAT("cust_", FieldName) AS OptionValue FROM <PREFIX>CustomField WHERE (Type = 11) AND (IsSystem = 0)</SQL>' WHERE VariableName IN ('product_OrderProductsBy', 'product_OrderProductsThenBy');

UPDATE Modules SET Version = '1.1.0' WHERE Name = 'In-Commerce';