Skip to content

Commit

Permalink
feat: replace LocationInterface with LocationModel in Location facade…
Browse files Browse the repository at this point in the history
… and related models

Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Feb 26, 2025
1 parent 6d068a7 commit 220c2de
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
30 changes: 13 additions & 17 deletions src/Classes/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Igniter\Flame\Geolite\Contracts\CoordinatesInterface;
use Igniter\Flame\Geolite\Model\Location as UserLocation;
use Igniter\Flame\Traits\EventEmitter;
use Igniter\Local\Contracts\LocationInterface;
use Igniter\Local\Models\Location as LocationModel;
use Igniter\Local\Models\LocationArea;
use Igniter\System\Traits\SessionMaker;
Expand All @@ -36,7 +35,7 @@ class Location

protected string $sessionKey = 'local_info';

protected ?LocationInterface $model = null;
protected ?LocationModel $model = null;

protected string $locationModel = \Igniter\Local\Models\Location::class;

Expand Down Expand Up @@ -78,7 +77,7 @@ public function check(): bool
return !is_null($this->current());
}

public function current(): ?LocationInterface
public function current(): ?LocationModel
{
if (!is_null($this->model)) {
return $this->model;
Expand All @@ -101,9 +100,9 @@ public function current(): ?LocationInterface
return $this->model;
}

public function currentOrDefault(): ?LocationInterface
public function currentOrDefault(): ?LocationModel
{
if (($model = $this->current()) instanceof LocationInterface) {
if (($model = $this->current()) instanceof LocationModel) {
return $model;
}

Expand All @@ -128,7 +127,7 @@ public function currentOrAssigned(): array
return AdminAuth::user()?->locations?->pluck('location_id')->all() ?? [];
}

public function setCurrent(LocationInterface $locationModel): void
public function setCurrent(LocationModel $locationModel): void
{
$this->setModel($locationModel);

Expand All @@ -137,12 +136,12 @@ public function setCurrent(LocationInterface $locationModel): void
$this->fireSystemEvent('location.current.updated', [$locationModel]);
}

public function getModel(): ?LocationInterface
public function getModel(): ?LocationModel
{
return $this->model;
}

public function setModel(LocationInterface $model): self
public function setModel(LocationModel $model): self
{
$this->model = $model;

Expand All @@ -159,7 +158,7 @@ public function getName(): ?string
return $this->model?->getName();
}

public function createLocationModel(): LocationInterface
public function createLocationModel(): LocationModel
{
$class = '\\'.ltrim($this->locationModel, '\\');

Expand All @@ -182,22 +181,22 @@ public function extendLocationQuery(Builder $query): void
}
}

public function getById(string|int $identifier): ?LocationInterface
public function getById(string|int $identifier): ?LocationModel
{
$query = $this->createLocationModelQuery();

/** @var ?LocationInterface $location */
/** @var ?LocationModel $location */
$location = $query->find($identifier);

return $location ?: null;
}

public function getBySlug(string $slug): ?LocationInterface
public function getBySlug(string $slug): ?LocationModel
{
$model = $this->createLocationModel();
$query = $this->createLocationModelQuery();

/** @var ?LocationInterface $location */
/** @var ?LocationModel $location */
$location = $query->where($model->getSlugKeyName(), $slug)->first();

return $location ?: null;
Expand Down Expand Up @@ -575,10 +574,7 @@ public function coveredArea(): CoveredArea
return $coveredArea;
}

/**
* @return \Igniter\Flame\Geolite\Model\Location
*/
public function userPosition(): mixed
public function userPosition(): ?\Igniter\Flame\Geolite\Model\Location
{
return $this->getSession('position', UserLocation::createFromArray([]));
}
Expand Down
31 changes: 15 additions & 16 deletions src/Facades/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Igniter\Local\Classes\CoveredArea;
use Igniter\Local\Classes\WorkingSchedule;
use Igniter\Local\Contracts\AreaInterface;
use Igniter\Local\Contracts\LocationInterface;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Facade;
Expand All @@ -20,18 +19,18 @@
* @method static string|null resolveLocationSlug()
* @method static void locationSlugResolver(Closure $resolver)
* @method static bool check()
* @method static \Igniter\Local\Models\Location|LocationInterface|null current()
* @method static LocationInterface|null currentOrDefault()
* @method static \Igniter\Local\Models\Location|null current()
* @method static \Igniter\Local\Models\Location|null currentOrDefault()
* @method static array currentOrAssigned()
* @method static void setCurrent(LocationInterface $locationModel)
* @method static LocationInterface|null getModel()
* @method static \Igniter\Local\Classes\Location setModel(LocationInterface $model)
* @method static void setCurrent(\Igniter\Local\Models\Location $locationModel)
* @method static \Igniter\Local\Models\Location|null getModel()
* @method static \Igniter\Local\Classes\Location setModel(\Igniter\Local\Models\Location $model)
* @method static int|null getId()
* @method static string|null getName()
* @method static LocationInterface createLocationModel()
* @method static \Igniter\Local\Models\Location createLocationModel()
* @method static void extendLocationQuery(Builder $query)
* @method static LocationInterface|null getById(string | int $identifier)
* @method static LocationInterface|null getBySlug(string $slug)
* @method static \Igniter\Local\Models\Location|null getById(string | int $identifier)
* @method static \Igniter\Local\Models\Location|null getBySlug(string $slug)
* @method static void clearInternalCache()
* @method static void updateOrderType(void $code = null)
* @method static string orderType()
Expand All @@ -49,18 +48,18 @@
* @method static void openTime(void $type = null, void $format = null)
* @method static void closeTime(void $type = null, void $format = null)
* @method static void lastOrderTime()
* @method static void checkOrderTime(void $timestamp = null, void $orderTypeCode = null)
* @method static bool checkOrderTime(void $timestamp = null, void $orderTypeCode = null)
* @method static Carbon orderDateTime()
* @method static void orderTimeIsAsap()
* @method static void hasAsapSchedule()
* @method static void isOpened()
* @method static bool orderTimeIsAsap()
* @method static bool hasAsapSchedule()
* @method static bool isOpened()
* @method static void asapScheduleTimeslot()
* @method static void isClosed()
* @method static bool isClosed()
* @method static void firstScheduleTimeslot()
* @method static void scheduleTimeslot(void $orderType = null)
* @method static void orderLeadTime()
* @method static void orderTimeInterval()
* @method static void checkNoOrderTypeAvailable()
* @method static bool checkNoOrderTypeAvailable()
* @method static void hasLaterSchedule()
* @method static WorkingSchedule workingSchedule(string $type, array | int | null $days = null)
* @method static void updateNearbyArea(AreaInterface $area)
Expand All @@ -71,7 +70,7 @@
* @method static bool isCurrentAreaId(void $areaId)
* @method static null|int getAreaId()
* @method static CoveredArea coveredArea()
* @method static \Igniter\Flame\Geolite\Model\Location userPosition()
* @method static null|\Igniter\Flame\Geolite\Model\Location userPosition()
* @method static Collection deliveryAreas()
* @method static float|int deliveryAmount(void $cartTotal)
* @method static float|int minimumOrderTotal(void $orderType = null)
Expand Down
16 changes: 8 additions & 8 deletions src/Models/Concerns/HasDeliveryAreas.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Igniter\Flame\Geolite\Contracts\CoordinatesInterface;
use Igniter\Flame\Geolite\Facades\Geocoder;
use Igniter\Local\Contracts\AreaInterface;
use Igniter\Local\Models\LocationArea;

trait HasDeliveryAreas
Expand Down Expand Up @@ -38,7 +37,7 @@ protected function geocodeAddressOnSave()
return;
}

