Merx

Product Variants

If you want to sell shoes you probably want to sell the shoes in a specific size. This cookbook shows you how to sell variations of your products.

Add to cart

Simply add the desired variations to the customer’s cart. That’s it.

$cart->add([
  'id' => 'nice-shoes',
  'color' => 'red',
  'size' => 38,
]);

You can even set a custom price within the add method:

$cart->add([
  'id' => 'nice-shoes',
  'color' => 'gold',
  'size' => 41.5,
  'price' => 249.99,
]);

Tax is calculated automatically based on the tax value defined in the product page.

Combination with stock management

If you want to combine product variations with stock management things are getting more complicated. We recommend to think of product variations as own products.

content/nice-shoes/variant-red-41/product.txt

Title: Nice shoes
----
Price: 99.99
----
Tax: 19
----
Color: red
----
Size: 41
----
Stock: 10

content/nice-shoes/variant-red-40/product.txt

Title: Nice shoes
----
Price: 99.99
----
Tax: 19
----
Color: red
----
Size: 40
----
Stock: 8

content/nice-shoes/variant-gold-40/product.txt

Title: Nice shoes
----
Price: 249.99
----
Tax: 19
----
Color: gold
----
Size: 41
----
Stock: 1

Add variant to cart

$cart->add([
  'id' => 'nice-shoes/variant-gold-40',
]);