From 0ebc3396d2be47e884e99b5ee9f94842f56b654d Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 8 Jul 2026 15:04:09 +0200 Subject: [PATCH 1/4] Implement weee_tax models --- config/rapidez/models.php | 1 + src/Models/Product.php | 9 +++ .../ForCurrentWebsiteWithoutLimitScope.php | 56 +++++++++++++++++++ src/Models/WeeeTax.php | 38 +++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 src/Models/Scopes/ForCurrentWebsiteWithoutLimitScope.php create mode 100644 src/Models/WeeeTax.php diff --git a/config/rapidez/models.php b/config/rapidez/models.php index e082d0773..3f21220f0 100644 --- a/config/rapidez/models.php +++ b/config/rapidez/models.php @@ -50,5 +50,6 @@ 'search_synonym' => Rapidez\Core\Models\SearchSynonym::class, 'store' => Rapidez\Core\Models\Store::class, 'super_attribute' => Rapidez\Core\Models\SuperAttribute::class, + 'weee_tax' => Rapidez\Core\Models\WeeeTax::class, 'widget' => Rapidez\Core\Models\Widget::class, ]; diff --git a/src/Models/Product.php b/src/Models/Product.php index 6e0cdd317..19fc050a1 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -203,6 +203,15 @@ public function tierPrices(): HasMany )->whereIn('website_id', [0, config('rapidez.website')]); } + public function fixedProductTaxes(): HasMany + { + return $this->hasMany( + config('rapidez.models.weee_tax', WeeeTax::class), + 'entity_id', + 'entity_id', + )->afterQuery(fn ($results) => $results->keyBy('attribute_code')); + } + public function getUnitPrice(int $quantity = 1, int $customerGroup = 0) { $tierPrice = $this->tierPrices() diff --git a/src/Models/Scopes/ForCurrentWebsiteWithoutLimitScope.php b/src/Models/Scopes/ForCurrentWebsiteWithoutLimitScope.php new file mode 100644 index 000000000..69e2a96ab --- /dev/null +++ b/src/Models/Scopes/ForCurrentWebsiteWithoutLimitScope.php @@ -0,0 +1,56 @@ +uniquePerWebsiteKeys = is_array($uniquePerWebsiteKey) ? $uniquePerWebsiteKey : [$uniquePerWebsiteKey]; + } + + public function apply(Builder $query, Model $model) + { + if (! config('rapidez.website')) { + return $query + ->where($query->qualifyColumn($this->websiteIdColumn), 0); + } + + $scope = $this; + + return $query + // Pre-filter results to be default and current website only. + ->whereIn($query->qualifyColumn($this->websiteIdColumn), [0, config('rapidez.website')]) + // Remove values from the default website where values for the current website exist. + ->where(fn ($query) => $query + // Remove values where we already have values in the current website. + ->where(function ($query) use ($scope, $model) { + $query + ->whereNotExists(function ($query) use ($scope, $model) { + $query + ->select(DB::raw(1)) + ->from($model->getTable() . ' as comparison') + ->where('comparison.' . $this->websiteIdColumn, config('rapidez.website')); + foreach ($scope->uniquePerWebsiteKeys as $uniquePerWebsiteKey) { + $query->whereColumn('comparison.' . $uniquePerWebsiteKey, $model->qualifyColumn($uniquePerWebsiteKey)); + } + }); + }) + // Unless the value IS the current website. + ->orWhere($query->qualifyColumn($this->websiteIdColumn), config('rapidez.website')) + ); + } +} diff --git a/src/Models/WeeeTax.php b/src/Models/WeeeTax.php new file mode 100644 index 000000000..1bbb9ccc5 --- /dev/null +++ b/src/Models/WeeeTax.php @@ -0,0 +1,38 @@ + 'float', + ]; + + protected static function booting() + { + static::addGlobalScope('website', new ForCurrentWebsiteWithoutLimitScope(['entity_id', 'attribute_id'])); + static::addGlobalScope('withAttributeData', fn (Builder $query) => + $query->leftJoin('eav_attribute', 'eav_attribute.attribute_id', 'weee_tax.attribute_id') + ); + } + + public function product(): BelongsTo + { + return $this->belongsTo( + config('rapidez.models.product'), + 'entity_id', + 'entity_id', + ); + } +} + From b067f70af7afa16768ffca00525a074c71f3affb Mon Sep 17 00:00:00 2001 From: Jade-GG Date: Wed, 8 Jul 2026 13:04:33 +0000 Subject: [PATCH 2/4] Apply fixes from Duster --- src/Models/WeeeTax.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Models/WeeeTax.php b/src/Models/WeeeTax.php index 1bbb9ccc5..8f39edc60 100644 --- a/src/Models/WeeeTax.php +++ b/src/Models/WeeeTax.php @@ -21,8 +21,7 @@ class WeeeTax extends Model protected static function booting() { static::addGlobalScope('website', new ForCurrentWebsiteWithoutLimitScope(['entity_id', 'attribute_id'])); - static::addGlobalScope('withAttributeData', fn (Builder $query) => - $query->leftJoin('eav_attribute', 'eav_attribute.attribute_id', 'weee_tax.attribute_id') + static::addGlobalScope('withAttributeData', fn (Builder $query) => $query->leftJoin('eav_attribute', 'eav_attribute.attribute_id', 'weee_tax.attribute_id') ); } @@ -35,4 +34,3 @@ public function product(): BelongsTo ); } } - From 4ba0796e5129759388d56e805153f19183a6ff99 Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Mon, 13 Jul 2026 14:11:09 +0200 Subject: [PATCH 3/4] Remove afterQuery --- src/Models/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Product.php b/src/Models/Product.php index 19fc050a1..657eabdb2 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -209,7 +209,7 @@ public function fixedProductTaxes(): HasMany config('rapidez.models.weee_tax', WeeeTax::class), 'entity_id', 'entity_id', - )->afterQuery(fn ($results) => $results->keyBy('attribute_code')); + ); } public function getUnitPrice(int $quantity = 1, int $customerGroup = 0) From f66dc2d630b02b8201e3f4c631c1da62edb47542 Mon Sep 17 00:00:00 2001 From: Jade Geels Date: Mon, 13 Jul 2026 14:13:01 +0200 Subject: [PATCH 4/4] Remove timestamps the right way --- src/Models/WeeeTax.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Models/WeeeTax.php b/src/Models/WeeeTax.php index 8f39edc60..969ac08fa 100644 --- a/src/Models/WeeeTax.php +++ b/src/Models/WeeeTax.php @@ -8,8 +8,7 @@ class WeeeTax extends Model { - const CREATED_AT = null; - const UPDATED_AT = null; + public $timestamps = false; protected $table = 'weee_tax'; protected $primaryKey = 'value_id';