# ===== v 4.3.9 =====

INSERT INTO ImportScripts VALUES (DEFAULT, 'Products from CSV file [In-Commerce]', '', 'p', 'In-Commerce', '', 'CSV', '1');

ALTER TABLE Products ADD OnSale TINYINT(1) NOT NULL default '0' AFTER Featured, ADD INDEX (OnSale);

UPDATE Phrase SET Module = 'In-Commerce' WHERE Phrase IN ('lu_comm_Images', 'lu_comm_ImagesHeader');

# ===== v 5.0.0 =====
UPDATE Category SET Template = '/in-commerce/designs/section' WHERE Template = 'in-commerce/store/category';
UPDATE Category SET CachedTemplate = '/in-commerce/designs/section' WHERE CachedTemplate = 'in-commerce/store/category';

UPDATE ConfigurationValues SET VariableValue = '/in-commerce/designs/section' WHERE VariableName = 'p_CategoryTemplate';
UPDATE ConfigurationValues SET VariableValue = 'in-commerce/designs/detail' WHERE VariableName = 'p_ItemTemplate';

DELETE FROM PersistantSessionData WHERE VariableName IN ('affil_columns_.', 'ap_columns_.', 'apayments_columns_.', 'apayments.log_columns_.', 'd_columns_.', 'coup_columns_.', 'file_columns_.', 'po_columns_.', 'z_columns_.', 'tax_columns_.');
DELETE FROM PersistantSessionData WHERE VariableName LIKE '%ord.%';

INSERT INTO Permissions VALUES (DEFAULT, 'in-commerce:products.view', 11, 1, 1, 0);
INSERT INTO Permissions VALUES (DEFAULT, 'in-commerce:setting_folder.view', 11, 1, 1, 0);

INSERT INTO ShippingQuoteEngines VALUES (DEFAULT, 'USPS.com', 0, 0, 0, 'a:21:{s:12:"AccountLogin";s:0:"";s:15:"AccountPassword";N;s:10:"UPSEnabled";N;s:10:"UPSAccount";s:0:"";s:11:"UPSInvoiced";N;s:10:"FDXEnabled";N;s:10:"FDXAccount";s:0:"";s:10:"DHLEnabled";N;s:10:"DHLAccount";s:0:"";s:11:"DHLInvoiced";N;s:10:"USPEnabled";N;s:10:"USPAccount";s:0:"";s:11:"USPInvoiced";N;s:10:"ARBEnabled";N;s:10:"ARBAccount";s:0:"";s:11:"ARBInvoiced";N;s:10:"1DYEnabled";N;s:10:"2DYEnabled";N;s:10:"3DYEnabled";N;s:10:"GNDEnabled";N;s:10:"ShipMethod";N;}', 'USPS');

INSERT INTO ConfigurationAdmin VALUES ('Comm_CompanyName', 'la_Text_ContactsGeneral', 'la_text_CompanyName', 'text', NULL, NULL, 10.01, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'Comm_CompanyName', '', 'In-Commerce', 'in-commerce:contacts');

UPDATE ConfigurationAdmin SET prompt = 'la_text_StoreName', DisplayOrder = 10.02 WHERE VariableName = 'Comm_StoreName';

INSERT INTO ConfigurationAdmin VALUES ('Comm_Contacts_Name', 'la_Text_ContactsGeneral', 'la_text_ContactName', 'text', NULL, NULL, 10.03, 0, 0);
INSERT INTO ConfigurationValues VALUES (DEFAULT, 'Comm_Contacts_Name', '', 'In-Commerce', 'in-commerce:contacts');

UPDATE ConfigurationAdmin SET DisplayOrder = 10.04 WHERE VariableName = 'Comm_Contacts_Phone';
UPDATE ConfigurationAdmin SET DisplayOrder = 10.05 WHERE VariableName = 'Comm_Contacts_Fax';
UPDATE ConfigurationAdmin SET DisplayOrder = 10.06 WHERE VariableName = 'Comm_Contacts_Email';
UPDATE ConfigurationAdmin SET DisplayOrder = 10.07 WHERE VariableName = 'Comm_Contacts_Additional';

