Skip to content
Draft
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
841685b
Implement EAV structure for product entity
Jade-GG Jul 24, 2025
78a47ec
Apply fixes from Duster
Jade-GG Jul 24, 2025
77c9a41
Fix model name
Jade-GG Jul 24, 2025
42a1a7e
Get store specific values
Jade-GG Jul 24, 2025
ee340e9
Apply fixes from Duster
Jade-GG Jul 24, 2025
9cfed19
Allow for values to be queried on, filter products based on website a…
Jade-GG Jul 24, 2025
30c975e
Apply fixes from Duster
Jade-GG Jul 24, 2025
573f3bf
Rename EavAttribute to AbstractAttribute
Jade-GG Jul 24, 2025
9184a38
Apply fixes from Duster
Jade-GG Jul 24, 2025
0cda5c0
Add stock data to products
Jade-GG Jul 24, 2025
9766b95
Apply fixes from Duster
Jade-GG Jul 24, 2025
dbe6403
Rename Datetime
Jade-GG Jul 24, 2025
e6b9338
Delete src/Models/AttributeDateTime.php
Jade-GG Jul 24, 2025
22b4949
Cast value properly when getting
Jade-GG Jul 24, 2025
521423d
Apply fixes from Duster
Jade-GG Jul 24, 2025
b6fef4c
Small fixes
Jade-GG Jul 24, 2025
24c785d
Add parent, children, super attributes & super attribute values
Jade-GG Jul 24, 2025
b72b189
Apply fixes from Duster
Jade-GG Jul 24, 2025
f5fcd82
Add consts
Jade-GG Jul 24, 2025
1ec5263
Fix sorting on super attributes & change whereValue to whereAttribute
Jade-GG Jul 24, 2025
8594af0
Apply fixes from Duster
Jade-GG Jul 24, 2025
46f1854
Rename product, use config rapidez.model, add callbacks, abstractify …
Jade-GG Aug 6, 2025
ab8aeda
Still return falsy values
Jade-GG Aug 6, 2025
0bab9eb
Remove old scopes, update HasAlternates to include rewrites relation
Jade-GG Aug 6, 2025
3f25db8
Apply fixes from Duster
Jade-GG Aug 6, 2025
98aacc5
Remove unnecessary casts
Jade-GG Aug 6, 2025
052ba64
Add URL, images, price for configurable/grouped products, move stuff …
Jade-GG Aug 6, 2025
7e934b7
Apply fixes from Duster
Jade-GG Aug 6, 2025
f310cc7
Simplify price & add specialPrice
Jade-GG Aug 6, 2025
baae5d8
Merge branch 'feature/flat-tables' of https://github.com/rapidez/core…
Jade-GG Aug 6, 2025
e42bdc5
Apply fixes from Duster
Jade-GG Aug 6, 2025
c7c4da2
Make custom attributes trait slightly more abstract, add product link…
Jade-GG Aug 7, 2025
7faf8d3
Apply fixes from Duster
Jade-GG Aug 7, 2025
0830d95
Add inverted product links
Jade-GG Aug 7, 2025
c13f98c
Add category info & use config models
Jade-GG Aug 7, 2025
f3e8018
Add minSaleQty
Jade-GG Aug 7, 2025
9c0f104
Add breadcrumb categories
Jade-GG Aug 7, 2025
c8499d0
Add reviewSummary
Jade-GG Aug 7, 2025
b50ce36
Fix bug & add toArray for indexing
Jade-GG Aug 7, 2025
d265943
Allow indexing (but slow)
Jade-GG Aug 8, 2025
5262dcf
Apply fixes from Duster
Jade-GG Aug 8, 2025
2240d05
Formatting
Jade-GG Aug 8, 2025
3947219
Add tier pricing
Jade-GG Aug 26, 2025
1097b17
Apply fixes from Duster
Jade-GG Aug 26, 2025
16993dc
Merge pull request #985 from rapidez/feature/flat-tables-tier-pricing
royduin Aug 27, 2025
9602fe3
Fix performance
Jade-GG Sep 1, 2025
cdb4c9b
Apply fixes from Duster
Jade-GG Sep 1, 2025
21a2620
Merge branch 'master' into feature/flat-tables
royduin Oct 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/rapidez/attribute-models.php
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,
];
3 changes: 3 additions & 0 deletions config/rapidez/magento-defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
'catalog/seo/category_url_suffix' => '.html',
'catalog/seo/product_url_suffix' => '.html',
'cataloginventory/item_options/backorders' => '0',
'cataloginventory/item_options/min_sale_qty' => '1',
'cataloginventory/item_options/max_sale_qty' => '10000',
'cataloginventory/item_options/qty_increments' => '1',
'cataloginventory/options/show_out_of_stock' => '0',
'checkout/cart/redirect_to_cart' => '0',
'currency/options/default' => 'USD',
Expand Down
17 changes: 17 additions & 0 deletions config/rapidez/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
// Should the stock qty be exposed and indexed within Elasticsearch?
'expose_stock' => false,

