Create Cart Price Rule and generate Coupon Codes programmatically

Magento offers a marketing feature called Cart Price Rules, which allows for the application of discounts to items in the shopping cart based on a set of conditions. The discount can be applied automatically as soon as the conditions are met, or when the customer enters a valid coupon code. Coupon codes can be generated for each cart price rule via the admin panel in Marketing -> Cart Price Rulessection. However, sometimes we need to automate this process. Let’s find out how to create a cart price rule and generate coupon codes programmatically in Magento 2.

How to add the details for cart item in Magento 2

In this blog post, I would like to share a pretty interesting and not obvious solution on how to join some additional details to cart item block on checkout cart page.

Let’s say we need to add the “Brand” custom product attribute and show its value within a specific block on the product view page and checkout cart page. It’s very simple in the scope of the product page, but how to deal with number cart items on checkout cart page. There are a couple of issues which you may face with. We will cover them further.