$this->createTrigger($connection, $query, ['currencyId' => Defaults::CURRENCY]);
}
private function addUpdateTrigger(Connection $connection): void
{
$query = 'CREATE TRIGGER country_tax_free_update BEFORE UPDATE ON country
FOR EACH ROW BEGIN
IF @TRIGGER_DISABLED IS NULL OR @TRIGGER_DISABLED = 0 THEN
IF NEW.tax_free <> OLD.tax_free THEN
SET NEW.customer_tax = JSON_OBJECT("enabled", NEW.tax_free, "currencyId", JSON_EXTRACT(OLD.customer_tax, "$.currencyId"), "amount", JSON_EXTRACT(OLD.customer_tax, "$.amount"));
ELSEIF NEW.tax_free = OLD.tax_free AND JSON_EXTRACT(NEW.customer_tax, "$.enabled") <> JSON_EXTRACT(OLD.customer_tax, "$.enabled") THEN
SET NEW.tax_free = JSON_EXTRACT(NEW.customer_tax, "$.enabled");
END IF;
IF NEW.company_tax_free <> OLD.company_tax_free THEN
SET NEW.company_tax = JSON_OBJECT("enabled", NEW.company_tax_free, "currencyId", JSON_EXTRACT(OLD.company_tax, "$.currencyId"), "amount", JSON_EXTRACT(OLD.company_tax, "$.amount"));
ELSEIF NEW.company_tax_free = OLD.company_tax_free AND JSON_EXTRACT(NEW.company_tax, "$.enabled") <> JSON_EXTRACT(OLD.company_tax, "$.enabled") THEN
SET NEW.company_tax_free = JSON_EXTRACT(NEW.company_tax, "$.enabled");
END IF;
END IF;
END;';