|
|
@@ -12,6 +12,40 @@ class MagentoSchema
|
|
|
|
|
|
public const ADDRESS_TYPE_ID = 2;
|
|
|
|
|
|
+ public const CATEGORY_TYPE_ID = 3;
|
|
|
+
|
|
|
+ public const PRODUCT_TYPE_ID = 4;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_NAME = 70;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_DESCRIPTION = 71;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_SHORT_DESCRIPTION = 72;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_PRICE = 73;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_SPECIAL_PRICE = 74;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_COST = 75;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_WEIGHT = 76;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_STATUS = 77;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_META_TITLE = 78;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_META_KEYWORD = 79;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_META_DESCRIPTION = 80;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_URL_KEY = 81;
|
|
|
+
|
|
|
+ public const ATTR_PRODUCT_HAIR_COLORR = 90;
|
|
|
+
|
|
|
+ public const ATTR_CATEGORY_NAME = 111;
|
|
|
+
|
|
|
+ public const HAIR_COLORR_OPTION_ID = 501;
|
|
|
+
|
|
|
public static function create(string $connection): void
|
|
|
{
|
|
|
$schema = Schema::connection($connection);
|
|
|
@@ -26,6 +60,10 @@ class MagentoSchema
|
|
|
$table->integer('entity_type_id');
|
|
|
$table->string('attribute_code');
|
|
|
$table->string('backend_type');
|
|
|
+ $table->string('frontend_label')->nullable();
|
|
|
+ $table->string('frontend_input')->nullable();
|
|
|
+ $table->integer('is_required')->default(0);
|
|
|
+ $table->integer('is_user_defined')->default(0);
|
|
|
});
|
|
|
|
|
|
$schema->create('customer_entity', function (Blueprint $table) {
|
|
|
@@ -78,6 +116,7 @@ class MagentoSchema
|
|
|
['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' => 89, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'customer_source', 'backend_type' => 'int'],
|
|
|
['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'],
|
|
|
@@ -89,6 +128,16 @@ class MagentoSchema
|
|
|
['attribute_id' => 28, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'telephone', 'backend_type' => 'varchar'],
|
|
|
]);
|
|
|
|
|
|
+ $schema->create('newsletter_subscriber', function (Blueprint $table) {
|
|
|
+ $table->integer('subscriber_id');
|
|
|
+ $table->integer('store_id')->default(0);
|
|
|
+ $table->string('change_status_at')->nullable();
|
|
|
+ $table->integer('customer_id')->default(0);
|
|
|
+ $table->string('subscriber_email')->nullable();
|
|
|
+ $table->integer('subscriber_status')->default(0);
|
|
|
+ $table->string('subscriber_confirm_code')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
$schema->create('sales_flat_order', function (Blueprint $table) {
|
|
|
$table->integer('entity_id');
|
|
|
$table->string('increment_id')->nullable();
|
|
|
@@ -122,6 +171,11 @@ class MagentoSchema
|
|
|
$table->string('shipping_method')->nullable();
|
|
|
$table->string('shipping_description')->nullable();
|
|
|
$table->string('coupon_code')->nullable();
|
|
|
+ $table->integer('mw_rewardpoint')->default(0);
|
|
|
+ $table->decimal('mw_rewardpoint_discount', 12, 4)->default(0);
|
|
|
+ $table->decimal('mw_rewardpoint_discount_show', 12, 4)->default(0);
|
|
|
+ $table->decimal('amcheckoutfees_amount', 12, 4)->default(0);
|
|
|
+ $table->decimal('base_amcheckoutfees_amount', 12, 4)->default(0);
|
|
|
$table->integer('total_item_count')->default(0);
|
|
|
$table->decimal('total_qty_ordered', 12, 4)->default(0);
|
|
|
$table->decimal('total_invoiced', 12, 4)->default(0);
|
|
|
@@ -188,6 +242,17 @@ class MagentoSchema
|
|
|
$table->decimal('amount_ordered', 12, 4)->nullable();
|
|
|
$table->decimal('base_amount_ordered', 12, 4)->nullable();
|
|
|
});
|
|
|
+
|
|
|
+ $schema->create('mw_reward_point_order', function (Blueprint $table) {
|
|
|
+ $table->integer('order_id');
|
|
|
+ $table->integer('reward_point')->default(0);
|
|
|
+ $table->integer('rewardpoint_sell_product')->default(0);
|
|
|
+ $table->integer('earn_rewardpoint')->default(0);
|
|
|
+ $table->float('money')->default(0);
|
|
|
+ $table->string('reward_point_money_rate')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
+ self::createProductCatalog($connection);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -233,6 +298,14 @@ class MagentoSchema
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ if (isset($data['customer_source'])) {
|
|
|
+ DB::connection($connection)->table('customer_entity_int')->insert([
|
|
|
+ 'entity_id' => $entityId,
|
|
|
+ 'attribute_id' => 89,
|
|
|
+ 'value' => $data['customer_source'],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
if (! empty($data['default_billing'])) {
|
|
|
DB::connection($connection)->table('customer_entity_int')->insert([
|
|
|
'entity_id' => $entityId,
|
|
|
@@ -297,6 +370,22 @@ class MagentoSchema
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array<string, mixed> $data
|
|
|
+ */
|
|
|
+ public static function seedSubscriber(string $connection, array $data): void
|
|
|
+ {
|
|
|
+ DB::connection($connection)->table('newsletter_subscriber')->insert([
|
|
|
+ 'subscriber_id' => $data['subscriber_id'],
|
|
|
+ 'store_id' => $data['store_id'] ?? 1,
|
|
|
+ 'change_status_at' => $data['change_status_at'] ?? '2020-01-01 00:00:00',
|
|
|
+ 'customer_id' => $data['customer_id'] ?? 0,
|
|
|
+ 'subscriber_email' => $data['subscriber_email'],
|
|
|
+ 'subscriber_status' => $data['subscriber_status'] ?? 1,
|
|
|
+ 'subscriber_confirm_code' => $data['subscriber_confirm_code'] ?? 'confirmcode',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param array<string, mixed> $data
|
|
|
*/
|
|
|
@@ -337,6 +426,11 @@ class MagentoSchema
|
|
|
'shipping_method' => $data['shipping_method'] ?? 'flatrate_flatrate',
|
|
|
'shipping_description' => $data['shipping_description'] ?? 'Flat Rate - Fixed',
|
|
|
'coupon_code' => $data['coupon_code'] ?? null,
|
|
|
+ 'mw_rewardpoint' => $data['mw_rewardpoint'] ?? 0,
|
|
|
+ 'mw_rewardpoint_discount' => $data['mw_rewardpoint_discount'] ?? 0,
|
|
|
+ 'mw_rewardpoint_discount_show' => $data['mw_rewardpoint_discount_show'] ?? 0,
|
|
|
+ 'amcheckoutfees_amount' => $data['amcheckoutfees_amount'] ?? 0,
|
|
|
+ 'base_amcheckoutfees_amount' => $data['base_amcheckoutfees_amount'] ?? 0,
|
|
|
'total_item_count' => $data['total_item_count'] ?? 1,
|
|
|
'total_qty_ordered' => $data['total_qty_ordered'] ?? 1,
|
|
|
'total_invoiced' => $data['total_invoiced'] ?? 110,
|
|
|
@@ -356,6 +450,25 @@ class MagentoSchema
|
|
|
if (! empty($data['payment'])) {
|
|
|
self::seedOrderPayment($connection, array_merge(['parent_id' => $entityId], $data['payment']));
|
|
|
}
|
|
|
+
|
|
|
+ if (! empty($data['reward_point_order'])) {
|
|
|
+ self::seedRewardPointOrder($connection, array_merge(['order_id' => $entityId], $data['reward_point_order']));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array<string, mixed> $data
|
|
|
+ */
|
|
|
+ public static function seedRewardPointOrder(string $connection, array $data): void
|
|
|
+ {
|
|
|
+ DB::connection($connection)->table('mw_reward_point_order')->insert([
|
|
|
+ 'order_id' => $data['order_id'],
|
|
|
+ 'reward_point' => $data['reward_point'] ?? 0,
|
|
|
+ 'rewardpoint_sell_product' => $data['rewardpoint_sell_product'] ?? 0,
|
|
|
+ 'earn_rewardpoint' => $data['earn_rewardpoint'] ?? 0,
|
|
|
+ 'money' => $data['money'] ?? 0,
|
|
|
+ 'reward_point_money_rate' => $data['reward_point_money_rate'] ?? '100/1',
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -434,4 +547,315 @@ class MagentoSchema
|
|
|
'base_amount_ordered' => $data['base_amount_ordered'] ?? 110,
|
|
|
]);
|
|
|
}
|
|
|
+
|
|
|
+ public static function createProductCatalog(string $connection): void
|
|
|
+ {
|
|
|
+ $schema = Schema::connection($connection);
|
|
|
+ $db = DB::connection($connection);
|
|
|
+
|
|
|
+ $db->table('eav_entity_type')->insert([
|
|
|
+ ['entity_type_id' => self::CATEGORY_TYPE_ID, 'entity_type_code' => 'catalog_category'],
|
|
|
+ ['entity_type_id' => self::PRODUCT_TYPE_ID, 'entity_type_code' => 'catalog_product'],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $schema->create('catalog_eav_attribute', function (Blueprint $table) {
|
|
|
+ $table->integer('attribute_id');
|
|
|
+ $table->integer('is_searchable')->default(0);
|
|
|
+ $table->integer('is_filterable')->default(0);
|
|
|
+ $table->integer('is_comparable')->default(0);
|
|
|
+ $table->integer('is_configurable')->default(0);
|
|
|
+ $table->integer('position')->default(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('eav_attribute_option', function (Blueprint $table) {
|
|
|
+ $table->integer('option_id');
|
|
|
+ $table->integer('attribute_id');
|
|
|
+ $table->integer('sort_order')->default(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('eav_attribute_option_value', function (Blueprint $table) {
|
|
|
+ $table->increments('value_id');
|
|
|
+ $table->integer('option_id');
|
|
|
+ $table->integer('store_id')->default(0);
|
|
|
+ $table->string('value')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_product_entity', function (Blueprint $table) {
|
|
|
+ $table->integer('entity_id');
|
|
|
+ $table->string('sku')->nullable();
|
|
|
+ $table->string('type_id')->default('simple');
|
|
|
+ $table->integer('attribute_set_id')->default(4);
|
|
|
+ $table->string('created_at')->nullable();
|
|
|
+ $table->string('updated_at')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
+ foreach (['varchar', 'int', 'decimal', 'text', 'datetime'] as $type) {
|
|
|
+ $schema->create('catalog_product_entity_'.$type, function (Blueprint $table) {
|
|
|
+ $table->increments('value_id');
|
|
|
+ $table->integer('entity_id');
|
|
|
+ $table->integer('attribute_id');
|
|
|
+ $table->integer('store_id')->default(0);
|
|
|
+ $table->text('value')->nullable();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ $schema->create('catalog_product_entity_media_gallery', function (Blueprint $table) {
|
|
|
+ $table->increments('value_id');
|
|
|
+ $table->integer('entity_id');
|
|
|
+ $table->string('value')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_product_entity_media_gallery_value', function (Blueprint $table) {
|
|
|
+ $table->integer('value_id');
|
|
|
+ $table->integer('store_id')->default(0);
|
|
|
+ $table->string('label')->nullable();
|
|
|
+ $table->integer('position')->default(0);
|
|
|
+ $table->integer('disabled')->default(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('cataloginventory_stock_item', function (Blueprint $table) {
|
|
|
+ $table->increments('item_id');
|
|
|
+ $table->integer('product_id');
|
|
|
+ $table->integer('stock_id')->default(1);
|
|
|
+ $table->decimal('qty', 12, 4)->default(0);
|
|
|
+ $table->integer('is_in_stock')->default(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_category_entity', function (Blueprint $table) {
|
|
|
+ $table->integer('entity_id');
|
|
|
+ $table->string('path')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_category_entity_varchar', function (Blueprint $table) {
|
|
|
+ $table->increments('value_id');
|
|
|
+ $table->integer('entity_id');
|
|
|
+ $table->integer('attribute_id');
|
|
|
+ $table->integer('store_id')->default(0);
|
|
|
+ $table->string('value')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_category_product', function (Blueprint $table) {
|
|
|
+ $table->integer('category_id');
|
|
|
+ $table->integer('product_id');
|
|
|
+ $table->integer('position')->default(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_product_option', function (Blueprint $table) {
|
|
|
+ $table->increments('option_id');
|
|
|
+ $table->integer('product_id');
|
|
|
+ $table->string('type')->nullable();
|
|
|
+ $table->integer('is_require')->default(0);
|
|
|
+ $table->integer('sort_order')->default(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_product_option_title', function (Blueprint $table) {
|
|
|
+ $table->increments('option_title_id');
|
|
|
+ $table->integer('option_id');
|
|
|
+ $table->integer('store_id')->default(0);
|
|
|
+ $table->string('title')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_product_option_type_value', function (Blueprint $table) {
|
|
|
+ $table->increments('option_type_id');
|
|
|
+ $table->integer('option_id');
|
|
|
+ $table->string('sku')->nullable();
|
|
|
+ $table->integer('sort_order')->default(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_product_option_type_title', function (Blueprint $table) {
|
|
|
+ $table->increments('option_type_title_id');
|
|
|
+ $table->integer('option_type_id');
|
|
|
+ $table->integer('store_id')->default(0);
|
|
|
+ $table->string('title')->nullable();
|
|
|
+ });
|
|
|
+
|
|
|
+ $schema->create('catalog_product_option_type_price', function (Blueprint $table) {
|
|
|
+ $table->increments('option_type_price_id');
|
|
|
+ $table->integer('option_type_id');
|
|
|
+ $table->integer('store_id')->default(0);
|
|
|
+ $table->decimal('price', 12, 4)->default(0);
|
|
|
+ $table->string('price_type')->default('fixed');
|
|
|
+ });
|
|
|
+
|
|
|
+ $db->table('eav_attribute')->insert([
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_NAME, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'name', 'backend_type' => 'varchar', 'frontend_label' => 'Name', 'frontend_input' => 'text', 'is_required' => 1, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_DESCRIPTION, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'description', 'backend_type' => 'text', 'frontend_label' => 'Description', 'frontend_input' => 'textarea', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_SHORT_DESCRIPTION, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'short_description', 'backend_type' => 'text', 'frontend_label' => 'Short Description', 'frontend_input' => 'textarea', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_PRICE, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'price', 'backend_type' => 'decimal', 'frontend_label' => 'Price', 'frontend_input' => 'price', 'is_required' => 1, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_SPECIAL_PRICE, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'special_price', 'backend_type' => 'decimal', 'frontend_label' => 'Special Price', 'frontend_input' => 'price', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_COST, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'cost', 'backend_type' => 'decimal', 'frontend_label' => 'Cost', 'frontend_input' => 'price', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_WEIGHT, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'weight', 'backend_type' => 'decimal', 'frontend_label' => 'Weight', 'frontend_input' => 'weight', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_STATUS, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'status', 'backend_type' => 'int', 'frontend_label' => 'Status', 'frontend_input' => 'select', 'is_required' => 1, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_META_TITLE, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'meta_title', 'backend_type' => 'varchar', 'frontend_label' => 'Meta Title', 'frontend_input' => 'text', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_META_KEYWORD, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'meta_keyword', 'backend_type' => 'text', 'frontend_label' => 'Meta Keywords', 'frontend_input' => 'textarea', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_META_DESCRIPTION, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'meta_description', 'backend_type' => 'varchar', 'frontend_label' => 'Meta Description', 'frontend_input' => 'textarea', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_URL_KEY, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'url_key', 'backend_type' => 'varchar', 'frontend_label' => 'URL Key', 'frontend_input' => 'text', 'is_required' => 0, 'is_user_defined' => 0],
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_HAIR_COLORR, 'entity_type_id' => self::PRODUCT_TYPE_ID, 'attribute_code' => 'hair_colorr', 'backend_type' => 'int', 'frontend_label' => 'Hair Color', 'frontend_input' => 'select', 'is_required' => 0, 'is_user_defined' => 1],
|
|
|
+ ['attribute_id' => self::ATTR_CATEGORY_NAME, 'entity_type_id' => self::CATEGORY_TYPE_ID, 'attribute_code' => 'name', 'backend_type' => 'varchar', 'frontend_label' => 'Name', 'frontend_input' => 'text', 'is_required' => 1, 'is_user_defined' => 0],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $db->table('catalog_eav_attribute')->insert([
|
|
|
+ ['attribute_id' => self::ATTR_PRODUCT_HAIR_COLORR, 'is_searchable' => 1, 'is_filterable' => 1, 'is_comparable' => 0, 'is_configurable' => 0, 'position' => 10],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $db->table('eav_attribute_option')->insert([
|
|
|
+ ['option_id' => self::HAIR_COLORR_OPTION_ID, 'attribute_id' => self::ATTR_PRODUCT_HAIR_COLORR, 'sort_order' => 1],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $db->table('eav_attribute_option_value')->insert([
|
|
|
+ ['option_id' => self::HAIR_COLORR_OPTION_ID, 'store_id' => 0, 'value' => 'Natural Black'],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array<string, mixed> $data
|
|
|
+ */
|
|
|
+ public static function seedProduct(string $connection, array $data): void
|
|
|
+ {
|
|
|
+ $entityId = (int) $data['entity_id'];
|
|
|
+ $db = DB::connection($connection);
|
|
|
+
|
|
|
+ $db->table('catalog_product_entity')->insert([
|
|
|
+ 'entity_id' => $entityId,
|
|
|
+ 'sku' => $data['sku'] ?? 'SKU-'.$entityId,
|
|
|
+ 'type_id' => $data['type_id'] ?? 'simple',
|
|
|
+ 'attribute_set_id' => $data['attribute_set_id'] ?? 4,
|
|
|
+ 'created_at' => $data['created_at'] ?? '2020-01-01 00:00:00',
|
|
|
+ 'updated_at' => $data['updated_at'] ?? '2020-01-01 00:00:00',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $map = [
|
|
|
+ 'name' => [self::ATTR_PRODUCT_NAME, 'varchar'],
|
|
|
+ 'description' => [self::ATTR_PRODUCT_DESCRIPTION, 'text'],
|
|
|
+ 'short_description' => [self::ATTR_PRODUCT_SHORT_DESCRIPTION, 'text'],
|
|
|
+ 'price' => [self::ATTR_PRODUCT_PRICE, 'decimal'],
|
|
|
+ 'special_price' => [self::ATTR_PRODUCT_SPECIAL_PRICE, 'decimal'],
|
|
|
+ 'cost' => [self::ATTR_PRODUCT_COST, 'decimal'],
|
|
|
+ 'weight' => [self::ATTR_PRODUCT_WEIGHT, 'decimal'],
|
|
|
+ 'status' => [self::ATTR_PRODUCT_STATUS, 'int'],
|
|
|
+ 'meta_title' => [self::ATTR_PRODUCT_META_TITLE, 'varchar'],
|
|
|
+ 'meta_keyword' => [self::ATTR_PRODUCT_META_KEYWORD, 'text'],
|
|
|
+ 'meta_description' => [self::ATTR_PRODUCT_META_DESCRIPTION, 'varchar'],
|
|
|
+ 'url_key' => [self::ATTR_PRODUCT_URL_KEY, 'varchar'],
|
|
|
+ 'hair_colorr' => [self::ATTR_PRODUCT_HAIR_COLORR, 'int'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ $values = $data['eav'] ?? $data;
|
|
|
+
|
|
|
+ foreach ($map as $code => [$attributeId, $type]) {
|
|
|
+ if (! array_key_exists($code, $values) || $values[$code] === null || $values[$code] === '') {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $db->table('catalog_product_entity_'.$type)->insert([
|
|
|
+ 'entity_id' => $entityId,
|
|
|
+ 'attribute_id' => $attributeId,
|
|
|
+ 'store_id' => 0,
|
|
|
+ 'value' => $values[$code],
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (! array_key_exists('status', $values)) {
|
|
|
+ $db->table('catalog_product_entity_int')->insert([
|
|
|
+ 'entity_id' => $entityId,
|
|
|
+ 'attribute_id' => self::ATTR_PRODUCT_STATUS,
|
|
|
+ 'store_id' => 0,
|
|
|
+ 'value' => 1,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($data['images'] ?? [] as $position => $path) {
|
|
|
+ $valueId = $db->table('catalog_product_entity_media_gallery')->insertGetId([
|
|
|
+ 'entity_id' => $entityId,
|
|
|
+ 'value' => $path,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $db->table('catalog_product_entity_media_gallery_value')->insert([
|
|
|
+ 'value_id' => $valueId,
|
|
|
+ 'store_id' => 0,
|
|
|
+ 'label' => '',
|
|
|
+ 'position' => $position,
|
|
|
+ 'disabled' => 0,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['qty']) || isset($data['is_in_stock'])) {
|
|
|
+ $db->table('cataloginventory_stock_item')->insert([
|
|
|
+ 'product_id' => $entityId,
|
|
|
+ 'stock_id' => 1,
|
|
|
+ 'qty' => $data['qty'] ?? 0,
|
|
|
+ 'is_in_stock' => $data['is_in_stock'] ?? 0,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($data['categories'] ?? [] as $category) {
|
|
|
+ $categoryId = (int) $category['entity_id'];
|
|
|
+
|
|
|
+ if (! $db->table('catalog_category_entity')->where('entity_id', $categoryId)->exists()) {
|
|
|
+ $db->table('catalog_category_entity')->insert([
|
|
|
+ 'entity_id' => $categoryId,
|
|
|
+ 'path' => $category['path'] ?? (string) $categoryId,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $db->table('catalog_category_entity_varchar')->insert([
|
|
|
+ 'entity_id' => $categoryId,
|
|
|
+ 'attribute_id' => self::ATTR_CATEGORY_NAME,
|
|
|
+ 'store_id' => 0,
|
|
|
+ 'value' => $category['name'] ?? 'Category',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $db->table('catalog_category_product')->insert([
|
|
|
+ 'category_id' => $categoryId,
|
|
|
+ 'product_id' => $entityId,
|
|
|
+ 'position' => $category['position'] ?? 0,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($data['options'] ?? [] as $option) {
|
|
|
+ self::seedProductOption($connection, array_merge($option, ['product_id' => $entityId]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param array<string, mixed> $data
|
|
|
+ */
|
|
|
+ public static function seedProductOption(string $connection, array $data): void
|
|
|
+ {
|
|
|
+ $db = DB::connection($connection);
|
|
|
+
|
|
|
+ $optionId = $db->table('catalog_product_option')->insertGetId([
|
|
|
+ 'product_id' => $data['product_id'],
|
|
|
+ 'type' => $data['type'] ?? 'drop_down',
|
|
|
+ 'is_require' => $data['is_require'] ?? 1,
|
|
|
+ 'sort_order' => $data['sort_order'] ?? 0,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $db->table('catalog_product_option_title')->insert([
|
|
|
+ 'option_id' => $optionId,
|
|
|
+ 'store_id' => 0,
|
|
|
+ 'title' => $data['title'] ?? 'Option',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ foreach ($data['values'] ?? [] as $index => $value) {
|
|
|
+ $typeId = $db->table('catalog_product_option_type_value')->insertGetId([
|
|
|
+ 'option_id' => $optionId,
|
|
|
+ 'sku' => $value['sku'] ?? '',
|
|
|
+ 'sort_order' => $value['sort_order'] ?? $index,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $db->table('catalog_product_option_type_title')->insert([
|
|
|
+ 'option_type_id' => $typeId,
|
|
|
+ 'store_id' => 0,
|
|
|
+ 'title' => $value['title'] ?? '',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $db->table('catalog_product_option_type_price')->insert([
|
|
|
+ 'option_type_id' => $typeId,
|
|
|
+ 'store_id' => 0,
|
|
|
+ 'price' => $value['price'] ?? 0,
|
|
|
+ 'price_type' => $value['price_type'] ?? 'fixed',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|