DELETE FROM Phrase WHERE Phrase IN ('la_fld_ManufacturerId', 'la_fld_DiscountId', 'la_fld_CouponId', 'la_fld_AffiliatePlanId', 'la_fld_AffiliateId', 'la_fld_ZoneId', 'la_fld_EngineId', 'la_fld_ShippingId', 'la_fld_ProductId', 'la_fld_OptionId', 'la_fld_CurrencyId', 'la_fld_Zone_Name');

UPDATE Phrase SET Module = 'In-Commerce' WHERE ((Phrase LIKE '%Product%' OR Phrase LIKE '%Shipping%' OR Phrase LIKE '%Coupon%' OR Phrase LIKE '%Discount%' OR Phrase LIKE '%Report%' OR Phrase LIKE '%Currency%' OR Phrase LIKE '%Cart%') AND (Module = 'Core'));

# ===== v 5.0.1 =====
UPDATE ConfigurationValues SET VariableValue = 'in-commerce/products/product_detail' WHERE VariableName = 'p_ItemTemplate';

UPDATE ConfigurationAdmin SET ValueList = '1=la_opt_Session,2=la_opt_PermanentCookie' WHERE VariableName = 'Comm_AffiliateStorageMethod';

UPDATE ConfigurationAdmin SET ValueList = 'ASC=la_common_Ascending,DESC=la_common_Descending'
WHERE VariableName IN ('product_OrderProductsByDir', 'product_OrderProductsThenByDir');

UPDATE ConfigurationAdmin SET ValueList = '1=la_opt_PriceCalculationByPrimary,2=la_opt_PriceCalculationByOptimal'
WHERE VariableName = 'Comm_PriceBracketCalculation';

UPDATE ConfigurationAdmin
SET ValueList = '1=la_opt_Sec,60=la_opt_Min,3600=la_opt_Hour,86400=la_opt_Day,604800=la_opt_Week,2419200=la_opt_Month,29030400=la_opt_Year'
WHERE VariableName IN ('product_ReviewDelay_Interval', 'product_RatingDelay_Interval');

UPDATE CustomField SET FieldLabel = 'la_fld_cust_p_ItemTemplate', Prompt = 'la_fld_cust_p_ItemTemplate' WHERE FieldName = 'p_ItemTemplate';

UPDATE Events SET Type = 1 WHERE Event = 'BACKORDER.FULLFILL';

UPDATE ConfigurationAdmin SET ValueList = 'style="width: 50px;"' WHERE VariableName IN ('product_RatingDelay_Value', 'product_ReviewDelay_Value');

# ===== v 5.0.2-B1 =====
ALTER TABLE AffiliatePayments
	CHANGE Comment Comment text NULL,
	CHANGE PaymentDate PaymentDate INT(10) UNSIGNED NULL DEFAULT NULL;

ALTER TABLE AffiliatePaymentTypes CHANGE Description Description text NULL;

ALTER TABLE Affiliates
	CHANGE Comments Comments text NULL,
	CHANGE CreatedOn CreatedOn INT(11) NULL DEFAULT NULL;

ALTER TABLE Manufacturers CHANGE Description Description text NULL;

ALTER TABLE Orders
	CHANGE UserComment UserComment text NULL,
	CHANGE AdminComment AdminComment text NULL,
	CHANGE GWResult1 GWResult1 MEDIUMTEXT NULL,
	CHANGE GWResult2 GWResult2 MEDIUMTEXT NULL,
	CHANGE OrderDate OrderDate INT(10) UNSIGNED NULL DEFAULT NULL,
	CHANGE PaymentExpires PaymentExpires INT(10) UNSIGNED NULL DEFAULT NULL;

ALTER TABLE PaymentTypes CHANGE PortalGroups PortalGroups text NULL;
ALTER TABLE ProductOptionCombinations CHANGE Combination Combination text NULL;

ALTER TABLE Products
	CHANGE ShippingLimitation ShippingLimitation text NULL,
	CHANGE PackageContent PackageContent MEDIUMTEXT NULL;

