Logic to add or edit items based on multiple fields; shopping cart logic; conditional add/edit

Hi,

I´m trying to wrap my head around the logic of a shopping cart for products that can be configured.

I have the following tables (images are below):

  • products ( configuration based on size and color possible)

  • configurations_group

  • configurations_values

  • carts

  • cart items

  • selected_configuration

Example:

  • A customer can add 1 jacket in size L and the color RED to the cart ( new cart item gets created).

  • When the customer now adds another jacket in size L and color RED to the cart it should only update the quantity (edit record; new quantity 2).

  • When the same customer now adds a jacket in size L and color BLUE to the cart it should create a new cart item

--> so if any part of the configuration of a product is different from the other cart items I want to add a new cart item else I only want to edit it so we don´t have two cart items. with the same configuration.

** Mind that the configuration_groups and the configuration_values are dynamic. A merchant could have 10 different configuration_groups with 5 different configuration_values each for eg.

How can I achieve this? If Add/edit doesn´t seem to work here because I can only use one value. Using conditionals would get quite messy (at least when doing it the way I tried to do it lol).

Does anyone have a good approach on this? Would be very greatful 🙂

images:

4 replies