if ($this->location_lat && $this->location_lng && !$this->isDirty([
$attributesToCheck = [
'location_address_1',
'location_address_2',
'location_city',
Expand All @@ -47,7 +46,8 @@ protected function geocodeAddressOnSave()
'location_country_id',
'location_lat',
'location_lng',
])) {
];
if ($this->location_lat && $this->location_lng && !$this->isDirty($attributesToCheck)) {
return;
}

Expand All @@ -65,12 +65,12 @@ public function listDeliveryAreas()
return $this->delivery_areas->keyBy('area_id');
}

public function findDeliveryArea($areaId): ?AreaInterface
public function findDeliveryArea($areaId): ?LocationArea
{
return $this->listDeliveryAreas()->get($areaId);
}

public function searchOrDefaultDeliveryArea(?CoordinatesInterface $coordinates): ?AreaInterface
public function searchOrDefaultDeliveryArea(?CoordinatesInterface $coordinates): ?LocationArea
{
if ($coordinates && ($area = $this->searchDeliveryArea($coordinates))) {
return $area;
Expand All @@ -79,7 +79,7 @@ public function searchOrDefaultDeliveryArea(?CoordinatesInterface $coordinates):
return $this->delivery_areas->where('is_default', 1)->first();
}

public function searchOrFirstDeliveryArea(?CoordinatesInterface $coordinates): ?AreaInterface
public function searchOrFirstDeliveryArea(?CoordinatesInterface $coordinates): ?LocationArea
{
if ($coordinates && ($area = $this->searchDeliveryArea($coordinates))) {
return $area;
Expand All @@ -88,11 +88,11 @@ public function searchOrFirstDeliveryArea(?CoordinatesInterface $coordinates): ?
return $this->delivery_areas->first();
}

public function searchDeliveryArea(CoordinatesInterface $coordinates): ?AreaInterface
public function searchDeliveryArea(CoordinatesInterface $coordinates): ?LocationArea
{
return $this->delivery_areas
->sortBy('priority')
->first(function(AreaInterface $model) use ($coordinates) {
->first(function(LocationArea $model) use ($coordinates) {
return $model->checkBoundary($coordinates);
});
}
Expand Down
1 change: 1 addition & 0 deletions src/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* @property-read mixed $thumb
* @property-read Collection<int, Media> $media
* @property-read int|null $media_count
* @property-read float|null $distance
* @method static Location first()
* @method static Builder|Location selectDistance()
* @mixin Model
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Igniter\Local\Models;

use Igniter\Cart\Models\Order;
use Igniter\Flame\Database\Builder;
use Igniter\Flame\Database\Factories\HasFactory;
use Igniter\Flame\Database\Model;
use Igniter\Flame\Exception\ApplicationException;
Expand Down Expand Up @@ -33,6 +34,8 @@
* @property Carbon $created_at
* @property bool $review_status
* @property Carbon $updated_at
* @property-read null|Customer $customer
* @method static Builder|Review whereReviewable()
* @mixin Model
*/
class Review extends Model
Expand Down

0 comments on commit 220c2de

Please sign in to comment.