Skip to content

Commit 5c8737a

Browse files
committed
Plugin: BuyCourses: Bump to v7.5 to apply update on tax_perc in plugin_buycourses_services
1 parent 1b4d52e commit 5c8737a

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

public/plugin/BuyCourses/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
v7.5 - 2026-06-12
2+
====
3+
Fix: an empty tax rate on a service or a subscription can now be saved again, and is stored
4+
as NULL so the item falls back to the global tax rate (as intended). Older installations
5+
created the `tax_perc` column as NOT NULL on the services and subscription tables, which made
6+
saving an empty tax rate fail with "Column 'tax_perc' cannot be null".
7+
8+
ACTION REQUIRED for installations updated from an earlier version: run the update procedure
9+
so these columns are made nullable. Either load [your-host]/plugin/BuyCourses/update.php in
10+
your browser as a platform administrator, or run this SQL manually:
11+
```sql
12+
ALTER TABLE plugin_buycourses_services MODIFY tax_perc int unsigned NULL;
13+
ALTER TABLE plugin_buycourses_subscription MODIFY tax_perc int unsigned NULL;
14+
```
15+
116
v7.4 - 2022-04-28
217
====
318
Add subscriptions support.

public/plugin/BuyCourses/src/buy_course_plugin.class.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class BuyCoursesPlugin extends Plugin
117117
public function __construct()
118118
{
119119
parent::__construct(
120-
'7.1',
120+
'7.5',
121121
'
122122
Jose Angel Ruiz - NoSoloRed (original author) <br/>
123123
Francis Gonzales and Yannick Warnier - BeezNest (integration) <br/>
@@ -363,6 +363,16 @@ public function update(): void
363363
if (!$res) {
364364
echo Display::return_message($this->get_lang('ErrorUpdateFieldDB'), 'warning');
365365
}
366+
} else {
367+
// An empty tax rate must be stored as NULL so the service falls back to the
368+
// global tax rate. Older installations created this column as NOT NULL.
369+
$column = Database::fetch_assoc($res);
370+
if (isset($column['Null']) && 'NO' === $column['Null']) {
371+
$res = Database::query("ALTER TABLE $table MODIFY tax_perc int unsigned NULL");
372+
if (!$res) {
373+
echo Display::return_message($this->get_lang('ErrorUpdateFieldDB'), 'warning');
374+
}
375+
}
366376
}
367377

368378
$table = Database::get_main_table(self::TABLE_SALE);
@@ -576,6 +586,17 @@ public function update(): void
576586
)";
577587
Database::query($sql);
578588

589+
// An empty tax rate must be stored as NULL so the subscription falls back to the
590+
// global tax rate. Older installations created this column as NOT NULL.
591+
$res = Database::query("SHOW COLUMNS FROM $table WHERE Field = 'tax_perc'");
592+
$column = Database::fetch_assoc($res);
593+
if (isset($column['Null']) && 'NO' === $column['Null']) {
594+
$res = Database::query("ALTER TABLE $table MODIFY tax_perc int unsigned NULL");
595+
if (!$res) {
596+
echo Display::return_message($this->get_lang('ErrorUpdateFieldDB'), 'warning');
597+
}
598+
}
599+
579600
$table = Database::get_main_table(self::TABLE_SUBSCRIPTION_SALE);
580601
$sql = "CREATE TABLE IF NOT EXISTS $table (
581602
id int unsigned NOT NULL AUTO_INCREMENT,

0 commit comments

Comments
 (0)