// Which columns in the `cataloginventory_stock_item` table should be exposed?
// Add `qty` to this to expose the current stock to the frontend
'exposed_stock_columns' => [
'min_sale_qty',
'max_sale_qty',
'qty_increments',
'backorders',

// These are necessary to make sure we use the config value when available
'use_config_min_sale_qty',
'use_config_max_sale_qty',
'use_config_qty_increments',
'use_config_backorders',

'is_in_stock',
],

'standalone_checkout' => [
// What cache store should be used to store temporary standalone checkout credentials
'cache_store' => env('STANDALONE_CHECKOUT_CACHE_STORE', config('cache.default')),
Expand Down
49 changes: 49 additions & 0 deletions src/Models/AbstractAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Rapidez\Core\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Rapidez\Core\Models\Scopes\ForCurrentStoreWithoutLimitScope;

class AbstractAttribute 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 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 array_key_exists('value', $this->getCasts()) ? $this->castAttribute('value', $value) : $value;
});
}
}
8 changes: 8 additions & 0 deletions src/Models/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Casts\Attribute as CastsAttribute;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Rapidez\Core\Models\Scopes\Attribute\OnlyProductAttributesScope;

class Attribute extends Model
Expand Down Expand Up @@ -44,6 +45,13 @@ protected function prefix(): CastsAttribute
)->shouldCache();
}

public static function getCached()
{
return Cache::rememberForever('eav_attributes', function () {
return DB::table('eav_attribute')->get()->keyBy('attribute_code');
});
}

public static function getCachedWhere(callable $callback): array
{
$attributes = Cache::store('rapidez:multi')->rememberForever('attributes.' . config('rapidez.store'), function () {
Expand Down
8 changes: 8 additions & 0 deletions src/Models/AttributeDatetime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Rapidez\Core\Models;

class AttributeDatetime extends AbstractAttribute
{
protected $casts = ['value' => 'datetime'];
}
8 changes: 8 additions & 0 deletions src/Models/AttributeDecimal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Rapidez\Core\Models;

class AttributeDecimal extends AbstractAttribute
{
protected $casts = ['value' => 'float'];
}
10 changes: 10 additions & 0 deletions src/Models/AttributeInt.php
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 AbstractAttribute
{
use HasAttributeOptions;
}
13 changes: 13 additions & 0 deletions src/Models/AttributeModels/ArrayBackend.php
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);
}
}
8 changes: 8 additions & 0 deletions src/Models/AttributeModels/AttributeModel.php
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);
}
23 changes: 23 additions & 0 deletions src/Models/AttributeOption.php
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')]);
});
});
}
}
10 changes: 10 additions & 0 deletions src/Models/AttributeText.php
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 AbstractAttribute
{
use HasAttributeOptions;
}
10 changes: 10 additions & 0 deletions src/Models/AttributeVarchar.php
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 AbstractAttribute
{
use HasAttributeOptions;
}
112 changes: 112 additions & 0 deletions src/Models/ProductEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Rapidez\Core\Models;

use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
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 $with = ['stock', 'superAttributes'];

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 parent(): HasOneThrough
{
return $this->hasOneThrough(
ProductEntity::class,
config('rapidez.models.product_link'),
'product_id', 'entity_id',
'entity_id', 'parent_id'
);
}

public function children(): HasManyThrough
{
return $this->hasManyThrough(
ProductEntity::class,
config('rapidez.models.product_link'),
'parent_id', 'entity_id',
'entity_id', 'product_id'
);
}

public function stock(): BelongsTo
{
return $this->belongsTo(
ProductStock::class,
'entity_id',
'product_id',
);
}

public function superAttributes(): HasMany
{
return $this->hasMany(
SuperAttribute::class,
'product_id',
)->orderBy('position');
}

public function superAttributeValues(): Attribute
{
return Attribute::get(function() {
return $this->superAttributes->pluck('attribute_code')
->mapWithKeys(fn ($attribute) => [
$attribute => $this->children->mapWithKeys(function ($child) use ($attribute) {
return [$child->entity_id => [
'label' => $child->{$attribute},
'value' => $child->customAttributes[$attribute]->value_id,
]];
})
]);
});
}

public function getAttribute($key)
{
if (! $key) {
return;
}

if ($value = parent::getAttribute($key)) {
return $value;
}

return $this->getCustomAttribute($key)?->value;
}
}
28 changes: 28 additions & 0 deletions src/Models/ProductStock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Rapidez\Core\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Rapidez\Core\Facades\Rapidez;

class ProductStock extends Model
{
protected $table = 'cataloginventory_stock_item';

public static function boot()
{
parent::boot();

static::addGlobalScope('onlyExposedColumns', fn (Builder $builder) => $builder->select(['product_id', ...config('rapidez.exposed_stock_columns')]));
}

public function __get($key)
{
if ($this->hasAttribute('use_config_' . $key) && $this->getAttribute('use_config_' . $key) == 1) {
return Rapidez::config('cataloginventory/item_options/' . $key);
}

return parent::__get($key);
}
}
Loading