create('eav_entity_type', function (Blueprint $table) { $table->integer('entity_type_id'); $table->string('entity_type_code'); }); $schema->create('eav_attribute', function (Blueprint $table) { $table->integer('attribute_id'); $table->integer('entity_type_id'); $table->string('attribute_code'); $table->string('backend_type'); }); $schema->create('customer_entity', function (Blueprint $table) { $table->integer('entity_id'); $table->string('email')->nullable(); $table->integer('is_active')->default(1); $table->integer('group_id')->default(1); $table->string('created_at')->nullable(); $table->string('updated_at')->nullable(); }); foreach (['varchar', 'int', 'datetime', 'text'] as $type) { $schema->create('customer_entity_'.$type, function (Blueprint $table) { $table->increments('value_id'); $table->integer('entity_id'); $table->integer('attribute_id'); $table->text('value')->nullable(); }); } $schema->create('customer_address_entity', function (Blueprint $table) { $table->integer('entity_id'); $table->integer('parent_id'); $table->integer('is_active')->default(1); $table->string('created_at')->nullable(); }); foreach (['varchar', 'int', 'text'] as $type) { $schema->create('customer_address_entity_'.$type, function (Blueprint $table) { $table->increments('value_id'); $table->integer('entity_id'); $table->integer('attribute_id'); $table->text('value')->nullable(); }); } $db = DB::connection($connection); $db->table('eav_entity_type')->insert([ ['entity_type_id' => self::CUSTOMER_TYPE_ID, 'entity_type_code' => 'customer'], ['entity_type_id' => self::ADDRESS_TYPE_ID, 'entity_type_code' => 'customer_address'], ]); $db->table('eav_attribute')->insert([ ['attribute_id' => 5, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'firstname', 'backend_type' => 'varchar'], ['attribute_id' => 7, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'lastname', 'backend_type' => 'varchar'], ['attribute_id' => 11, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'dob', 'backend_type' => 'datetime'], ['attribute_id' => 12, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'password_hash', 'backend_type' => 'varchar'], ['attribute_id' => 13, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'default_billing', 'backend_type' => 'int'], ['attribute_id' => 14, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'default_shipping', 'backend_type' => 'int'], ['attribute_id' => 18, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'gender', 'backend_type' => 'int'], ['attribute_id' => 88, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'telephone', 'backend_type' => 'varchar'], ['attribute_id' => 20, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'firstname', 'backend_type' => 'varchar'], ['attribute_id' => 21, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'lastname', 'backend_type' => 'varchar'], ['attribute_id' => 22, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'company', 'backend_type' => 'varchar'], ['attribute_id' => 23, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'street', 'backend_type' => 'text'], ['attribute_id' => 24, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'city', 'backend_type' => 'varchar'], ['attribute_id' => 25, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'region', 'backend_type' => 'varchar'], ['attribute_id' => 26, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'postcode', 'backend_type' => 'varchar'], ['attribute_id' => 27, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'country_id', 'backend_type' => 'varchar'], ['attribute_id' => 28, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'telephone', 'backend_type' => 'varchar'], ]); $schema->create('sales_flat_order', function (Blueprint $table) { $table->integer('entity_id'); $table->string('increment_id')->nullable(); $table->integer('customer_id')->nullable(); $table->string('customer_email')->nullable(); $table->string('customer_firstname')->nullable(); $table->string('customer_lastname')->nullable(); $table->integer('customer_is_guest')->default(0); $table->string('status')->nullable(); $table->string('state')->nullable(); $table->integer('store_id')->nullable(); $table->string('base_currency_code')->nullable(); $table->string('order_currency_code')->nullable(); $table->string('store_currency_code')->nullable(); $table->decimal('grand_total', 12, 4)->default(0); $table->decimal('base_grand_total', 12, 4)->default(0); $table->decimal('subtotal', 12, 4)->default(0); $table->decimal('base_subtotal', 12, 4)->default(0); $table->decimal('subtotal_incl_tax', 12, 4)->nullable(); $table->decimal('base_subtotal_incl_tax', 12, 4)->nullable(); $table->decimal('tax_amount', 12, 4)->default(0); $table->decimal('base_tax_amount', 12, 4)->default(0); $table->decimal('discount_amount', 12, 4)->default(0); $table->decimal('base_discount_amount', 12, 4)->default(0); $table->decimal('shipping_amount', 12, 4)->default(0); $table->decimal('base_shipping_amount', 12, 4)->default(0); $table->decimal('shipping_incl_tax', 12, 4)->nullable(); $table->decimal('base_shipping_incl_tax', 12, 4)->nullable(); $table->decimal('shipping_tax_amount', 12, 4)->default(0); $table->decimal('base_shipping_tax_amount', 12, 4)->default(0); $table->string('shipping_method')->nullable(); $table->string('shipping_description')->nullable(); $table->string('coupon_code')->nullable(); $table->integer('total_item_count')->default(0); $table->decimal('total_qty_ordered', 12, 4)->default(0); $table->decimal('total_invoiced', 12, 4)->default(0); $table->decimal('base_total_invoiced', 12, 4)->default(0); $table->string('created_at')->nullable(); $table->string('updated_at')->nullable(); }); $schema->create('sales_flat_order_item', function (Blueprint $table) { $table->integer('item_id'); $table->integer('order_id'); $table->integer('parent_item_id')->nullable(); $table->integer('product_id')->nullable(); $table->string('product_type')->nullable(); $table->string('sku')->nullable(); $table->string('name')->nullable(); $table->decimal('qty_ordered', 12, 4)->default(0); $table->decimal('qty_shipped', 12, 4)->default(0); $table->decimal('qty_invoiced', 12, 4)->default(0); $table->decimal('qty_canceled', 12, 4)->default(0); $table->decimal('qty_refunded', 12, 4)->default(0); $table->decimal('price', 12, 4)->default(0); $table->decimal('base_price', 12, 4)->default(0); $table->decimal('price_incl_tax', 12, 4)->nullable(); $table->decimal('base_price_incl_tax', 12, 4)->nullable(); $table->decimal('row_total', 12, 4)->default(0); $table->decimal('base_row_total', 12, 4)->default(0); $table->decimal('row_total_incl_tax', 12, 4)->nullable(); $table->decimal('base_row_total_incl_tax', 12, 4)->nullable(); $table->decimal('tax_amount', 12, 4)->default(0); $table->decimal('base_tax_amount', 12, 4)->default(0); $table->decimal('tax_percent', 12, 4)->default(0); $table->decimal('discount_amount', 12, 4)->default(0); $table->decimal('base_discount_amount', 12, 4)->default(0); $table->decimal('discount_percent', 12, 4)->default(0); $table->decimal('weight', 12, 4)->default(0); $table->decimal('row_weight', 12, 4)->default(0); $table->string('created_at')->nullable(); }); $schema->create('sales_flat_order_address', function (Blueprint $table) { $table->integer('entity_id'); $table->integer('parent_id'); $table->string('address_type')->nullable(); $table->string('firstname')->nullable(); $table->string('lastname')->nullable(); $table->string('company')->nullable(); $table->text('street')->nullable(); $table->string('city')->nullable(); $table->string('region')->nullable(); $table->string('postcode')->nullable(); $table->string('country_id')->nullable(); $table->string('telephone')->nullable(); $table->string('email')->nullable(); }); $schema->create('sales_flat_order_payment', function (Blueprint $table) { $table->integer('entity_id'); $table->integer('parent_id'); $table->string('method')->nullable(); $table->string('last_trans_id')->nullable(); $table->string('cc_type')->nullable(); $table->string('cc_last4')->nullable(); $table->decimal('amount_ordered', 12, 4)->nullable(); $table->decimal('base_amount_ordered', 12, 4)->nullable(); }); } /** * @param array $data */ public static function seedCustomer(string $connection, array $data): void { $entityId = (int) $data['entity_id']; DB::connection($connection)->table('customer_entity')->insert([ 'entity_id' => $entityId, 'email' => $data['email'], 'is_active' => $data['is_active'] ?? 1, 'group_id' => $data['group_id'] ?? 99, 'created_at' => $data['created_at'] ?? '2020-01-01 00:00:00', 'updated_at' => $data['updated_at'] ?? '2020-01-01 00:00:00', ]); $varchar = [ 5 => $data['firstname'] ?? null, 7 => $data['lastname'] ?? null, 12 => $data['password_hash'] ?? null, 88 => $data['telephone'] ?? null, ]; foreach ($varchar as $attributeId => $value) { if ($value === null || $value === '') { continue; } DB::connection($connection)->table('customer_entity_varchar')->insert([ 'entity_id' => $entityId, 'attribute_id' => $attributeId, 'value' => $value, ]); } if (isset($data['gender'])) { DB::connection($connection)->table('customer_entity_int')->insert([ 'entity_id' => $entityId, 'attribute_id' => 18, 'value' => $data['gender'], ]); } if (! empty($data['default_billing'])) { DB::connection($connection)->table('customer_entity_int')->insert([ 'entity_id' => $entityId, 'attribute_id' => 13, 'value' => $data['default_billing'], ]); } if (! empty($data['default_shipping'])) { DB::connection($connection)->table('customer_entity_int')->insert([ 'entity_id' => $entityId, 'attribute_id' => 14, 'value' => $data['default_shipping'], ]); } if (! empty($data['dob'])) { DB::connection($connection)->table('customer_entity_datetime')->insert([ 'entity_id' => $entityId, 'attribute_id' => 11, 'value' => $data['dob'], ]); } } /** * @param array $data */ public static function seedAddress(string $connection, array $data): void { $entityId = (int) $data['entity_id']; DB::connection($connection)->table('customer_address_entity')->insert([ 'entity_id' => $entityId, 'parent_id' => $data['parent_id'], 'is_active' => 1, 'created_at' => '2020-01-01 00:00:00', ]); $map = [ 20 => ['table' => 'customer_address_entity_varchar', 'value' => $data['firstname'] ?? null], 21 => ['table' => 'customer_address_entity_varchar', 'value' => $data['lastname'] ?? null], 22 => ['table' => 'customer_address_entity_varchar', 'value' => $data['company'] ?? null], 23 => ['table' => 'customer_address_entity_text', 'value' => $data['street'] ?? null], 24 => ['table' => 'customer_address_entity_varchar', 'value' => $data['city'] ?? null], 25 => ['table' => 'customer_address_entity_varchar', 'value' => $data['region'] ?? null], 26 => ['table' => 'customer_address_entity_varchar', 'value' => $data['postcode'] ?? null], 27 => ['table' => 'customer_address_entity_varchar', 'value' => $data['country_id'] ?? null], 28 => ['table' => 'customer_address_entity_varchar', 'value' => $data['telephone'] ?? null], ]; foreach ($map as $attributeId => $item) { if ($item['value'] === null || $item['value'] === '') { continue; } DB::connection($connection)->table($item['table'])->insert([ 'entity_id' => $entityId, 'attribute_id' => $attributeId, 'value' => $item['value'], ]); } } /** * @param array $data */ public static function seedOrder(string $connection, array $data): void { $entityId = (int) $data['entity_id']; DB::connection($connection)->table('sales_flat_order')->insert([ 'entity_id' => $entityId, 'increment_id' => $data['increment_id'] ?? (string) (100000000 + $entityId), 'customer_id' => $data['customer_id'] ?? null, 'customer_email' => $data['customer_email'] ?? 'guest@example.com', 'customer_firstname' => $data['customer_firstname'] ?? 'Jane', 'customer_lastname' => $data['customer_lastname'] ?? 'Doe', 'customer_is_guest' => $data['customer_is_guest'] ?? 0, 'status' => $data['status'] ?? 'complete', 'state' => $data['state'] ?? 'complete', 'store_id' => $data['store_id'] ?? 1, 'base_currency_code' => $data['base_currency_code'] ?? 'USD', 'order_currency_code' => $data['order_currency_code'] ?? 'USD', 'store_currency_code' => $data['store_currency_code'] ?? 'USD', 'grand_total' => $data['grand_total'] ?? 110, 'base_grand_total' => $data['base_grand_total'] ?? 110, 'subtotal' => $data['subtotal'] ?? 100, 'base_subtotal' => $data['base_subtotal'] ?? 100, 'subtotal_incl_tax' => $data['subtotal_incl_tax'] ?? 100, 'base_subtotal_incl_tax' => $data['base_subtotal_incl_tax'] ?? 100, 'tax_amount' => $data['tax_amount'] ?? 0, 'base_tax_amount' => $data['base_tax_amount'] ?? 0, 'discount_amount' => $data['discount_amount'] ?? 0, 'base_discount_amount' => $data['base_discount_amount'] ?? 0, 'shipping_amount' => $data['shipping_amount'] ?? 10, 'base_shipping_amount' => $data['base_shipping_amount'] ?? 10, 'shipping_incl_tax' => $data['shipping_incl_tax'] ?? 10, 'base_shipping_incl_tax' => $data['base_shipping_incl_tax'] ?? 10, 'shipping_tax_amount' => $data['shipping_tax_amount'] ?? 0, 'base_shipping_tax_amount'=> $data['base_shipping_tax_amount'] ?? 0, 'shipping_method' => $data['shipping_method'] ?? 'flatrate_flatrate', 'shipping_description' => $data['shipping_description'] ?? 'Flat Rate - Fixed', 'coupon_code' => $data['coupon_code'] ?? null, 'total_item_count' => $data['total_item_count'] ?? 1, 'total_qty_ordered' => $data['total_qty_ordered'] ?? 1, 'total_invoiced' => $data['total_invoiced'] ?? 110, 'base_total_invoiced' => $data['base_total_invoiced'] ?? 110, 'created_at' => $data['created_at'] ?? '2021-06-01 12:00:00', 'updated_at' => $data['updated_at'] ?? '2021-06-01 12:00:00', ]); foreach ($data['items'] ?? [] as $item) { self::seedOrderItem($connection, array_merge(['order_id' => $entityId], $item)); } foreach ($data['addresses'] ?? [] as $address) { self::seedOrderAddress($connection, array_merge(['parent_id' => $entityId], $address)); } if (! empty($data['payment'])) { self::seedOrderPayment($connection, array_merge(['parent_id' => $entityId], $data['payment'])); } } /** * @param array $data */ public static function seedOrderItem(string $connection, array $data): void { DB::connection($connection)->table('sales_flat_order_item')->insert([ 'item_id' => $data['item_id'], 'order_id' => $data['order_id'], 'parent_item_id' => $data['parent_item_id'] ?? null, 'product_id' => $data['product_id'] ?? null, 'product_type' => $data['product_type'] ?? 'simple', 'sku' => $data['sku'] ?? 'SKU-1', 'name' => $data['name'] ?? 'Test Product', 'qty_ordered' => $data['qty_ordered'] ?? 1, 'qty_shipped' => $data['qty_shipped'] ?? 1, 'qty_invoiced' => $data['qty_invoiced'] ?? 1, 'qty_canceled' => $data['qty_canceled'] ?? 0, 'qty_refunded' => $data['qty_refunded'] ?? 0, 'price' => $data['price'] ?? 100, 'base_price' => $data['base_price'] ?? 100, 'price_incl_tax' => $data['price_incl_tax'] ?? 100, 'base_price_incl_tax' => $data['base_price_incl_tax'] ?? 100, 'row_total' => $data['row_total'] ?? 100, 'base_row_total' => $data['base_row_total'] ?? 100, 'row_total_incl_tax' => $data['row_total_incl_tax'] ?? 100, 'base_row_total_incl_tax' => $data['base_row_total_incl_tax'] ?? 100, 'tax_amount' => $data['tax_amount'] ?? 0, 'base_tax_amount' => $data['base_tax_amount'] ?? 0, 'tax_percent' => $data['tax_percent'] ?? 0, 'discount_amount' => $data['discount_amount'] ?? 0, 'base_discount_amount' => $data['base_discount_amount'] ?? 0, 'discount_percent' => $data['discount_percent'] ?? 0, 'weight' => $data['weight'] ?? 1, 'row_weight' => $data['row_weight'] ?? 1, 'created_at' => $data['created_at'] ?? '2021-06-01 12:00:00', ]); } /** * @param array $data */ public static function seedOrderAddress(string $connection, array $data): void { DB::connection($connection)->table('sales_flat_order_address')->insert([ 'entity_id' => $data['entity_id'], 'parent_id' => $data['parent_id'], 'address_type' => $data['address_type'] ?? 'billing', 'firstname' => $data['firstname'] ?? 'Jane', 'lastname' => $data['lastname'] ?? 'Doe', 'company' => $data['company'] ?? null, 'street' => $data['street'] ?? '123 Main St', 'city' => $data['city'] ?? 'Austin', 'region' => $data['region'] ?? 'TX', 'postcode' => $data['postcode'] ?? '78701', 'country_id' => $data['country_id'] ?? 'US', 'telephone' => $data['telephone'] ?? '5551112222', 'email' => $data['email'] ?? null, ]); } /** * @param array $data */ public static function seedOrderPayment(string $connection, array $data): void { DB::connection($connection)->table('sales_flat_order_payment')->insert([ 'entity_id' => $data['entity_id'], 'parent_id' => $data['parent_id'], 'method' => $data['method'] ?? 'paypal_express', 'last_trans_id' => $data['last_trans_id'] ?? null, 'cc_type' => $data['cc_type'] ?? null, 'cc_last4' => $data['cc_last4'] ?? null, 'amount_ordered' => $data['amount_ordered'] ?? 110, 'base_amount_ordered' => $data['base_amount_ordered'] ?? 110, ]); } }