Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Aug 11, 2024
1 parent 0eda296 commit 1c908bb
Show file tree
Hide file tree
Showing 26 changed files with 76 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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();
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
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;
}
4 changes: 2 additions & 2 deletions src/Interfaces/Models/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Cone\Bazar\Interfaces\Models;

use Cone\Bazar\Interfaces\Discountable;
use Cone\Bazar\Interfaces\Itemable;
use Cone\Bazar\Interfaces\Checkoutable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

interface Cart extends Discountable, Itemable
interface Cart extends Discountable, Checkoutable
{
/**
* Get the order for the cart.
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ interface Item extends LineItem
public function buyable(): MorphTo;

/**
* Get the itemable model for the item.
* Get the checkoutable model for the item.
*/
public function itemable(): MorphTo;
public function checkoutable(): MorphTo;

/**
* Determine if the item is a line item.
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Cone\Bazar\Interfaces\Models;

use Cone\Bazar\Interfaces\Discountable;
use Cone\Bazar\Interfaces\Itemable;
use Cone\Bazar\Interfaces\Checkoutable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Notifications\Notification;

interface Order extends Discountable, Itemable
interface Order extends Discountable, Checkoutable
{
/**
* Get the cart for the order.
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/Shipping/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Cone\Bazar\Interfaces\Shipping;

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;
}
12 changes: 6 additions & 6 deletions src/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Item extends Model implements Contract
* @var list<string>
*/
protected $hidden = [
'itemable',
'checkoutable',
];

/**
Expand Down Expand Up @@ -121,9 +121,9 @@ public function buyable(): MorphTo
}

/**
* Get the itemable model for the item.
* Get the checkoutable model for the item.
*/
public function itemable(): MorphTo
public function checkoutable(): MorphTo
{
return $this->morphTo()->withDefault();
}
Expand Down Expand Up @@ -209,7 +209,7 @@ public function getPrice(): float
*/
public function getFormattedPrice(): string
{
return (new Currency($this->getPrice(), $this->itemable->getCurrency()))->format();
return (new Currency($this->getPrice(), $this->checkoutable->getCurrency()))->format();
}

/**
Expand All @@ -225,7 +225,7 @@ public function getTotal(): float
*/
public function getFormattedTotal(): string
{
return (new Currency($this->getTotal(), $this->itemable->getCurrency()))->format();
return (new Currency($this->getTotal(), $this->checkoutable->getCurrency()))->format();
}

/**
Expand All @@ -241,7 +241,7 @@ public function getSubtotal(): float
*/
public function getFormattedSubtotal(): string
{
return (new Currency($this->getSubtotal(), $this->itemable->getCurrency()))->format();
return (new Currency($this->getSubtotal(), $this->checkoutable->getCurrency()))->format();
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Cone\Bazar\Models;

use Cone\Bazar\Database\Factories\ProductFactory;
use Cone\Bazar\Interfaces\Itemable;
use Cone\Bazar\Interfaces\Checkoutable;
use Cone\Bazar\Interfaces\Models\Product as Contract;
use Cone\Bazar\Traits\HasPrices;
use Cone\Bazar\Traits\HasProperties;
use Cone\Bazar\Traits\InteractsWithItemables;
use Cone\Bazar\Traits\InteractsWithCheckoutables;
use Cone\Bazar\Traits\InteractsWithStock;
use Cone\Root\Traits\HasMedia;
use Cone\Root\Traits\HasMetaData;
Expand All @@ -28,7 +28,7 @@ class Product extends Model implements Contract
use HasMetaData;
use HasPrices;
use HasProperties;
use InteractsWithItemables;
use InteractsWithCheckoutables;
use InteractsWithProxy;
use InteractsWithStock;
use SoftDeletes;
Expand Down Expand Up @@ -92,9 +92,9 @@ public function variants(): HasMany
}

/**
* 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
{
return true;
}
Expand Down Expand Up @@ -150,15 +150,15 @@ function (QueryBuilder $query): QueryBuilder {
/**
* Get the item representation of the buyable instance.
*/
public function toItem(Itemable $itemable, array $attributes = []): Item
public function toItem(Checkoutable $checkoutable, array $attributes = []): Item
{
if ($variant = $this->toVariant($attributes['properties'] ?? [])) {
return $variant->toItem($itemable, $attributes);
return $variant->toItem($checkoutable, $attributes);
}

return $this->items()->make(array_merge([
'name' => $this->name,
'price' => $this->getPrice($itemable->getCurrency()),
'price' => $this->getPrice($checkoutable->getCurrency()),
'quantity' => 1,
], $attributes))->setRelation('buyable', $this);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Models/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace Cone\Bazar\Models;

use Cone\Bazar\Database\Factories\VariantFactory;
use Cone\Bazar\Interfaces\Itemable;
use Cone\Bazar\Interfaces\Checkoutable;
use Cone\Bazar\Interfaces\Models\Variant as Contract;
use Cone\Bazar\Traits\HasPrices;
use Cone\Bazar\Traits\HasProperties;
use Cone\Bazar\Traits\InteractsWithItemables;
use Cone\Bazar\Traits\InteractsWithCheckoutables;
use Cone\Bazar\Traits\InteractsWithStock;
use Cone\Root\Traits\HasMedia;
use Cone\Root\Traits\HasMetaData;
Expand All @@ -28,7 +28,7 @@ class Variant extends Model implements Contract
HasPrices::getPrice as __getPrice;
}
use HasProperties;
use InteractsWithItemables;
use InteractsWithCheckoutables;
use InteractsWithProxy;
use InteractsWithStock;
use SoftDeletes;
Expand Down Expand Up @@ -112,9 +112,9 @@ protected function alias(): Attribute
}

