-
Notifications
You must be signed in to change notification settings - Fork 13
[5.x] Implement weee_tax models #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jade-GG
wants to merge
4
commits into
master
Choose a base branch
from
feature/weeetax
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−0
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models\Scopes; | ||
|
|
||
| use Illuminate\Database\Eloquent\Builder; | ||
| use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Database\Eloquent\Scope; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| /** | ||
| * Remove results from the default website when website view specific is found. | ||
| */ | ||
| class ForCurrentWebsiteWithoutLimitScope implements Scope | ||
| { | ||
| public array $uniquePerWebsiteKeys; | ||
|
|
||
| /** | ||
| * @param string|array $uniquePerWebsiteKey column(s) that may be duplicate across websites, but must be unique when filtered by website. | ||
| */ | ||
| public function __construct(string|array $uniquePerWebsiteKey, public $websiteIdColumn = 'website_id') | ||
| { | ||
| $this->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')) | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Builder; | ||
| use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
| use Rapidez\Core\Models\Scopes\ForCurrentWebsiteWithoutLimitScope; | ||
|
|
||
| class WeeeTax extends Model | ||
| { | ||
| const CREATED_AT = null; | ||
| const UPDATED_AT = null; | ||
|
|
||
| protected $table = 'weee_tax'; | ||
| protected $primaryKey = 'value_id'; | ||
|
|
||
| protected $casts = [ | ||
| 'value' => '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', | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.