ALTER TABLE `mm_EventAttendee` DROP FOREIGN KEY `mm_EventAttendee_ibfk_9`;
ALTER TABLE `mm_EventAttendee` ADD CONSTRAINT `mm_EventAttendee_ibfk_9` FOREIGN KEY (`cartId`) REFERENCES `mm_Cart`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

SET @template := 'cartNotEmptyToUser';
SET @categoryId := 7;
SET @sorter := IFNULL((SELECT MAX(sorter) FROM mm_Settings WHERE idCategory = @categoryId), -1) + 1;

INSERT INTO `mm_Settings` (`name`, `idCategory`, `fieldType`, `label`, `value`, `options`, `description`, `required`, `system`, `sorter`, `added`, `changed`) VALUES
(CONCAT(@template, 'Header'), @categoryId, 'header', '', 'Uncompleted purchase (User Notification)', '', '', 'n', 'n', @sorter, NOW(), NOW()),
(CONCAT(@template, 'Subject'), @categoryId, 'text', 'Subject', 'Uncompleted purchase on the MMUA website! ', '', '', 'y', 'n', @sorter + 1, NOW(), NOW()),
(CONCAT(@template, 'From'), @categoryId, 'text', 'From Email Address &nbsp; <span class="label_description">If you leave this field empty - the From Email Address will be the same as the one in General Settings.</span>', '', '', '', 'n', 'n', @sorter + 2, NOW(), NOW()),
(CONCAT(@template, 'Body'), @categoryId, 'HtmlEditor', 'Message Body', '<p>Dear {memberOfficialFullName},</p><p>You have an uncompleted purchase on the MMUA website.</p><p>{cartItems}</p><p>Click <a href="{cartUrl}">here</a> to view your shopping cart</p>', '', 'Constants: {memberOfficialFullName} {cartItems} {cartUrl}', 'y', 'n', @sorter + 3, NOW(), NOW());

INSERT INTO `mm_SettingsOptions` (`name`, `variable`, `value`, `type`, `sorter`) VALUES (CONCAT(@template, 'Body'), 'mode', 'view', 'string', NULL);
