Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Aug 10, 2024
1 parent 9b2b616 commit bb80afb
Show file tree
Hide file tree
Showing 56 changed files with 495 additions and 547 deletions.
39 changes: 39 additions & 0 deletions database/factories/DiscountFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Cone\Bazar\Database\Factories;

use Cone\Bazar\Models\Discount;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @template TModel of \Illuminate\Database\Eloquent\Model
*/
class DiscountFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<\Illuminate\Database\Eloquent\Model>
*/
protected $model = Discount::class;

/**
* Get the name of the model that is generated by the factory.
*
* @return class-string<\Illuminate\Database\Eloquent\Model|TModel>
*/
public function modelName(): string
{
return $this->model::getProxiedClass();
}

/**
* Define the model's default state.
*/
public function definition(): array
{
return [
//
];
}
}
39 changes: 39 additions & 0 deletions database/factories/DiscountRateFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Cone\Bazar\Database\Factories;

use Cone\Bazar\Models\DiscountRate;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @template TModel of \Illuminate\Database\Eloquent\Model
*/
class DiscountRateFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<\Illuminate\Database\Eloquent\Model>
*/
protected $model = DiscountRate::class;

/**
* Get the name of the model that is generated by the factory.
*
* @return class-string<\Illuminate\Database\Eloquent\Model|TModel>
*/
public function modelName(): string
{
return $this->model::getProxiedClass();
}

