21
21
namespace Meta \Sales \Model \Api ;
22
22
23
23
use Magento \Newsletter \Model \SubscriberFactory ;
24
- use Magento \SalesRule \Api \Data \CouponInterface ;
25
24
use Magento \SalesRule \Model \RuleFactory ;
26
25
use Magento \SalesRule \Model \Coupon \MassgeneratorFactory ;
27
26
use Meta \BusinessExtension \Helper \FBEHelper ;
@@ -106,10 +105,10 @@ public function __construct(
106
105
* @param string $externalBusinessId The external business ID.
107
106
* @param string $email The email address of the subscriber.
108
107
* @param int $ruleId The ID of the sales rule.
109
- * @return CouponInterface The generated coupon.
108
+ * @return string The generated coupon.
110
109
* @throws LocalizedException If an error occurs during the process.
111
110
*/
112
- public function subscribeForCoupon (string $ externalBusinessId , string $ email , int $ ruleId ): CouponInterface
111
+ public function subscribeForCoupon (string $ externalBusinessId , string $ email , int $ ruleId ): string
113
112
{
114
113
$ this ->authenticator ->authenticateRequest ();
115
114
@@ -128,14 +127,16 @@ public function subscribeForCoupon(string $externalBusinessId, string $email, in
128
127
throw new LocalizedException (__ ('The specified discount rule does not exist. ' ));
129
128
}
130
129
130
+ $ coupon = $ this ->generateCoupon ((int )$ rule ->getId ());
131
+
131
132
// Subscribe the user to the newsletter
132
133
$ subscriber = $ this ->subscriberFactory ->create ();
133
134
$ subscriber ->setStoreId ($ storeId );
134
135
$ subscriber ->setSubscriberEmail ($ email );
135
136
$ subscriber ->setSubscriberStatus (\Magento \Newsletter \Model \Subscriber::STATUS_SUBSCRIBED );
136
137
$ subscriber ->save ();
137
138
138
- return $ this -> generateCoupon (( int ) $ rule -> getId ()) ;
139
+ return $ coupon ;
139
140
} catch (\Exception $ e ) {
140
141
$ this ->fbeHelper ->logExceptionImmediatelyToMeta (
141
142
$ e ,
@@ -160,7 +161,7 @@ public function subscribeForCoupon(string $externalBusinessId, string $email, in
160
161
* @param int $ruleId The sales rule ID.
161
162
* @return string The generated coupon code.
162
163
*/
163
- private function generateCoupon (int $ ruleId ): CouponInterface
164
+ private function generateCoupon (int $ ruleId ): string
164
165
{
165
166
$ rule = $ this ->ruleFactory ->create ()->load ($ ruleId );
166
167
if (!$ rule ->getId ()) {
0 commit comments