diff --git a/packages/Webkul/Core/src/Database/Factories/CartAddressFactory.php b/packages/Webkul/Core/src/Database/Factories/CartAddressFactory.php new file mode 100644 index 000000000..536369a49 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/CartAddressFactory.php @@ -0,0 +1,18 @@ +define(CartAddress::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + return [ + 'first_name' => $faker->firstName(), + 'last_name' => $faker->lastName, + 'email' => $faker->email, + 'created_at' => $now, + 'updated_at' => $now, + 'address_type' => 'billing', + ]; +}); diff --git a/packages/Webkul/Core/src/Database/Factories/CartFactory.php b/packages/Webkul/Core/src/Database/Factories/CartFactory.php new file mode 100644 index 000000000..394c543c9 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/CartFactory.php @@ -0,0 +1,41 @@ +define(Cart::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + + $lastOrder = DB::table('orders') + ->orderBy('id', 'desc') + ->select('id') + ->first(); + + $customer = factory(Customer::class)->create(); + $cartAddress = factory(CartAddress::class)->create(); + + return [ + 'is_guest' => 0, + 'is_active' => 1, + 'customer_id' => $customer->id, + 'customer_email' => $customer->email, + 'customer_first_name' => $customer->first_name, + 'customer_last_name' => $customer->last_name, + 'is_gift' => 0, + 'base_currency_code' => 'EUR', + 'channel_currency_code' => 'EUR', + 'grand_total' => 0.0000, + 'base_grand_total' => 0.0000, + 'sub_total' => 0.0000, + 'base_sub_total' => 0.0000, + 'channel_id' => 1, + 'created_at' => $now, + 'updated_at' => $now, + ]; +}); diff --git a/packages/Webkul/Core/src/Database/Factories/CartItemFactory.php b/packages/Webkul/Core/src/Database/Factories/CartItemFactory.php new file mode 100644 index 000000000..7c916f194 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/CartItemFactory.php @@ -0,0 +1,16 @@ +define(CartItem::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + + return [ + 'created_at' => $now, + 'updated_at' => $now, + ]; +}); + diff --git a/packages/Webkul/Core/src/Database/Factories/CartPaymentFactory.php b/packages/Webkul/Core/src/Database/Factories/CartPaymentFactory.php new file mode 100644 index 000000000..3d45f70b0 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/CartPaymentFactory.php @@ -0,0 +1,16 @@ +define(CartPayment::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + + return [ + 'created_at' => $now, + 'updated_at' => $now, + ]; +}); + diff --git a/packages/Webkul/Core/src/Database/Factories/CategoryFactory.php b/packages/Webkul/Core/src/Database/Factories/CategoryFactory.php new file mode 100644 index 000000000..941601997 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/CategoryFactory.php @@ -0,0 +1,19 @@ +define(Category::class, function (Faker $faker, array $attributes) { + + return [ + 'status' => 1, + 'position' => $faker->randomDigit, + 'parent_id' => 1, + ]; +}); + +$factory->state(Category::class, 'inactive', [ + 'status' => 0, +]); diff --git a/packages/Webkul/Core/src/Database/Factories/CustomerFactory.php b/packages/Webkul/Core/src/Database/Factories/CustomerFactory.php new file mode 100644 index 000000000..c51af93c6 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/CustomerFactory.php @@ -0,0 +1,34 @@ +define(Customer::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + $gender = array_rand(['male', 'female', 'other']); + $password = $faker->password; + return [ + 'first_name' => $faker->firstName($gender), + 'last_name' => $faker->lastName, + 'gender' => ucfirst($gender), + 'email' => $faker->email, + 'status' => 1, + 'password' => Hash::make($password), + 'customer_group_id' => 2, + 'is_verified' => 1, + 'created_at' => $now, + 'updated_at' => $now, + 'notes' => json_encode(array('plain_password' => $password)), + ]; +}); + +$factory->state(Customer::class, 'male', [ + 'gender' => 'Male', +]); + +$factory->state(Customer::class, 'female', [ + 'gender' => 'Female', +]); diff --git a/packages/Webkul/Core/src/Database/Factories/InventorySourceFactory.php b/packages/Webkul/Core/src/Database/Factories/InventorySourceFactory.php new file mode 100644 index 000000000..1f63b1333 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/InventorySourceFactory.php @@ -0,0 +1,28 @@ +define(InventorySource::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + $code = $faker->unique()->word; + return [ + 'code' => $faker->unique()->word, + 'name' => $code, + 'description' => $faker->sentence, + 'contact_name' => $faker->name, + 'contact_email' => $faker->safeEmail, + 'contact_number' => $faker->phoneNumber, + 'country' => $faker->countryCode, + 'state' => $faker->state, + 'city' => $faker->city, + 'street' => $faker->streetAddress, + 'postcode' => $faker->postcode, + 'priority' => 0, + 'status' => 1, + 'created_at' => $now, + 'updated_at' => $now, + ]; +}); diff --git a/packages/Webkul/Core/src/Database/Factories/InvoiceItemFactory.php b/packages/Webkul/Core/src/Database/Factories/InvoiceItemFactory.php new file mode 100644 index 000000000..21cd87411 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/InvoiceItemFactory.php @@ -0,0 +1,41 @@ +define(InvoiceItem::class, function (Faker $faker, array $attributes) { + + $basePrice = $faker->randomFloat(2); + $quantity = $faker->randomNumber(); + + if (! $attributes['order_item_id']) { + $attributes['order_item_id'] = function () { + return factory(OrderItem::class)->create()->id; + }; + } + + $orderItem = OrderItem::find($attributes['order_item_id']); + + return [ + 'name' => $faker->word, + 'sku' => $faker->unique()->ean13, + 'qty' => $quantity, + 'price' => $basePrice, + 'base_price' => $basePrice, + 'total' => $quantity * $basePrice, + 'base_total' => $quantity * $basePrice, + 'tax_amount' => 0, + 'base_tax_amount' => 0, + 'product_id' => $orderItem->product_id, + 'product_type' => $orderItem->product_type, + 'order_item_id' => $attributes['order_item_id'], + 'invoice_id' => function () { + return factory(Invoice::class)->create()->id; + }, + ]; +}); diff --git a/packages/Webkul/Core/src/Database/Factories/OrderFactory.php b/packages/Webkul/Core/src/Database/Factories/OrderFactory.php new file mode 100644 index 000000000..5f813145c --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/OrderFactory.php @@ -0,0 +1,68 @@ +define(Order::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + + $lastOrder = DB::table('orders') + ->orderBy('id', 'desc') + ->select('id') + ->first(); + + $customer = factory(Customer::class)->create(); + + return [ + 'increment_id' => $lastOrder + 1, + 'status' => 'pending', + 'channel_name' => 'Default', + 'is_guest' => 0, + 'customer_id' => $customer->id, + 'customer_email' => $customer->email, + 'customer_first_name' => $customer->first_name, + 'customer_last_name' => $customer->last_name, + 'is_gift' => 0, + 'total_item_count' => 1, + 'total_qty_ordered' => 1, + 'base_currency_code' => 'EUR', + 'channel_currency_code' => 'EUR', + 'order_currency_code' => 'EUR', + 'grand_total' => 0.0000, + 'base_grand_total' => 0.0000, + 'grand_total_invoiced' => 0.0000, + 'base_grand_total_invoiced' => 0.0000, + 'grand_total_refunded' => 0.0000, + 'base_grand_total_refunded' => 0.0000, + 'sub_total' => 0.0000, + 'base_sub_total' => 0.0000, + 'sub_total_invoiced' => 0.0000, + 'base_sub_total_invoiced' => 0.0000, + 'sub_total_refunded' => 0.0000, + 'base_sub_total_refunded' => 0.0000, + 'customer_type' => Customer::class, + 'channel_id' => 1, + 'channel_type' => Channel::class, + 'created_at' => $now, + 'updated_at' => $now, + 'cart_id' => 0, + ]; +}); + +$factory->state(Order::class, 'pending', [ + 'status' => 'pending', +]); + +$factory->state(Order::class, 'completed', [ + 'status' => 'completed', +]); + +$factory->state(Order::class, 'closed', [ + 'status' => 'closed', +]); diff --git a/packages/Webkul/Core/src/Database/Factories/OrderItemFactory.php b/packages/Webkul/Core/src/Database/Factories/OrderItemFactory.php new file mode 100644 index 000000000..c9a4fc635 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/OrderItemFactory.php @@ -0,0 +1,38 @@ +define(OrderItem::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + + $product = factory(Product::class, 'simple')->create(); + + return [ + 'sku' => $product->sku, + 'type' => $product->type, + 'name' => $product->name, + 'price' => $product->price, + 'base_price' => $product->price, + 'total' => $product->price, + 'base_total' => $product->price, + 'product_id' => $product->id, + 'qty_ordered' => 1, + 'qty_shipped' => 0, + 'qty_invoiced' => 0, + 'qty_canceled' => 0, + 'qty_refunded' => 0, + 'order_id' => function () { + return factory(Order::class)->create()->id; + }, + 'created_at' => $now, + 'updated_at' => $now, + ]; +}); + + + diff --git a/packages/Webkul/Core/src/Database/Factories/OrderPaymentFactory.php b/packages/Webkul/Core/src/Database/Factories/OrderPaymentFactory.php new file mode 100644 index 000000000..8a4bb49fe --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/OrderPaymentFactory.php @@ -0,0 +1,17 @@ +define(OrderPayment::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + + return [ + 'created_at' => $now, + 'updated_at' => $now, + ]; +}); + diff --git a/packages/Webkul/Core/src/Database/Factories/ProductAttributeValueFactory.php b/packages/Webkul/Core/src/Database/Factories/ProductAttributeValueFactory.php new file mode 100644 index 000000000..65e5e6245 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/ProductAttributeValueFactory.php @@ -0,0 +1,276 @@ +defineAs(ProductAttributeValue::class, 'sku', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'text_value' => $faker->uuid, + 'attribute_id' => 1, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'name', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'locale' => 'en', //$faker->languageCode, + 'channel' => 'default', + 'text_value' => $faker->words(2, true), + 'attribute_id' => 2, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'url_key', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'text_value' => $faker->unique()->slug, + 'attribute_id' => 3, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'tax_category_id', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'channel' => 'default', + 'integer_value' => null, // ToDo + 'attribute_id' => 4, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'new', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'boolean_value' => 1, + 'attribute_id' => 5, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'featured', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'boolean_value' => 1, + 'attribute_id' => 6, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'visible_individually', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'boolean_value' => 1, + 'attribute_id' => 7, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'status', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'boolean_value' => 1, + 'attribute_id' => 8, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'short_description', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'locale' => 'en', //$faker->languageCode, + 'channel' => 'default', + 'text_value' => $faker->sentence, + 'attribute_id' => 9, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'description', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'locale' => 'en', //$faker->languageCode, + 'channel' => 'default', + 'text_value' => $faker->sentences(3, true), + 'attribute_id' => 10, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'price', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'float_value' => $faker->randomFloat(4, 0, 1000), + 'attribute_id' => 11, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'cost', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'channel' => 'default', + 'float_value' => $faker->randomFloat(4, 0, 10), + 'attribute_id' => 12, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'special_price', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'float_value' => $faker->randomFloat(4, 0, 100), + 'attribute_id' => 13, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'special_price_from', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'channel' => 'default', + 'date_value' => $faker->dateTimeBetween('-5 days', 'now', 'Europe/Berlin'), + 'attribute_id' => 14, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'special_price_to', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'channel' => 'default', + 'date_value' => $faker->dateTimeBetween('now', '+ 5 days', 'Europe/Berlin'), + 'attribute_id' => 15, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'meta_title', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'locale' => 'en', //$faker->languageCode, + 'channel' => 'default', + 'text_value' => $faker->words(2, true), + 'attribute_id' => 16, + ]; +}); + + +$factory->defineAs(ProductAttributeValue::class, 'meta_keywords', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'locale' => 'en', //$faker->languageCode, + 'channel' => 'default', + 'text_value' => $faker->words(5, true), + 'attribute_id' => 17, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'meta_description', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'locale' => 'en', //$faker->languageCode, + 'channel' => 'default', + 'text_value' => $faker->sentence, + 'attribute_id' => 18, + ]; +}); +$factory->defineAs(ProductAttributeValue::class, 'width', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'integer_value' => $faker->numberBetween(1, 50), + 'attribute_id' => 19, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'height', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'integer_value' => $faker->numberBetween(1, 50), + 'attribute_id' => 20, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'depth', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'integer_value' => $faker->numberBetween(1, 50), + 'attribute_id' => 21, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'weight', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'integer_value' => $faker->numberBetween(1, 50), + 'attribute_id' => 22, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'color', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'integer_value' => $faker->numberBetween(1, 5), + 'attribute_id' => 23, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'size', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'integer_value' => $faker->numberBetween(1, 5), + 'attribute_id' => 24, + ]; +}); + +$factory->defineAs(ProductAttributeValue::class, 'brand', function (Faker $faker) { + return [ + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'attribute_id' => 25, + 'integer_value' => function () { + return factory(AttributeOption::class)->create()->id; + }, + ]; +}); diff --git a/packages/Webkul/Core/src/Database/Factories/ProductDownloadableLinkFactory.php b/packages/Webkul/Core/src/Database/Factories/ProductDownloadableLinkFactory.php new file mode 100644 index 000000000..67bace113 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/ProductDownloadableLinkFactory.php @@ -0,0 +1,31 @@ +define(ProductDownloadableLink::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + $filename = 'ProductImageExampleForUpload.jpg'; + $filepath = '/tests/_data/'; + return [ + 'url' => '', + 'file' => $filepath . $filename, + 'file_name' => $filename, + 'type' => 'file', + 'price' => 0.0000, + 'downloads' => $faker->randomNumber(1), + 'created_at' => $now, + 'updated_at' => $now, + ]; +}); + +$factory->define(ProductDownloadableLinkTranslation::class, function (Faker $faker) { + return [ + 'locale' => 'en', + 'title' => $faker->word, + ]; +}); + diff --git a/packages/Webkul/Core/src/Database/Factories/ProductFactory.php b/packages/Webkul/Core/src/Database/Factories/ProductFactory.php new file mode 100644 index 000000000..85761b605 --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/ProductFactory.php @@ -0,0 +1,21 @@ +define(Product::class, function (Faker $faker) { + $now = date("Y-m-d H:i:s"); + return [ + 'sku' => $faker->uuid, + 'type' => 'virtual', + 'created_at' => $now, + 'updated_at' => $now, + 'attribute_family_id' => 1, + ]; +}); + +$factory->state(Product::class, 'simple', [ + 'type' => 'simple', +]); diff --git a/packages/Webkul/Core/src/Database/Factories/ProductInventoryFactory.php b/packages/Webkul/Core/src/Database/Factories/ProductInventoryFactory.php new file mode 100644 index 000000000..eee69e31d --- /dev/null +++ b/packages/Webkul/Core/src/Database/Factories/ProductInventoryFactory.php @@ -0,0 +1,22 @@ +define(ProductInventory::class, function (Faker $faker) { + return [ + 'qty' => $faker->numberBetween(1, 20), + 'product_id' => function () { + return factory(Product::class)->create()->id; + }, + 'inventory_source_id' => function () { + return factory(InventorySource::class)->create()->id; + }, + //'vendor_id' => 0, // this is default in DB schema + ]; +}); +