/**
* 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
{
return true;
}
Expand All @@ -130,11 +130,11 @@ public function getPrice(?string $currency = null): ?float
/**
* Get the item representation of the buyable instance.
*/
public function toItem(Itemable $itemable, array $attributes = []): Item
public function toItem(Checkoutable $checkoutable, array $attributes = []): Item
{
return $this->items()->make(array_merge([
'name' => $this->name,
'price' => $this->getPrice($itemable->getCurrency()),
'price' => $this->getPrice($checkoutable->getCurrency()),
'quantity' => 1,
], $attributes))->setRelation('buyable', $this);
}
Expand Down
Empty file removed src/Resources/TaxRateResource.php
Empty file.
4 changes: 2 additions & 2 deletions src/Shipping/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Cone\Bazar\Shipping;

use Cone\Bazar\Interfaces\Itemable;
use Cone\Bazar\Interfaces\Checkoutable;
use Cone\Bazar\Interfaces\Shipping\Manager as Contract;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Manager as BaseManager;
Expand Down Expand Up @@ -30,7 +30,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
4 changes: 2 additions & 2 deletions src/Support/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Cone\Bazar\Support;

use Cone\Bazar\Interfaces\Itemable;
use Cone\Bazar\Interfaces\Checkoutable;
use Illuminate\Support\Str;

abstract class Driver
Expand All @@ -29,7 +29,7 @@ public function __construct(array $config = [])
/**
* Determine if the driver is available for the given model.
*/
public function available(Itemable $model): bool
public function available(Checkoutable $model): bool
{
return $this->enabled();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Facades/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Facades\Facade;

/**
* @method static array getAvailableDrivers(\Cone\Bazar\Interfaces\Itemable $model)
* @method static array getAvailableDrivers(\Cone\Bazar\Interfaces\Checkoutable $model)
* @method static \Cone\Bazar\Gateway\Driver driver(string $driver)
*
* @see \Cone\Bazar\Interfaces\Gateway\Manager
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Facades/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Support\Facades\Facade;

/**
* @method static array getAvailableDrivers(\Cone\Bazar\Interfaces\Itemable $model)
* @method static array getAvailableDrivers(\Cone\Bazar\Interfaces\Checkoutable $model)
*
* @see \Cone\Bazar\Interfaces\Shipping\Manager
*/
Expand Down
Loading

0 comments on commit 1c908bb

Please sign in to comment.