Skip to content

Commit

Permalink
Bump address to v3.3 - using Zoneable
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Apr 10, 2024
1 parent 21cd075 commit d6e7ada
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 75 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Added Laravel 11 Support
- Changed minimum Laravel version to v10.43
- Changed minimal Enum requirement to v4.2
- Changed minimal Address module requirement to v3.3
- Upgraded to Konekt Address, Customer and User modules to v3
- Upgraded to Laravel Media Library v11
- Removed the Vanilo v2 `Framework` namespace compatibility layer
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"spatie/laravel-medialibrary": "^11.0",
"cviebrock/eloquent-sluggable": "^10.0|^11.0",
"konekt/laravel-migration-compatibility": "^1.6",
"konekt/address": "^3.1",
"konekt/address": "^3.3.1",
"konekt/customer": "^3.0",
"konekt/user": "^3.0",
"konekt/search": "^1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/Channel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"phpunit/phpunit": "^10.0",
"orchestra/testbench": "^8.0|^9.0",
"laravel/legacy-factories": "^1.0",
"konekt/address": "^3.0"
"konekt/address": "^3.3.1"
},
"suggest": {
"konekt/address": "To support billing and shipping zones (^3.0)"
"konekt/address": "To support billing and shipping zones (^3.3)"
},
"autoload": {
"psr-4": { "Vanilo\\Channel\\": "" }
Expand Down
1 change: 1 addition & 0 deletions src/Checkout/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Added Laravel 11 Support
- Changed minimum Laravel version to v10.43
- Changed minimal Enum requirement to v4.2
- Changed minimal Address requirement to v3.3
- Added the `BillpayerChanged` event
- BC: Removed the following traits:
- `HasCart`
Expand Down
2 changes: 1 addition & 1 deletion src/Checkout/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"require-dev": {
"phpunit/phpunit": "^10.0",
"orchestra/testbench": "^8.0|^9.0",
"konekt/address": "^3.0"
"konekt/address": "^3.3.1"
},
"autoload": {
"psr-4": { "Vanilo\\Checkout\\": "" }
Expand Down
2 changes: 1 addition & 1 deletion src/Order/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"php": "^8.2",
"konekt/address": "^3.0",
"konekt/address": "^3.3.1",
"konekt/concord": "^1.13",
"konekt/enum": "^4.2",
"konekt/laravel-migration-compatibility": "^1.6",
Expand Down
1 change: 1 addition & 0 deletions src/Shipment/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Added Laravel 11 Support
- Changed minimum Laravel version to v10.43
- Changed minimal Enum requirement to v4.2
- Changed minimal Address module requirement to v3.3
- Added `isZoneRestricted()` & `isNotZoneRestricted()` helper methods to the `ShippingMethod` class
- BC: Changed the ShippingFeeCalculator, Carrier and Shipment interfaces to Configurable & Schematized
- BC: Added the `getCalculator()` & `estimate()` methods to the `ShippingMethod` interface
Expand Down
39 changes: 2 additions & 37 deletions src/Shipment/Models/ShippingMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Collection;
use Konekt\Address\Concerns\Zoneable;
use Konekt\Address\Contracts\Zone;
use Konekt\Address\Models\ZoneProxy;
use Vanilo\Contracts\Schematized;
use Vanilo\Shipment\Calculators\NullShippingFeeCalculator;
use Vanilo\Shipment\Contracts\ShippingFeeCalculator;
Expand All @@ -38,19 +37,16 @@
* @property boolean $is_active
* @property array $configuration
*
* @property-read Zone|null $zone
*
* @method static Builder actives()
* @method static Builder inactives()
* @method static Builder forZone(Zone|int $zone)
* @method static Builder forZones(array|Collection $zones)
*
* @method static ShippingMethod create(array $attributes)
*/
class ShippingMethod extends Model implements ShippingMethodContract
{
use BelongsToCarrier;
use ConfigurableModel;
use Zoneable;

protected $guarded = ['id', 'created_at', 'updated_at'];

Expand Down Expand Up @@ -85,26 +81,11 @@ public function estimate(?object $subject = null): ShippingFee
return $this->getCalculator()->calculate($subject, $this->configuration());
}

public function isZoneRestricted(): bool
{
return null !== $this->zone_id;
}

public function isNotZoneRestricted(): bool
{
return !$this->isZoneRestricted();
}

public function getConfigurationSchema(): ?Schematized
{
return SchemaDefinition::wrap($this->getCalculator());
}

public function zone(): BelongsTo
{
return $this->belongsTo(ZoneProxy::modelClass(), 'zone_id', 'id');
}

public function scopeActives(Builder $query): Builder
{
return $query->where('is_active', true);
Expand All @@ -114,20 +95,4 @@ public function scopeInactives(Builder $query): Builder
{
return $query->where('is_active', false);
}

public function scopeForZone(Builder $query, Zone|int $zone): Builder
{
return $query->where('zone_id', is_int($zone) ? $zone : $zone->id);
}

public function scopeForZones(Builder $query, array|Collection $zones): Builder
{
if (is_array($zones)) {
$zones = array_map(fn (Zone|int $zone) => is_int($zone) ? $zone : $zone->id, $zones);
} else {
$zones = $zones->map(fn (Zone $zone) => $zone->id);
}

return $query->whereIn('zone_id', $zones);
}
}
2 changes: 1 addition & 1 deletion src/Shipment/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"php": "^8.2",
"konekt/address": "^3.0",
"konekt/address": "^3.3.1",
"konekt/concord": "^1.13",
"konekt/enum": "^4.2",
"konekt/laravel-migration-compatibility": "^1.6",
Expand Down
2 changes: 1 addition & 1 deletion src/Support/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"suggest": {
"spatie/laravel-medialibrary": "Allows associating images or other files with Eloquent models (^11.0)",
"konekt/concord": "Library to write Modular Applications (^1.13)",
"konekt/address": "Improves the EU membership and VAT ID validation (^3.1)"
"konekt/address": "Improves the EU membership and VAT ID validation (^3.3)"
},
"extra": {
"branch-alias": {
Expand Down
2 changes: 1 addition & 1 deletion src/Taxes/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

- Dropped PHP 8.0 & PHP 8.1 Support
- Dropped Laravel 9 Support
- Upgraded to Konekt Address v3
- Upgraded to Konekt Address v3.3+
- Added PHP 8.3 Support
- Added Laravel 11 Support
- Changed minimum Laravel version to v10.43
Expand Down
31 changes: 2 additions & 29 deletions src/Taxes/Models/TaxRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Konekt\Address\Concerns\Zoneable;
use Konekt\Address\Contracts\Zone;
use Konekt\Address\Models\ZoneProxy;
use Vanilo\Contracts\Schematized;
Expand All @@ -45,18 +46,16 @@
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read TaxCategory|null $taxCategory
* @property-read Zone|null $zone
*
* @method static Builder byTaxCategory(TaxCategory|int $taxCategory)
* @method Builder forZone(Zone|int $zone)
* @method Builder forZones(array|Collection $zones)
* @method Builder actives()
* @method Builder inactives()
*/
class TaxRate extends Model implements TaxRateContract
{
use BelongsToTaxCategory;
use ConfigurableModel;
use Zoneable;

protected $guarded = ['id', 'created_at', 'updated_at'];

Expand Down Expand Up @@ -97,11 +96,6 @@ public function getName(): string
return $this->name;
}

public function getZone(): ?Zone
{
return $this->zone;
}

public function getTaxCategory(): ?TaxCategory
{
return $this->taxCategory;
Expand All @@ -126,11 +120,6 @@ public function getConfigurationSchema(): ?Schematized
return SchemaDefinition::wrap($this->getCalculator());
}

public function zone(): BelongsTo
{
return $this->belongsTo(ZoneProxy::modelClass(), 'zone_id', 'id');
}

public function scopeActives(Builder $query): Builder
{
return $query->where('is_active', true);
Expand All @@ -141,22 +130,6 @@ public function scopeInactives(Builder $query): Builder
return $query->where('is_active', false);
}

public function scopeForZone(Builder $query, Zone|int $zone): Builder
{
return $query->where('zone_id', is_int($zone) ? $zone : $zone->id);
}

public function scopeForZones(Builder $query, array|Collection $zones): Builder
{
if (is_array($zones)) {
$zones = array_map(fn (Zone|int $zone) => is_int($zone) ? $zone : $zone->id, $zones);
} else {
$zones = $zones->map(fn (Zone $zone) => $zone->id);
}

return $query->whereIn('zone_id', $zones);
}

public function scopeByTaxCategory(Builder $query, TaxCategory|int $taxCategory): Builder
{
return $query->where('tax_category_id', is_int($taxCategory) ? $taxCategory : $taxCategory->id);
Expand Down
2 changes: 1 addition & 1 deletion src/Taxes/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require": {
"php": "^8.2",
"konekt/concord": "^1.13",
"konekt/address": "^3.0",
"konekt/address": "^3.3.1",
"konekt/enum": "^4.2",
"konekt/laravel-migration-compatibility": "^1.6",
"laravel/framework": "^10.43|^11.0",
Expand Down

0 comments on commit d6e7ada

Please sign in to comment.