-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for image disabled option (#381)
- Loading branch information
1 parent
800877e
commit d896bcb
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,24 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Models; | ||
|
||
use Rapidez\Core\Models\Scopes\ForCurrentStoreWithoutLimitScope; | ||
|
||
class ProductImageValue extends Model | ||
{ | ||
protected $table = 'catalog_product_entity_media_gallery_value'; | ||
|
||
protected $primaryKey = 'record_id'; | ||
|
||
public $timestamps = false; | ||
|
||
protected static function booted(): void | ||
{ | ||
static::addGlobalScope(new ForCurrentStoreWithoutLimitScope('value_id')); | ||
} | ||
|
||
public function productImage() | ||
{ | ||
return $this->belongsTo(config('rapidez.models.product_image'), 'value_id'); | ||
} | ||
} |
This file contains 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,41 @@ | ||
<?php | ||
|
||
namespace Rapidez\Core\Models\Scopes; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Scope; | ||
|
||
/** | ||
* Remove results from the default store when store view specific is found. | ||
*/ | ||
class ForCurrentStoreWithoutLimitScope implements Scope | ||
{ | ||
public function __construct(public $uniquePerStoreKey, public $storeIdColumn = 'store_id') | ||
{ | ||
} | ||
|
||
public function apply(Builder $query, Model $model) | ||
{ | ||
if (! config('rapidez.store')) { | ||
return $query | ||
->where($query->qualifyColumn($this->storeIdColumn), 0); | ||
} | ||
|
||
return $query | ||
// Pre-filter results to be default and current store only. | ||
->whereIn($query->qualifyColumn($this->storeIdColumn), [0, config('rapidez.store')]) | ||
// Remove values from the default store where values for the current store exist. | ||
->where(fn ($query) => $query | ||
// Remove values where we already have values in the current store. | ||
->whereNotIn($query->qualifyColumn($this->uniquePerStoreKey), fn ($query) => $query | ||
->select($model->qualifyColumn($this->uniquePerStoreKey)) | ||
->from($model->getTable()) | ||
->whereColumn($model->qualifyColumn($this->uniquePerStoreKey), $model->qualifyColumn($this->uniquePerStoreKey)) | ||
->where($model->qualifyColumn($this->storeIdColumn), config('rapidez.store')) | ||
) | ||
// Unless the value IS the current store. | ||
->orWhere($query->qualifyColumn($this->storeIdColumn), config('rapidez.store')) | ||
); | ||
} | ||
} |