Skip to content

product optnios and variants

Anton Kaplia edited this page Jul 28, 2020 · 26 revisions

Domain Overview

Magento allows customizing a product before adding the product to the cart. Customization happens through the customizable options defined by the merchant. Options can represent customization, other products, digital goods so on.

All Magento product types represented through the options.

Definition

  • ProductOption - represents a product characteristic which allows editing before adding to cart. ProductOption has to have a label, information on how option values should be displayed, and is this option mandatory.
  • ProductOptionValues - belong to a particular option as to a group and represent selections which allowed by the option. Option value could by display label, also one or may values could be pre-selected.
  • ProductVariant - represent the final selection of one or multiple option values that will characterize the customized product in a shopping cart. Depends on the business scenario, a particular product variant could be linked with an existing product, with a price, or an inventory record, or no be linked to any. Even with no entities associated with the variant, it still has great value for a catalog because the presence of the variant says that such composition of options and their values described by the variant makes sense so that it can be purchased.

The application distinguishes two approaches to manage options:

Approach 1, "One to many": Multiple options selections lead a shopper to a selection of the single variation.

Example: configurable products

Approach 2, "One to one": The selection of multiple options leads to multiple product variants.

Examples: bundle product, customizable product, downloadable products. Both of approaches could be used together.

Example: configurable product with customizable option.

Options and Variants Data Objects

Even though variants can be associated with prices and inventories, options/variants do not responsible for managing these external data. As a result, we can design options/variants schema minimalistic.

syntax = "proto3";

message Product {
    repeated ProductOption options = 100;
}

message ProductOptionValue {
    string id = 1;
    string label = 2;
    string sortOrder = 3;
    string isDefault = 4;
}

message ProductOption {
    string id = 1;
    string label = 2;
    string sortOrder = 3;
    string isRequired = 4;
    string renderType = 6;
    repeated ProductOptionValue values = 5;
}

message ProductVariant {
    repeated string optionValueId = 1;
    string id = 2;
}

Explaining data and operations through the pseudo SQL

To explain data and operations, Lets review pseudo SQL schema, which describes the picture above.

Tables products, product_options, product_option_values, product_variant represents visionary catalog domain entities.

create table products (
    object_id char(36) not null,
    name varchar(128) not null,
    primary key (object_id)
);

create table product_options (
    option_id char(36) not null,
    object_id char(36) not null,
    label varchar(64),
    sort_order smallint,
    is_required tinyint not null default 0,
    render_type enum('checkbox', 'radiobutton', 'select', 'multiselect'),
    primary key (option_id)
);

alter table product_options
    add foreign key fk_product_options_object_id (object_id) references products(object_id);

create table product_option_values (
    value_id char(36) not null,
    option_id char(36) not null,
    label varchar(64) not null,
    sort_order smallint,
    is_default tinyint,
    primary key (value_id)
);

alter table product_option_values
    add foreign key fk_product_options_product_id (option_id) references product_options(option_id);

create table product_variant (
    value_id char(36) not null,
    object_id char(36) not null,
    values_in_variant tinyint not null,
    primary key (value_id, object_id)
);

alter table product_variant
    add foreign key fk_product_variant_value_id (value_id) references product_option_values(value_id);