Skip to content

Commit

Permalink
Extended the channels model with domain, billing, etc data
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Jan 26, 2024
1 parent 3558e8c commit 8468ea0
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
- Upgraded to Konekt Address, Customer and User modules to v3
- Removed the Vanilo v2 `Framework` namespace compatibility layer
- Added the `currency` field to the orders table
- Added `currency` field to the Channel model/table
- Added the following fields to the Channel model/table:
- `currency`
- `language`
- `domain`
- billing fields (emitter's data)
- `billing_countries`
- `shipping_countries`
- `theme`
- `color`
- Added the `payment_method_id` to the orders table
- Added the processing of the `payment_method_id` field to the OrderFactory (Foundation)
- Added the `is_hidden` field to the `Property` model
Expand Down
10 changes: 9 additions & 1 deletion src/Channel/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@

- Dropped PHP 8.0 & PHP 8.1 Support
- Dropped Laravel 9 Support
- Added `currency` field to the Channel model/table
- Added the following fields to the Channel model/table:
- `currency`
- `language`
- `domain`
- billing fields (emitter's data)
- `billing_countries`
- `shipping_countries`
- `theme`
- `color`
- Added the `channelables` table for being many-to-many polymorphic relationships with channels and arbitrary models

## 3.x Series
Expand Down
27 changes: 26 additions & 1 deletion src/Channel/Models/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@
* @property ?string $slug
* @property ?string $currency
* @property ?array $configuration
* @property ?string $language
* @property ?string $domain
* @property ?string $billing_company
* @property ?string $billing_country_id
* @property ?string $billing_province_id
* @property ?string $billing_postalcode
* @property ?string $billing_city
* @property ?string $billing_address
* @property ?string $billing_address2
* @property ?string $billing_tax_nr
* @property ?string $billing_registration_nr
* @property ?string $email
* @property ?string $phone
* @property ?array $billing_countries
* @property ?array $shipping_countries
* @property string color
* @property ?string theme
*
* @property ?Carbon $deleted_at
* @property Carbon $created_at
* @property Carbon $updated_at
Expand All @@ -43,9 +61,16 @@ class Channel extends Model implements ChannelContract
protected $guarded = ['id', 'created_at', 'updated_at'];

protected $casts = [
'configuration' => 'array'
'configuration' => 'array',
'billing_countries' => 'array',
'shipping_countries' => 'array',
];

public static function findByDomain(string $domain): ?Channel
{
return self::query()->where('domain', $domain)->first();
}

public function getName(): string
{
return $this->name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

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

return new class () extends Migration {
public function up(): void
{
Schema::table('channels', function (Blueprint $table) {
$table->char('language', 2)->default('en')->comment('The two letter ISO 639-1 language code');
$table->string('domain', 255)->nullable()->unique();
$table->string('billing_company', 255)->nullable();
$table->char('billing_country_id', 2)->nullable();
$table->integer('billing_province_id')->unsigned()->nullable();
$table->string('billing_postalcode', 12)->nullable();
$table->string('billing_city')->nullable();
$table->string('billing_address', 384)->nullable();
$table->string('billing_address2', 255)->nullable();
$table->string('billing_tax_nr', 17)->nullable();
$table->string('billing_registration_nr')->nullable();
$table->string('email')->nullable();
$table->string('phone', 22)->nullable();
$table->json('billing_countries')->nullable();
$table->json('shipping_countries')->nullable();
$table->char('color', 7)->default('#777777');
$table->string('theme')->nullable();
});
}

public function down(): void
{
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('language');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('domain');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_company');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_country_id');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_province_id');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_postalcode');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_city');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_address');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_address2');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_tax_nr');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_registration_nr');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('email');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('phone');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('billing_countries');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('shipping_countries');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('color');
});
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('theme');
});
}
};
11 changes: 11 additions & 0 deletions src/Foundation/Models/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

namespace Vanilo\Foundation\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Konekt\Address\Contracts\Country;
use Konekt\Address\Models\CountryProxy;
use Vanilo\Category\Models\TaxonomyProxy;
use Vanilo\Channel\Models\Channel as BaseChannel;
use Vanilo\MasterProduct\Models\MasterProductProxy;
Expand All @@ -23,6 +26,9 @@
use Vanilo\Properties\Models\PropertyProxy;
use Vanilo\Shipment\Models\ShippingMethodProxy;

/**
* @property-read Country $billingCountry
*/
class Channel extends BaseChannel
{
public function products(): MorphToMany
Expand Down Expand Up @@ -54,4 +60,9 @@ public function properties(): MorphToMany
{
return $this->morphedByMany(PropertyProxy::modelClass(), 'channelable');
}

public function billingCountry(): BelongsTo
{
return $this->belongsTo(CountryProxy::modelClass(), 'billing_country_id');
}
}
34 changes: 34 additions & 0 deletions src/Foundation/Tests/ExtendedChannelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/**
* Contains the ExtendedChannelTest class.
*
* @copyright Copyright (c) 2024 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2024-01-26
*
*/


use Konekt\Address\Models\Country;
use Vanilo\Foundation\Models\Channel;
use Vanilo\Foundation\Tests\TestCase;

class ExtendedChannelTest extends TestCase
{
/** @test */
public function it_can_retrieve_the_billing_country()
{
Country::create(['id' => 'DE', 'name' => 'Germany', 'phonecode' => 49, 'is_eu_member' => true]);

$channel = Channel::create([
'name' => 'Test 50',
'billing_country_id' => 'DE',
]);

$this->assertInstanceOf(Country::class, $channel->billingCountry);
}
}

0 comments on commit 8468ea0

Please sign in to comment.