Skip to content

Commit

Permalink
Added the currency field to the orders table
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Jul 10, 2023
1 parent d398e8d commit a03e544
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Dropped Enum v3 Support
- Changed minimal Enum requirement to v4.1
- Upgraded to Konekt Address and User modules to v3
- Added the `currency` field to the orders table

## 3.x Series

Expand Down
1 change: 1 addition & 0 deletions Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @property OrderStatus $status
* @property FulfillmentStatus $fulfillment_status
* @property null|string $language The two-letter ISO 639-1 code
* @property null|string $currency The 3 letter currency code
* @property null|int $billpayer_id
* @property null|Billpayer $billpayer
* @property null|int $user_id
Expand Down
2 changes: 2 additions & 0 deletions Tests/CreateOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public function all_fields_can_be_properly_set()
'status' => OrderStatus::COMPLETED(),
'fulfillment_status' => FulfillmentStatus::FULFILLED(),
'language' => 'de',
'currency' => 'EUR',
'ordered_at' => '2023-01-15 11:35:27',
'user_id' => $user->id,
'billpayer_id' => $billpayer->id,
Expand All @@ -217,6 +218,7 @@ public function all_fields_can_be_properly_set()
$this->assertTrue($order->fulfillment_status->isFulfilled());

$this->assertEquals('de', $order->language);
$this->assertEquals('EUR', $order->currency);
$this->assertEquals('2023-01-15T11:35:27Z', $order->ordered_at->toIso8601ZuluString());
$this->assertEquals($user->id, $order->user_id);
$this->assertEquals($billpayer->id, $order->billpayer_id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
public function up()
{
Schema::table('orders', function (Blueprint $table) {
$table->char('currency', 3)->nullable()->after('language');
});

// Set default value for `currency` on existing records
$currencyInConfig = config('vanilo.foundation.currency.code');
if (is_string($currencyInConfig) && 3 === strlen($currencyInConfig)) {
DB::update('UPDATE orders set currency = ?', [$currencyInConfig]);
}
}

public function down()
{
Schema::table('orders', function (Blueprint $table) {
$table->dropColumn('currency');
});
}
};

0 comments on commit a03e544

Please sign in to comment.