From e76c1794b9dadb9b1c8b3db5a0888b133cd1985b Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Thu, 30 Jan 2020 21:01:45 +0100 Subject: [PATCH 1/2] add some factories into webkul core package to enhance testing potential --- .../Database/Factories/CartAddressFactory.php | 18 ++ .../src/Database/Factories/CartFactory.php | 41 +++ .../Database/Factories/CartItemFactory.php | 16 + .../Database/Factories/CartPaymentFactory.php | 16 + .../Database/Factories/CategoryFactory.php | 19 ++ .../Database/Factories/CustomerFactory.php | 34 +++ .../Factories/InventorySourceFactory.php | 28 ++ .../Database/Factories/InvoiceItemFactory.php | 41 +++ .../src/Database/Factories/OrderFactory.php | 68 +++++ .../Database/Factories/OrderItemFactory.php | 38 +++ .../Factories/OrderPaymentFactory.php | 17 ++ .../ProductAttributeValueFactory.php | 276 ++++++++++++++++++ .../ProductDownloadableLinkFactory.php | 31 ++ .../src/Database/Factories/ProductFactory.php | 21 ++ .../Factories/ProductInventoryFactory.php | 22 ++ 15 files changed, 686 insertions(+) create mode 100644 packages/Webkul/Core/src/Database/Factories/CartAddressFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/CartFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/CartItemFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/CartPaymentFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/CategoryFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/CustomerFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/InventorySourceFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/InvoiceItemFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/OrderFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/OrderItemFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/OrderPaymentFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/ProductAttributeValueFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/ProductDownloadableLinkFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/ProductFactory.php create mode 100644 packages/Webkul/Core/src/Database/Factories/ProductInventoryFactory.php 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 + ]; +}); + From 4d28188efb38a63e96470cfabc2e28fd70ed497a Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Fri, 31 Jan 2020 05:42:13 +0100 Subject: [PATCH 2/2] move factories into appropriate packages and remove redundant ones --- .../Database/Factories/CartAddressFactory.php | 0 .../src/Database/Factories/CartFactory.php | 0 .../Database/Factories/CartItemFactory.php | 0 .../Database/Factories/CartPaymentFactory.php | 0 .../src/Providers/CheckoutServiceProvider.php | 15 + .../Database/Factories/CategoryFactory.php | 19 -- .../Database/Factories/CustomerFactory.php | 34 --- .../Factories/InventorySourceFactory.php | 28 -- .../src/Database/Factories/OrderFactory.php | 68 ----- .../ProductAttributeValueFactory.php | 276 ------------------ .../src/Database/Factories/ProductFactory.php | 21 -- .../Factories/ProductInventoryFactory.php | 22 -- .../ProductDownloadableLinkFactory.php | 0 .../Database/Factories/InvoiceItemFactory.php | 0 .../Database/Factories/OrderItemFactory.php | 0 .../Factories/OrderPaymentFactory.php | 0 16 files changed, 15 insertions(+), 468 deletions(-) rename packages/Webkul/{Core => Checkout}/src/Database/Factories/CartAddressFactory.php (100%) rename packages/Webkul/{Core => Checkout}/src/Database/Factories/CartFactory.php (100%) rename packages/Webkul/{Core => Checkout}/src/Database/Factories/CartItemFactory.php (100%) rename packages/Webkul/{Core => Checkout}/src/Database/Factories/CartPaymentFactory.php (100%) delete mode 100644 packages/Webkul/Core/src/Database/Factories/CategoryFactory.php delete mode 100644 packages/Webkul/Core/src/Database/Factories/CustomerFactory.php delete mode 100644 packages/Webkul/Core/src/Database/Factories/InventorySourceFactory.php delete mode 100644 packages/Webkul/Core/src/Database/Factories/OrderFactory.php delete mode 100644 packages/Webkul/Core/src/Database/Factories/ProductAttributeValueFactory.php delete mode 100644 packages/Webkul/Core/src/Database/Factories/ProductFactory.php delete mode 100644 packages/Webkul/Core/src/Database/Factories/ProductInventoryFactory.php rename packages/Webkul/{Core => Product}/src/Database/Factories/ProductDownloadableLinkFactory.php (100%) rename packages/Webkul/{Core => Sales}/src/Database/Factories/InvoiceItemFactory.php (100%) rename packages/Webkul/{Core => Sales}/src/Database/Factories/OrderItemFactory.php (100%) rename packages/Webkul/{Core => Sales}/src/Database/Factories/OrderPaymentFactory.php (100%) diff --git a/packages/Webkul/Core/src/Database/Factories/CartAddressFactory.php b/packages/Webkul/Checkout/src/Database/Factories/CartAddressFactory.php similarity index 100% rename from packages/Webkul/Core/src/Database/Factories/CartAddressFactory.php rename to packages/Webkul/Checkout/src/Database/Factories/CartAddressFactory.php diff --git a/packages/Webkul/Core/src/Database/Factories/CartFactory.php b/packages/Webkul/Checkout/src/Database/Factories/CartFactory.php similarity index 100% rename from packages/Webkul/Core/src/Database/Factories/CartFactory.php rename to packages/Webkul/Checkout/src/Database/Factories/CartFactory.php diff --git a/packages/Webkul/Core/src/Database/Factories/CartItemFactory.php b/packages/Webkul/Checkout/src/Database/Factories/CartItemFactory.php similarity index 100% rename from packages/Webkul/Core/src/Database/Factories/CartItemFactory.php rename to packages/Webkul/Checkout/src/Database/Factories/CartItemFactory.php diff --git a/packages/Webkul/Core/src/Database/Factories/CartPaymentFactory.php b/packages/Webkul/Checkout/src/Database/Factories/CartPaymentFactory.php similarity index 100% rename from packages/Webkul/Core/src/Database/Factories/CartPaymentFactory.php rename to packages/Webkul/Checkout/src/Database/Factories/CartPaymentFactory.php diff --git a/packages/Webkul/Checkout/src/Providers/CheckoutServiceProvider.php b/packages/Webkul/Checkout/src/Providers/CheckoutServiceProvider.php index 74be9bc20..b0714c511 100755 --- a/packages/Webkul/Checkout/src/Providers/CheckoutServiceProvider.php +++ b/packages/Webkul/Checkout/src/Providers/CheckoutServiceProvider.php @@ -5,6 +5,7 @@ namespace Webkul\Checkout\Providers; use Illuminate\Support\ServiceProvider; use Illuminate\Foundation\AliasLoader; use Webkul\Checkout\Facades\Cart; +use Illuminate\Database\Eloquent\Factory as EloquentFactory; class CheckoutServiceProvider extends ServiceProvider { @@ -17,6 +18,8 @@ class CheckoutServiceProvider extends ServiceProvider $this->app->register(ModuleServiceProvider::class); $this->app->register(EventServiceProvider::class); + + $this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/Factories'); } /** @@ -48,4 +51,16 @@ class CheckoutServiceProvider extends ServiceProvider $this->app->bind('cart', 'Webkul\Checkout\Cart'); } + + /** + * Register factories. + * + * @param string $path + * + * @return void + */ + protected function registerEloquentFactoriesFrom($path): void + { + $this->app->make(EloquentFactory::class)->load($path); + } } \ No newline at end of file diff --git a/packages/Webkul/Core/src/Database/Factories/CategoryFactory.php b/packages/Webkul/Core/src/Database/Factories/CategoryFactory.php deleted file mode 100644 index 941601997..000000000 --- a/packages/Webkul/Core/src/Database/Factories/CategoryFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index c51af93c6..000000000 --- a/packages/Webkul/Core/src/Database/Factories/CustomerFactory.php +++ /dev/null @@ -1,34 +0,0 @@ -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 deleted file mode 100644 index 1f63b1333..000000000 --- a/packages/Webkul/Core/src/Database/Factories/InventorySourceFactory.php +++ /dev/null @@ -1,28 +0,0 @@ -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/OrderFactory.php b/packages/Webkul/Core/src/Database/Factories/OrderFactory.php deleted file mode 100644 index 5f813145c..000000000 --- a/packages/Webkul/Core/src/Database/Factories/OrderFactory.php +++ /dev/null @@ -1,68 +0,0 @@ -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/ProductAttributeValueFactory.php b/packages/Webkul/Core/src/Database/Factories/ProductAttributeValueFactory.php deleted file mode 100644 index 65e5e6245..000000000 --- a/packages/Webkul/Core/src/Database/Factories/ProductAttributeValueFactory.php +++ /dev/null @@ -1,276 +0,0 @@ -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/ProductFactory.php b/packages/Webkul/Core/src/Database/Factories/ProductFactory.php deleted file mode 100644 index 85761b605..000000000 --- a/packages/Webkul/Core/src/Database/Factories/ProductFactory.php +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index eee69e31d..000000000 --- a/packages/Webkul/Core/src/Database/Factories/ProductInventoryFactory.php +++ /dev/null @@ -1,22 +0,0 @@ -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 - ]; -}); - diff --git a/packages/Webkul/Core/src/Database/Factories/ProductDownloadableLinkFactory.php b/packages/Webkul/Product/src/Database/Factories/ProductDownloadableLinkFactory.php similarity index 100% rename from packages/Webkul/Core/src/Database/Factories/ProductDownloadableLinkFactory.php rename to packages/Webkul/Product/src/Database/Factories/ProductDownloadableLinkFactory.php diff --git a/packages/Webkul/Core/src/Database/Factories/InvoiceItemFactory.php b/packages/Webkul/Sales/src/Database/Factories/InvoiceItemFactory.php similarity index 100% rename from packages/Webkul/Core/src/Database/Factories/InvoiceItemFactory.php rename to packages/Webkul/Sales/src/Database/Factories/InvoiceItemFactory.php diff --git a/packages/Webkul/Core/src/Database/Factories/OrderItemFactory.php b/packages/Webkul/Sales/src/Database/Factories/OrderItemFactory.php similarity index 100% rename from packages/Webkul/Core/src/Database/Factories/OrderItemFactory.php rename to packages/Webkul/Sales/src/Database/Factories/OrderItemFactory.php diff --git a/packages/Webkul/Core/src/Database/Factories/OrderPaymentFactory.php b/packages/Webkul/Sales/src/Database/Factories/OrderPaymentFactory.php similarity index 100% rename from packages/Webkul/Core/src/Database/Factories/OrderPaymentFactory.php rename to packages/Webkul/Sales/src/Database/Factories/OrderPaymentFactory.php