/**
* Define the model's default state.
*/
public function definition(): array
{
return [
//
];
}
}
1 change: 0 additions & 1 deletion database/factories/ItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function modelName(): string
public function definition(): array
{
return [
'tax' => mt_rand(10, 100),
'name' => $this->faker->company(),
'price' => mt_rand(10, 100),
'quantity' => mt_rand(1, 10),
Expand Down
39 changes: 39 additions & 0 deletions database/factories/TaxFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Cone\Bazar\Database\Factories;

use Cone\Bazar\Models\Tax;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @template TModel of \Illuminate\Database\Eloquent\Model
*/
class TaxFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<\Illuminate\Database\Eloquent\Model>
*/
protected $model = Tax::class;

/**
* Get the name of the model that is generated by the factory.
*
* @return class-string<\Illuminate\Database\Eloquent\Model|TModel>
*/
public function modelName(): string
{
return $this->model::getProxiedClass();
}

/**
* Define the model's default state.
*/
public function definition(): array
{
return [
//
];
}
}
39 changes: 39 additions & 0 deletions database/factories/TaxRateFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Cone\Bazar\Database\Factories;

use Cone\Bazar\Models\TaxRate;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @template TModel of \Illuminate\Database\Eloquent\Model
*/
class TaxRateFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<\Illuminate\Database\Eloquent\Model>
*/
protected $model = TaxRate::class;

/**
* Get the name of the model that is generated by the factory.
*
* @return class-string<\Illuminate\Database\Eloquent\Model|TModel>
*/
public function modelName(): string
{
return $this->model::getProxiedClass();
}

/**
* Define the model's default state.
*/
public function definition(): array
{
return [
//
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ public function up(): void
{
Schema::create('bazar_items', static function (Blueprint $table): void {
$table->uuid('id')->primary();
$table->morphs('itemable');
$table->morphs('checkoutable');
$table->nullableMorphs('buyable');
$table->string('name');
$table->float('price')->unsigned();
$table->float('tax')->unsigned()->default(0);
$table->float('quantity')->unsigned();
$table->json('properties')->nullable();
$table->timestamps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public function up(): void
{
Schema::create('bazar_tax_rates', static function (Blueprint $table): void {
$table->id();
$table->string('name');
$table->string('type');
$table->float('value')->unsigned();
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public function up(): void
{
Schema::create('bazar_discount_rates', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('type');
$table->float('value')->unsigned();
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public function up(): void
{
Schema::create('bazar_discounts', function (Blueprint $table) {
$table->id();
$table->foreignId('discount_rate_id')->constrained('bazar_discount_rates')->nullOnDelete();
$table->morphs('discountable');
$table->float('value')->unsigned();
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public function up(): void
{
Schema::create('bazar_taxes', function (Blueprint $table) {
$table->id();
$table->foreignId('tax_rate_id')->constrained('bazar_tax_rates')->nullOnDelete();
$table->foreignId('item_id')->constrained('bazar_items')->nullOnDelete();
$table->float('value')->unsigned();
$table->timestamps();
});
}
Expand Down
2 changes: 0 additions & 2 deletions src/BazarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ class BazarServiceProvider extends ServiceProvider
public array $singletons = [
Interfaces\Cart\Manager::class => Cart\Manager::class,
Interfaces\Gateway\Manager::class => Gateway\Manager::class,
Interfaces\Repositories\DiscountRepository::class => Repositories\DiscountRepository::class,
Interfaces\Repositories\TaxRepository::class => Repositories\TaxRepository::class,
Interfaces\Shipping\Manager::class => Shipping\Manager::class,
];

Expand Down
6 changes: 3 additions & 3 deletions src/Console/Commands/ClearCarts.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public function handle(): void
{
if ($this->option('all')) {
Cart::proxy()->newQuery()->truncate();
Item::proxy()->newQuery()->where('itemable_type', Cart::getProxiedClass())->delete();
Item::proxy()->newQuery()->where('checkoutable_type', Cart::getProxiedClass())->delete();
Shipping::proxy()->newQuery()->where('shippable_type', Cart::getProxiedClass())->delete();

$this->info('All carts have been deleted.');
} else {
Item::proxy()
->newQuery()
->where('itemable_type', Cart::getProxiedClass())
->whereIn('itemable_id', Cart::proxy()->newQuery()->expired()->select('id'))
->where('checkoutable_type', Cart::getProxiedClass())
->whereIn('checkoutable_id', Cart::proxy()->newQuery()->expired()->select('id'))
->delete();

Shipping::proxy()
Expand Down
6 changes: 3 additions & 3 deletions src/Fields/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Items extends MorphMany
*/
protected array $with = [
'buyable',
'itemable',
'checkoutable',
];

/**
Expand Down Expand Up @@ -61,14 +61,14 @@ public function fields(Request $request): array
->min(0)
->required()
->format(static function (Request $request, Model $model, ?float $value): string {
return (new Currency($value, $model->itemable->currency))->format();
return (new Currency($value, $model->checkoutable->currency))->format();
}),

Number::make(__('TAX'), 'tax')
->min(0)
->required()
->format(static function (Request $request, Model $model, ?float $value): string {
return (new Currency($value, $model->itemable->currency))->format();
return (new Currency($value, $model->checkoutable->currency))->format();
}),

Number::make(__('Quantity'), 'quantity')
Expand Down
4 changes: 2 additions & 2 deletions src/Gateway/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Cone\Bazar\Gateway;

use Cone\Bazar\Interfaces\Gateway\Manager as Contract;
use Cone\Bazar\Interfaces\Itemable;
use Cone\Bazar\Interfaces\Checkoutable;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Manager as BaseManager;

Expand Down Expand Up @@ -31,7 +31,7 @@ public function getDefaultDriver(): string
/**
* Get the available drivers for the given model.
*/
public function getAvailableDrivers(?Itemable $model = null): array
public function getAvailableDrivers(?Checkoutable $model = null): array
{
foreach (array_keys(array_diff_key($this->customCreators, parent::getDrivers())) as $key) {
if (! isset($this->drivers[$key])) {
Expand Down
6 changes: 3 additions & 3 deletions src/Interfaces/Buyable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
interface Buyable
{
/**
* Determine whether the buyable object is available for the itemable instance.
* Determine whether the buyable object is available for the checkoutable instance.
*/
public function buyable(Itemable $itemable): bool;
public function buyable(Checkoutable $checkoutable): bool;

/**
* Get the item representation of the buyable instance.
*/
public function toItem(Itemable $itemable, array $attributes = []): Item;
public function toItem(Checkoutable $checkoutable, array $attributes = []): Item;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;

interface Itemable extends Shippable
interface Checkoutable extends Shippable
{
/**
* Get the user for the model.
Expand Down Expand Up @@ -44,7 +44,7 @@ public function getSubtotal(): float;
public function getFormattedSubtotal(): string;

/**
* Get the itemable model's fee total.
* Get the checkoutable model's fee total.
*/
public function getFeeTotal(): float;

Expand Down
11 changes: 0 additions & 11 deletions src/Interfaces/Discount.php

This file was deleted.

21 changes: 9 additions & 12 deletions src/Interfaces/Discountable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@

namespace Cone\Bazar\Interfaces;

use Illuminate\Database\Eloquent\Relations\MorphMany;

interface Discountable
{
/**
* Get the discount.
*/
public function getDiscount(): float;

/**
* Get the formatted discount.
* Get the discounts.
*/
public function getFormattedDiscount(): string;
public function discounts(): MorphMany;

/**
* Get the discount rate.
* Get the discount.
*/
public function getDiscountRate(): float;
public function getTotalDiscount(): float;

/**
* Get the formatted discount rate.
* Get the formatted discount.
*/
public function getFormattedDiscountRate(): string;
public function getFormattedTotalDiscount(): string;

/**
* Calculate the discount.
*/
public function calculateDiscount(bool $update = true): float;
public function calculateDiscount(): float;
}
4 changes: 2 additions & 2 deletions src/Interfaces/Gateway/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Cone\Bazar\Interfaces\Gateway;

use Cone\Bazar\Interfaces\Itemable;
use Cone\Bazar\Interfaces\Checkoutable;

interface Manager
{
/**
* Get the available drivers for the given model.
*/
public function getAvailableDrivers(?Itemable $model = null): array;
public function getAvailableDrivers(?Checkoutable $model = null): array;
}
Loading

0 comments on commit bb80afb

Please sign in to comment.