G
G
Gopa2020-05-22 12:38:17
Algorithms
Gopa, 2020-05-22 12:38:17

What algorithm to use for a product with parameters?

There is a product.
It has parameters, for example:
- Color (red, green blue)
- Material (cotton, silk)
- Size (xs, s, m, l)
There can be any number of these parameters, as well as the values ​​of the parameters themselves.
The combination of values ​​for the parameters (3 parameters in the example) gives some unique variation of the product with its id, price. Parameter values ​​can be combined in different ways. Those. there may not be an xs size for blue. The number of all possible product variations is not equal to the product of all the number of parameter values.

The data is stored as a multidimensional array, something like this:

$arr = array(
  0 => array(
    'variation_id' => 100,
    'price'        => 1000,
    'parameters'   => array(
      'color'    => 'red',
      'material' => 'cotton',
      'size'     => 'xs'
    )
  ),
  1 => array(
    'variation_id' => 101,
    'price'        => 1001,
    'parameters'   => array(
      'color'    => 'green',
      'material' => 'cotton',
      'size'     => 'xs'
    )
  ),
  2 => array(
    'variation_id' => 102,
    'price'        => 1002,
    'parameters'   => array(
      'color'    => 'red',
      'material' => 'cotton',
      'size'     => 's'
    )
  ),
  ...
);

For the user, a product card is displayed, where there are groups of checkboxes (parameters) with values.
The user selects, in any order, one of the values ​​of any of the parameters. Values ​​from other parameters become inactive if they do not participate in any of the variations with the selected value. Those. at the subsequent selection of the remaining parameter values, unsuitable values ​​are mutually excluded. I hope I explained clearly.
The question is how to implement this algorithm so that it would work quickly and well? A similar system is implemented in the product card on aliexpress.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2020-05-22
@Gopa

it's called EAV

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question