-
Notifications
You must be signed in to change notification settings - Fork 13
Use EAV structure instead of flat tables #943
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
100 commits
Select commit
Hold shift + click to select a range
841685b
Implement EAV structure for product entity
Jade-GG 78a47ec
Apply fixes from Duster
Jade-GG 77c9a41
Fix model name
Jade-GG 42a1a7e
Get store specific values
Jade-GG ee340e9
Apply fixes from Duster
Jade-GG 9cfed19
Allow for values to be queried on, filter products based on website a…
Jade-GG 30c975e
Apply fixes from Duster
Jade-GG 573f3bf
Rename EavAttribute to AbstractAttribute
Jade-GG 9184a38
Apply fixes from Duster
Jade-GG 0cda5c0
Add stock data to products
Jade-GG 9766b95
Apply fixes from Duster
Jade-GG dbe6403
Rename Datetime
Jade-GG e6b9338
Delete src/Models/AttributeDateTime.php
Jade-GG 22b4949
Cast value properly when getting
Jade-GG 521423d
Apply fixes from Duster
Jade-GG b6fef4c
Small fixes
Jade-GG 24c785d
Add parent, children, super attributes & super attribute values
Jade-GG b72b189
Apply fixes from Duster
Jade-GG f5fcd82
Add consts
Jade-GG 1ec5263
Fix sorting on super attributes & change whereValue to whereAttribute
Jade-GG 8594af0
Apply fixes from Duster
Jade-GG 46f1854
Rename product, use config rapidez.model, add callbacks, abstractify …
Jade-GG ab8aeda
Still return falsy values
Jade-GG 0bab9eb
Remove old scopes, update HasAlternates to include rewrites relation
Jade-GG 3f25db8
Apply fixes from Duster
Jade-GG 98aacc5
Remove unnecessary casts
Jade-GG 052ba64
Add URL, images, price for configurable/grouped products, move stuff …
Jade-GG 7e934b7
Apply fixes from Duster
Jade-GG f310cc7
Simplify price & add specialPrice
Jade-GG baae5d8
Merge branch 'feature/flat-tables' of https://github.com/rapidez/core…
Jade-GG e42bdc5
Apply fixes from Duster
Jade-GG c7c4da2
Make custom attributes trait slightly more abstract, add product link…
Jade-GG 7faf8d3
Apply fixes from Duster
Jade-GG 0830d95
Add inverted product links
Jade-GG c13f98c
Add category info & use config models
Jade-GG f3e8018
Add minSaleQty
Jade-GG 9c0f104
Add breadcrumb categories
Jade-GG c8499d0
Add reviewSummary
Jade-GG b50ce36
Fix bug & add toArray for indexing
Jade-GG d265943
Allow indexing (but slow)
Jade-GG 5262dcf
Apply fixes from Duster
Jade-GG 2240d05
Formatting
Jade-GG 3947219
Add tier pricing
Jade-GG 1097b17
Apply fixes from Duster
Jade-GG 16993dc
Merge pull request #985 from rapidez/feature/flat-tables-tier-pricing
royduin 9602fe3
Fix performance
Jade-GG cdb4c9b
Apply fixes from Duster
Jade-GG 21a2620
Merge branch 'master' into feature/flat-tables
royduin ded4821
Fix product pages & improve given product data
Jade-GG e4ed907
Add todo
Jade-GG 6815f9b
Apply fixes from Duster
Jade-GG 8fac631
Fix categories & super attributes
Jade-GG 2e535bf
Apply fixes from Duster
Jade-GG 71abd6b
Merge branch 'feature/flat-tables' into feature/flat-tables-product-data
Jade-GG 2523f8a
[CI] Update Snapshots
Jade-GG 94eca16
Fix super attributes swatch data
Jade-GG 9ad97eb
Merge branch 'feature/flat-tables-product-data' of https://github.com…
Jade-GG 49f6c47
[CI] Update Snapshots
Jade-GG ae91e4d
Merge pull request #1050 from rapidez/feature/flat-tables-product-data
royduin 18c484f
Explose stock implementation
royduin 10d4dd1
Apply fixes from Duster
royduin 8728146
Accessors for backwards compatiblity
royduin 275272d
Switched the fallback method so relations can be used
royduin eca329b
Fixed the grouped products, relation prices and breadcrumbs for inact…
royduin 4682610
Use the non-deprecated naming
royduin 53a9b0f
Merge branch 'feature/flat-tables' of github.com:rapidez/core into fe…
royduin 2f24eef
Apply fixes from Duster
royduin 035e093
Moved the product backwards compatibile accessors to a trait
royduin ea83753
Partially implement super attributes & small value refactor (#1052)
Jade-GG 77c5031
Add basic product unit tests & fix things that came out of that
Jade-GG 0e90b38
Apply fixes from Duster
Jade-GG 910e4a2
Fix error on PDP
Jade-GG e4d2be8
Model serialization: hide relations and add all attributes
royduin 556c1e0
Merge branch 'feature/flat-tables' into feature/flat-tables-unit-tests
royduin d640e72
Merge pull request #1056 from rapidez/feature/flat-tables-unit-tests
royduin 2a9d437
Index and caching improvements
royduin e089a97
Performance improvements
royduin 7242ce4
Use the price index table + improved model config usage
royduin 983b128
Apply fixes from Duster
royduin fdaf3c5
Unguard all models
royduin 6918192
Todo
royduin c168e9b
Use database transactions for unit tests
royduin 82c991c
Product options and views test
royduin a7d99a2
Apply fixes from Duster
royduin 0382b93
Apply catalog price rules correctly everywhere
royduin 5aee223
Merge branch 'feature/flat-tables' of github.com:rapidez/core into fe…
royduin f9c98ac
Apply fixes from Duster
royduin 5302d3d
Scopes cleanup
royduin 703f73b
Merge branch 'feature/flat-tables' of github.com:rapidez/core into fe…
royduin 7792694
Apply fixes from Duster
royduin a7b0474
Implemented the visibility differently
royduin 4b0056f
Merge branch 'feature/flat-tables' of github.com:rapidez/core into fe…
royduin 7bf82e7
Apply fixes from Duster
royduin 01c1202
Import
royduin 47e2dd5
Merge branch 'feature/flat-tables' of github.com:rapidez/core into fe…
royduin 447dc16
Todo
royduin 060e341
Product special price fixes, exclude bundle products and seperated pr…
royduin 77b1ede
Apply fixes from Duster
royduin 7602422
Update CHANGELOG
royduin 851f775
Merge branch 'master' into feature/flat-tables
royduin 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?php | ||
|
|
||
| return [ | ||
| 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend' => Rapidez\Core\Models\AttributeModels\ArrayBackend::class, | ||
| ]; |
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,8 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| class AttributeDateTime extends EavAttribute | ||
| { | ||
| protected $casts = ['value' => 'datetime']; | ||
| } |
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,8 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| class AttributeDecimal extends EavAttribute | ||
| { | ||
| protected $casts = ['value' => 'float']; | ||
| } |
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,10 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| use Rapidez\Core\Models\Traits\HasAttributeOptions; | ||
|
|
||
| class AttributeInt extends EavAttribute | ||
| { | ||
| use HasAttributeOptions; | ||
| } |
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,13 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models\AttributeModels; | ||
|
|
||
| class ArrayBackend implements AttributeModel | ||
| { | ||
| public static function value($value, $attribute) | ||
| { | ||
| $values = explode(',', $value); | ||
|
|
||
| return collect($values)->map(fn ($value) => $attribute->options[$value]?->value ?? $value); | ||
| } | ||
| } |
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,8 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models\AttributeModels; | ||
|
|
||
| interface AttributeModel | ||
| { | ||
| public static function value($value, $attribute); | ||
| } |
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,23 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| use Illuminate\Contracts\Database\Eloquent\Builder; | ||
| use Illuminate\Database\Query\JoinClause; | ||
|
|
||
| class AttributeOption extends Model | ||
| { | ||
| protected $table = 'eav_attribute_option'; | ||
|
|
||
| protected static function boot(): void | ||
| { | ||
| parent::boot(); | ||
|
|
||
| static::addGlobalScope('values', function (Builder $builder) { | ||
| $builder->leftJoin('eav_attribute_option_value', function (JoinClause $join) use ($builder) { | ||
| $join->on($builder->qualifyColumn('option_id'), '=', 'eav_attribute_option_value.option_id') | ||
| ->whereIn('store_id', [0, config('rapidez.store')]); | ||
| }); | ||
| }); | ||
| } | ||
| } |
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,10 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| use Rapidez\Core\Models\Traits\HasAttributeOptions; | ||
|
|
||
| class AttributeText extends EavAttribute | ||
| { | ||
| use HasAttributeOptions; | ||
| } |
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,10 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| use Rapidez\Core\Models\Traits\HasAttributeOptions; | ||
|
|
||
| class AttributeVarchar extends EavAttribute | ||
| { | ||
| use HasAttributeOptions; | ||
| } |
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,58 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Builder; | ||
| use Illuminate\Database\Eloquent\Casts\Attribute; | ||
| use Illuminate\Support\Facades\Cache; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Rapidez\Core\Models\Scopes\ForCurrentStoreWithoutLimitScope; | ||
|
|
||
| class EavAttribute extends Model | ||
| { | ||
| protected static function boot(): void | ||
| { | ||
| parent::boot(); | ||
|
|
||
| static::addGlobalScope(new ForCurrentStoreWithoutLimitScope(['attribute_id', 'entity_id'])); | ||
|
|
||
| static::addGlobalScope('attribute', function (Builder $builder) { | ||
| $builder->leftJoin('eav_attribute', $builder->qualifyColumn('attribute_id'), '=', 'eav_attribute.attribute_id'); | ||
| }); | ||
|
|
||
| if (isset(static::$hasAttributeOptions)) { // @phpstan-ignore-line | ||
| static::addGlobalScope('attributeOptions', function (Builder $builder) { | ||
| $builder->with('attributeOptions'); // @phpstan-ignore-line | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| public static function getCached() | ||
| { | ||
| return Cache::rememberForever('eav_attributes', function () { | ||
| return DB::table('eav_attribute')->get()->keyBy('attribute_code'); | ||
| }); | ||
| } | ||
|
|
||
| public function getTable() | ||
| { | ||
| // Overwritten to always return table, so that qualifyColumn and such work | ||
| return $this->table; | ||
| } | ||
|
|
||
| protected function value(): Attribute | ||
| { | ||
| return Attribute::get(function ($value) { | ||
| if ($this->frontend_input === 'select') { | ||
| return $this->options[$value]?->value ?? $value; | ||
| } | ||
|
|
||
| $class = config('rapidez.attribute-models')[$this->backend_model] ?? null; | ||
| if ($class) { | ||
| return $class::value($value, $this); | ||
| } | ||
|
|
||
| return $value; | ||
| }); | ||
| } | ||
| } |
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,53 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| use Illuminate\Contracts\Database\Eloquent\Builder; | ||
| use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
| use Rapidez\Core\Models\Scopes\Product\ForCurrentWebsiteScope; | ||
| use Rapidez\Core\Models\Traits\HasCustomAttributes; | ||
|
|
||
| class ProductEntity extends Model | ||
| { | ||
| use HasCustomAttributes; | ||
|
|
||
| protected $table = 'catalog_product_entity'; | ||
| protected $primaryKey = 'entity_id'; | ||
|
|
||
| protected $casts = [ | ||
| self::UPDATED_AT => 'datetime', | ||
| self::CREATED_AT => 'datetime', | ||
| ]; | ||
|
|
||
| protected static function boot(): void | ||
| { | ||
| parent::boot(); | ||
|
|
||
| static::addGlobalScope(ForCurrentWebsiteScope::class); | ||
| static::addGlobalScope('customAttributes', fn (Builder $builder) => $builder->withCustomAttributes()); | ||
| static::addGlobalScope('onlyEnabled', fn (Builder $builder) => $builder->whereValue('status', 1)); | ||
| } | ||
|
|
||
| public function gallery(): BelongsToMany | ||
| { | ||
| return $this->belongsToMany( | ||
| config('rapidez.models.product_image'), | ||
| 'catalog_product_entity_media_gallery_value_to_entity', | ||
| 'entity_id', | ||
| 'value_id', | ||
| ); | ||
| } | ||
|
|
||
| public function getAttribute($key) | ||
| { | ||
| if (! $key) { | ||
| return; | ||
| } | ||
|
|
||
| if ($value = parent::getAttribute($key)) { | ||
| return $value; | ||
| } | ||
|
|
||
| return $this->getCustomAttribute($key)?->value; | ||
| } | ||
| } |
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,10 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class ProductStock extends Model | ||
| { | ||
| protected $table = 'cataloginventory_stock_item'; | ||
| } |
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,16 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models\Scopes\Product; | ||
|
|
||
| use Illuminate\Database\Eloquent\Builder; | ||
| use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Database\Eloquent\Scope; | ||
|
|
||
| class ForCurrentWebsiteScope implements Scope | ||
| { | ||
| public function apply(Builder $builder, Model $model) | ||
| { | ||
| $builder->leftJoin('catalog_product_website', 'product_id', '=', $model->getQualifiedKeyName()); | ||
| $builder->where('website_id', 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,26 @@ | ||
| <?php | ||
|
|
||
| namespace Rapidez\Core\Models\Traits; | ||
|
|
||
| use Illuminate\Database\Eloquent\Casts\Attribute; | ||
| use Illuminate\Database\Eloquent\Relations\HasMany; | ||
| use Rapidez\Core\Models\AttributeOption; | ||
|
|
||
| trait HasAttributeOptions | ||
| { | ||
| protected static $hasAttributeOptions = true; | ||
|
|
||
| protected function options(): Attribute | ||
| { | ||
| // Sort by store_id first to always get the higher store id if there are two. | ||
| return Attribute::get(fn () => $this->attributeOptions | ||
| ->sortBy('store_id') | ||
| ->keyBy('option_id') | ||
| ); | ||
| } | ||
|
|
||
| public function attributeOptions(): HasMany | ||
| { | ||
| return $this->hasMany(AttributeOption::class, 'attribute_id', 'attribute_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.