Skip to main content
Attributes define product characteristics like Color, Size, or Material. They enable variable products, enhance filtering, and provide detailed product specifications.

Models

Shopper uses three models to manage attributes: The Attribute model implements Shopper\Core\Models\Contracts\Attribute and uses the HasSlug trait for automatic slug generation. Unlike products or brands, the Attribute model is not configurable via config/shopper/models.php and has no admin model wrapper.

Database Schema

Attribute Table

AttributeValue Table

AttributeProduct Table (Pivot)

Field Types

Attributes use the FieldType enum to determine input behavior:

Type Checking Methods

Each attribute type has helper methods to determine its behavior:
hasMultipleValues() returns true for Checkbox and ColorPicker. hasSingleValue() returns true for Select. hasTextValue() returns true for Text, Number, RichText, and DatePicker. fieldsWithValues() returns the types that require predefined values.

Relationships

Values

To add values to an attribute:

Products

Attach an attribute to a product with a predefined value:
Or with a custom value:

Variants (AttributeValue)

AttributeValue can be linked to product variants:

Slug & Lookup

The HasSlug trait generates unique slugs automatically and provides a findBySlug() static method:

Query Scopes

Filter attributes by their visibility and behavior flags:
Scopes can be combined:

Status Management

Display Helpers

type_formatted returns a translated label like “Checkbox”. typesFields() returns all available types with their labels.

Working with AttributeProduct

The AttributeProduct model provides a computed real_value accessor:

Creating Attributes

Attribute with Predefined Values

Attribute with Free Text

Assigning Attributes to Products

Retrieving Attributes

Observer Behavior

The AttributeObserver handles cleanup when deleting:

Disabling Attribute Feature

Permissions

The admin panel generates five permissions for attribute management:

Components

Attribute components are part of the product configuration. To customize them:
Attribute-related components in config/shopper/components/product.php:

Storefront Example

Use Cases