What happened to commerce_discounts->saveDiscounts or How to relate vouchers to product types in Commerce 2? We sell vouchers to our shop users. To prevent them for being used on vouchers themself, i could relate them to specific productTypes or even products in Commerce 1.

craft()-&gt;commerce_discounts-&gt;saveDiscount($discount, $groups, $productTypes, $products)


In Commerce 2 the 3rd and 4th parametes are gone. How can i relate vouchers to product types programmaticely?
You now need to set the groups, product types, and purchasables on the discount model directly, then just pass the discount model to the saveDiscount method:

Plugin::getInstance()-&gt;getDiscounts()-&gt;saveDiscount($discount)

An example of setting these things on the discount before saving can be found in the discount controller:

https://github.com/craftcms/commerce/blob/develop/src/controllers/DiscountsController.php#L128-L166