Cart
Cart copied to clipboard
If the amount of money differs depending on the color of the same product, how do you implement it?
In the example, the price is the same even if the color of the same product differs. But how can I implement it if I want to set a price by color?
You add two products as in the following code:
`$cart->add('1', 1, [ 'price' => '5.99', 'color' => 'Green' ]);
$cart->add('2', 1, [ 'price' => '9.99', 'color' => 'Purple' ]);`
The two cart entries wont be mixed up.
However, I strongly recommend not saving the price here. The cart data could be modified by the user.
its better to work with IDs here and do the calculation on the PHP Site not in the session or cookie.