Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Begin scaffolding address model
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbedard committed May 2, 2017
1 parent 9144f5e commit 9f8fede
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 0 deletions.
14 changes: 14 additions & 0 deletions classes/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static function fill(Model $model, array $data = [], array $omit = [])
$seed = [];

switch (get_class($model)) {
case 'Bedard\Shop\Models\Address': $seed = self::getAddressData($data); break;
case 'Bedard\Shop\Models\Cart': $seed = self::getCartData($data); break;
case 'Bedard\Shop\Models\CartItem': $seed = self::getCartItemData($data); break;
case 'Bedard\Shop\Models\Category': $seed = self::getCategoryData($data); break;
Expand All @@ -51,6 +52,19 @@ public static function fill(Model $model, array $data = [], array $omit = [])
return $model;
}

/**
* Address.
*
* @param array $data
* @return array
*/
public static function getAddressData(array $data = [])
{
return [
//
];
}

/**
* Cart.
*
Expand Down
62 changes: 62 additions & 0 deletions models/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php namespace Bedard\Shop\Models;

use Model;

/**
* Address Model
*/
class Address extends Model
{
use \October\Rain\Database\Traits\Validation;

/**
* @var string The database table used by the model.
*/
public $table = 'bedard_shop_addresses';

/**
* @var array Default attributes
*/
public $attributes = [
'country' => null,
'locality' => null,
'postal_code' => null,
'region' => null,
'street' => '[]',
];

/**
* @var array Fillable fields
*/
protected $fillable = [
'country_code',
'locality',
'postal_code',
'region',
'street',
];

/**
* @var array Guarded fields
*/
protected $guarded = ['*'];

/**
* @var array Jsonable fields
*/
protected $jsonable = [
'street',
];

/**
* @var array Relations
*/
public $belongsToMany = [];

/**
* @var array Validation
*/
public $rules = [
'street' => 'array',
];
}
8 changes: 8 additions & 0 deletions models/address/columns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ===================================
# List Column Definitions
# ===================================

columns:
id:
label: ID
searchable: true
8 changes: 8 additions & 0 deletions models/address/fields.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ===================================
# Form Field Definitions
# ===================================

fields:
id:
label: ID
disabled: true
28 changes: 28 additions & 0 deletions tests/unit/models/AddressTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php namespace Bedard\Shop\Tests\Unit\Models;

use Bedard\Shop\Classes\Factory;
use Bedard\Shop\Models\Address;
use Bedard\Shop\Tests\Unit\ShopTestCase;

class AddressTest extends ShopTestCase
{
public function test_initial_street_value_is_an_empty_array()
{
$address = new Address;
$this->assertTrue(is_array($address->street));
$this->assertEquals(0, count($address->street));
}

public function test_saving_multiple_street_lines()
{
$address = Factory::create(new Address, [
'street' => [
'123 Foo St.',
'Apartment #1234',
],
]);

$this->assertEquals('123 Foo St.', $address->street[0]);
$this->assertEquals('Apartment #1234', $address->street[1]);
}
}
27 changes: 27 additions & 0 deletions updates/1.0/create_addresses_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php namespace Bedard\Shop\Updates;

use Schema;
use October\Rain\Database\Schema\Blueprint;
use October\Rain\Database\Updates\Migration;

class CreateAddressesTable extends Migration
{
public function up()
{
Schema::create('bedard_shop_addresses', function(Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->json('street')->nullable();
$table->string('locality')->nullable();
$table->string('region')->nullable();
$table->string('postal_code')->nullable();
$table->string('country_code', 2)->nullable();
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('bedard_shop_addresses');
}
}
1 change: 1 addition & 0 deletions updates/1.0/seed_statuses_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function run()
Status::create([
'name' => Lang::get('bedard.shop::lang.statuses.presets.payment_received'),
'icon' => 'icon-money',
'is_reducing' => true,
]);

Status::create([
Expand Down
1 change: 1 addition & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.1.0:
- First version of Bedard.Shop
- 1.0/create_addresses_table.php
- 1.0/create_cart_items_table.php
- 1.0/create_cart_status_table.php
- 1.0/create_carts_table.php
Expand Down

0 comments on commit 9f8fede

Please sign in to comment.