remove factories (except necessary ones) from this pull request, as we deliver them as a separate PR

This commit is contained in:
Herbert Maschke 2020-01-16 09:54:04 +01:00
parent e0c2814f2e
commit d281aa373b
17 changed files with 14 additions and 719 deletions

View File

@ -1,19 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Category\Models\Category;
$factory->define(Category::class, function (Faker $faker, array $attributes) {
return [
'status' => 1,
'position' => $faker->randomDigit,
'parent_id' => 1,
];
});
$factory->state(Category::class, 'inactive', [
'status' => 0,
]);

View File

@ -1,28 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Inventory\Models\InventorySource;
$factory->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,
];
});

View File

@ -1,71 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Sales\Models\Invoice;
use Webkul\Sales\Models\Order;
use Webkul\Sales\Models\OrderAddress;
$factory->define(Invoice::class, function (Faker $faker, array $attributes) {
$availableStatus = [
'pending',
'paid',
'refunded',
];
$subTotal = $faker->randomFloat(2);
$shippingAmount = $faker->randomFloat(2);
$taxAmount = $faker->randomFloat(2);
if (! $attributes['order_id']) {
$attributes['order_id'] = function () {
return factory(Order::class)->create()->id;
};
}
if (! $attributes['order_address_id']) {
$attributes['order_address_id'] = function () use ($attributes) {
return factory(OrderAddress::class)
->create(['order_id' => $attributes['order_id']])
->id;
};
}
return [
'status' => array_rand($availableStatus),
'email_sent' => 0,
'total_qty' => $faker->randomNumber(),
'base_currency_code' => 'EUR',
'channel_currency_code' => 'EUR',
'order_currency_code' => 'EUR',
'sub_total' => $subTotal,
'base_sub_total' => $subTotal,
'grand_total' => $subTotal,
'base_grand_total' => $subTotal,
'shipping_amount' => $shippingAmount,
'base_shipping_amount' => $shippingAmount,
'tax_amount' => $taxAmount,
'base_tax_amount' => $taxAmount,
'discount_amount' => 0,
'base_discount_amount' => 0,
'order_id' => $attributes['order_id'],
'order_address_id' => $attributes['order_address_id'],
];
});
$factory->state(Invoice::class, 'pending', [
'status' => 'pending',
]);
$factory->state(Invoice::class, 'paid', [
'status' => 'paid',
]);
$factory->state(Invoice::class, 'refunded', [
'status' => 'refunded',
]);

View File

@ -1,41 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Product\Models\Product;
use Webkul\Sales\Models\Invoice;
use Webkul\Sales\Models\InvoiceItem;
use Webkul\Sales\Models\OrderItem;
$factory->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;
},
];
});

View File

@ -1,19 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Core\Models\Locale;
$factory->define(Locale::class, function (Faker $faker, array $attributes) {
return [
'code' => $faker->languageCode,
'name' => $faker->country,
'direction' => 'ltr',
];
});
$factory->state(Category::class, 'rtl', [
'direction' => 'rtl',
]);

View File

@ -1,35 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Customer\Models\Customer;
use Webkul\Customer\Models\CustomerAddress;
use Webkul\Sales\Models\OrderAddress;
$factory->define(OrderAddress::class, function (Faker $faker) {
$now = date("Y-m-d H:i:s");
$customer = factory(Customer::class)->create();
$customerAddress = factory(CustomerAddress::class)->create();
return [
'first_name' => $customer->first_name,
'last_name' => $customer->last_name,
'email' => $customer->email,
'address1' => $customerAddress->address1,
'country' => $customerAddress->country,
'state' => $customerAddress->state,
'city' => $customerAddress->city,
'postcode' => $customerAddress->postcode,
'phone' => $customerAddress->phone,
'address_type' => 'billing',
'order_id' => function () {
return factory(Order::class)->create()->id;
},
'created_at' => $now,
'updated_at' => $now,
];
});
$factory->state(OrderAddress::class, 'shipping', [
'address_type' => 'shipping',
]);

View File

@ -1,68 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Illuminate\Support\Facades\DB;
use Webkul\Core\Models\Channel;
use Webkul\Customer\Models\Customer;
use Webkul\Sales\Models\Order;
use Webkul\Product\Models\Product;
$factory->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',
]);

View File

@ -1,38 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Product\Models\Product;
use Webkul\Sales\Models\Order;
use Webkul\Sales\Models\OrderItem;
$factory->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,
];
});

View File

@ -1,276 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Product\Models\Product;
use Webkul\Product\Models\ProductAttributeValue;
use Webkul\Attribute\Models\AttributeOption;
$factory->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;
},
];
});

View File

@ -1,31 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Product\Models\ProductDownloadableLink;
use Webkul\Product\Models\ProductDownloadableLinkTranslation;
$factory->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,
];
});

View File

@ -1,29 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Product\Models\ProductDownloadableSample;
use Webkul\Product\Models\ProductDownloadableSampleTranslation;
$factory->define(ProductDownloadableSample::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',
'created_at' => $now,
'updated_at' => $now,
];
});
$factory->define(ProductDownloadableSampleTranslation::class, function (Faker $faker) {
return [
'locale' => 'en',
'title' => $faker->word,
];
});

View File

@ -1,28 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Product\Models\Product;
$factory->define(Product::class, function (Faker $faker) {
$now = date("Y-m-d H:i:s");
return [
'sku' => $faker->uuid,
'created_at' => $now,
'updated_at' => $now,
'attribute_family_id' => 1,
];
});
$factory->state(Product::class, 'simple', [
'type' => 'simple',
]);
$factory->state(Product::class, 'virtual_nos', [
'type' => 'virtual_nos',
]);
$factory->state(Product::class, 'downloadable_with_stock', [
'type' => 'downloadable_with_stock',
]);

View File

@ -1,22 +0,0 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Inventory\Models\InventorySource;
use Webkul\Product\Models\Product;
use Webkul\Product\Models\ProductInventory;
$factory->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
];
});

View File

@ -37,8 +37,6 @@ class CoreServiceProvider extends ServiceProvider
]);
SliderProxy::observe(SliderObserver::class);
$this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/Factories');
}
/**
@ -64,15 +62,4 @@ class CoreServiceProvider extends ServiceProvider
return app()->make(Core::class);
});
}
/**
* Register factories.
*
* @param string $path
* @return void
*/
protected function registerEloquentFactoriesFrom($path): void
{
$this->app->make(EloquentFactory::class)->load($path);
}
}
}

View File

@ -16,5 +16,18 @@ class CustomerServiceProvider extends ServiceProvider
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'customer');
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/Factories');
}
/**
* Register factories.
*
* @param string $path
* @return void
*/
protected function registerEloquentFactoriesFrom($path): void
{
$this->app->make(EloquentFactory::class)->load($path);
}
}