src/controllers/CartController.php
public function actionAddDiscountCoupon()
    {
        $rr = new RequestResponse();

        if ($rr->isRequestAjaxPost()) {
            $couponCode = \Yii::$app->request->post('coupon_code');

            try {
                if (!$couponCode) {
                    throw new Exception(\Yii::t('skeeks/shop/app', 'Not set coupon code'));
                }

                $applyShopDiscountCoupon = ShopDiscountCoupon::find()
                    ->where(['coupon' => $couponCode])
                    ->andWhere(['is_active' => 1])
                    ->andWhere(['>','active_to', time()])
                    ->one();


                if (!$applyShopDiscountCoupon) {
                    throw new Exception(\Yii::t('skeeks/shop/app', 'Coupon does not exist or is not active'));
                }

                /*$discount_coupons = [];
                if (\Yii::$app->shop->cart->shopOrder->shopDiscountCoupons) {
                    $discount_coupons = ArrayHelper::map(\Yii::$app->shop->cart->shopOrder->shopDiscountCoupons, 'id', 'id');
                }
                $discount_coupons[] = $applyShopDiscountCoupon->id;
                array_unique($discount_coupons);*/

                $map = new ShopOrder2discountCoupon();
                $map->order_id = \Yii::$app->shop->cart->shopOrder->id;
                $map->discount_coupon_id = $applyShopDiscountCoupon->id;

                $map->save();
                //\Yii::$app->shop->cart->shopOrder->shopDiscountCoupons = $discount_coupons;
                //\Yii::$app->shop->cart->shopOrder->save();
                \Yii::$app->shop->cart->shopOrder->recalculate()->save();

                $rr->data = \Yii::$app->shop->cart->shopOrder->jsonSerialize();
                $rr->success = true;
                $rr->message = \Yii::t('skeeks/shop/app', 'Coupon successfully installed');

            } catch (\Exception $e) {
                $rr->message = $e->getMessage();
                return (array)$rr;
            }

            return (array)$rr;
        } else {
            return $this->goBack();
        }
    }
public function actionAddDiscountCoupon()
    {
        $rr = new RequestResponse();

        if ($rr->isRequestAjaxPost()) {
            $couponCode = \Yii::$app->request->post('coupon_code');

            try {
                if (!$couponCode) {
                    throw new Exception(\Yii::t('skeeks/shop/app', 'Not set coupon code'));
                }

                $applyShopDiscountCoupon = ShopDiscountCoupon::find()
                    ->where(['coupon' => $couponCode])
                    ->andWhere(['is_active' => 1])
                    ->andWhere(['>','active_to', time()])
                    ->one();


                if (!$applyShopDiscountCoupon) {
                    throw new Exception(\Yii::t('skeeks/shop/app', 'Coupon does not exist or is not active'));
                }

                /*$discount_coupons = [];
                if (\Yii::$app->shop->cart->shopOrder->shopDiscountCoupons) {
                    $discount_coupons = ArrayHelper::map(\Yii::$app->shop->cart->shopOrder->shopDiscountCoupons, 'id', 'id');
                }
                $discount_coupons[] = $applyShopDiscountCoupon->id;
                array_unique($discount_coupons);*/

                $map = new ShopOrder2discountCoupon();
                $map->order_id = \Yii::$app->shop->cart->shopOrder->id;
                $map->discount_coupon_id = $applyShopDiscountCoupon->id;

                $map->save();
                //\Yii::$app->shop->cart->shopOrder->shopDiscountCoupons = $discount_coupons;
                //\Yii::$app->shop->cart->shopOrder->save();
                \Yii::$app->shop->cart->shopOrder->recalculate()->save();

                $rr->data = \Yii::$app->shop->cart->shopOrder->jsonSerialize();
                $rr->success = true;
                $rr->message = \Yii::t('skeeks/shop/app', 'Coupon successfully installed');

            } catch (\Exception $e) {
                $rr->message = $e->getMessage();
                return (array)$rr;
            }

            return (array)$rr;
        } else {
            return $this->goBack();
        }
    }
Adding a product to the cart.

@return array|\yii\web\Response