ALTER TABLE ShippingQuoteEngines CHANGE Properties Properties text NULL;
ALTER TABLE ShippingType CHANGE PortalGroups PortalGroups text NULL;

ALTER TABLE ProductFiles
	CHANGE ProductId ProductId INT(11) NOT NULL DEFAULT '0',
	CHANGE `Name` `Name` VARCHAR(255) NOT NULL DEFAULT '',
	CHANGE Version Version VARCHAR(100) NOT NULL DEFAULT '',
	CHANGE FilePath FilePath VARCHAR(255) NOT NULL DEFAULT '',
	CHANGE RealPath RealPath VARCHAR(255) NOT NULL DEFAULT '',
	CHANGE Size Size INT(11) NOT NULL DEFAULT '0',
	CHANGE AddedOn AddedOn INT(11) NULL DEFAULT NULL;

ALTER TABLE UserFileAccess
	CHANGE ProductId ProductId INT( 11 ) NOT NULL DEFAULT '0',
	CHANGE PortalUserId PortalUserId INT( 11 ) NOT NULL DEFAULT '0';

ALTER TABLE GatewayConfigFields CHANGE ValueList ValueList MEDIUMTEXT NULL;

ALTER TABLE Currencies
	CHANGE `Status` `Status` SMALLINT(6) NOT NULL DEFAULT '1',
	CHANGE Modified Modified INT(11) NULL DEFAULT NULL;

ALTER TABLE GiftCertificates CHANGE `Status` `Status` TINYINT(1) NOT NULL DEFAULT '2';

ALTER TABLE UserDownloads
	CHANGE StartedOn StartedOn INT(11) NULL DEFAULT NULL,
	CHANGE EndedOn EndedOn INT(11) NULL DEFAULT NULL;

# ===== v 5.0.2-B2 =====

# ===== v 5.0.2-RC1 =====

# ===== v 5.0.2 =====

# ===== v 5.0.3-B1 =====
UPDATE Phrase
SET PhraseType = 1
WHERE Phrase IN (
	'la_ship_All_Together', 'la_ship_Backorders_Upon_Avail', 'la_ship_Backorder_Separately',
	'lu_ship_Shipment', 'lu_ship_ShippingType'
);

# ===== v 5.0.3-B2 =====

# ===== v 5.0.3-RC1 =====

# ===== v 5.0.3 =====

# ===== v 5.1.0-B1 =====
UPDATE Modules SET Path = 'modules/in-commerce/' WHERE `Name` = 'In-Commerce';

UPDATE ConfigurationValues
SET ValueList = '0=lu_none||<SQL+>SELECT l%3$s_Name AS OptionName, IsoCode AS OptionValue FROM <PREFIX>CountryStates WHERE Type = 1 ORDER BY OptionName</SQL>'
WHERE ValueList = '0=lu_none||<SQL>SELECT DestName AS OptionName, DestAbbr AS OptionValue FROM <PREFIX>StdDestinations WHERE DestParentId IS NULL Order BY OptionName</SQL>';

ALTER TABLE SiteDomains
	ADD COLUMN BillingCountry varchar(3) NOT NULL DEFAULT '',
	ADD COLUMN ShippingCountry varchar(3) NOT NULL DEFAULT '',
	ADD COLUMN PrimaryCurrencyId int(11) NOT NULL DEFAULT '0',
	ADD COLUMN Currencies varchar(255) NOT NULL DEFAULT '',
	ADD COLUMN PrimaryPaymentTypeId int(11) NOT NULL DEFAULT '0',
	ADD COLUMN PaymentTypes varchar(255) NOT NULL DEFAULT '',
	ADD INDEX (BillingCountry),
	ADD INDEX (ShippingCountry),
	ADD INDEX (PrimaryCurrencyId),
	ADD INDEX (Currencies),
	ADD INDEX (PrimaryPaymentTypeId),
	ADD INDEX (PaymentTypes);

UPDATE Phrase SET Module = 'Core' WHERE Phrase IN ('la_btn_Add', 'la_fld_RecipientName', 'la_fld_SenderName');
DELETE FROM Permissions WHERE Permission LIKE 'in-commerce:incommerce_configemail%';