Skip to content

Commit d9b4756

Browse files
carterbuceCarter Buce
andauthored
return string instead of CouponInterface (#761)
Co-authored-by: Carter Buce <[email protected]>
1 parent 1b3d645 commit d9b4756

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

app/code/Meta/Sales/Api/NewsletterSubscriptionDiscountApiInterface.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
* See the License for the specific language governing permissions and
1818
* limitations under the License.
1919
*/
20-
namespace Meta\Sales\Api;
2120

22-
use Magento\SalesRule\Api\Data\CouponInterface;
21+
namespace Meta\Sales\Api;
2322

2423
interface NewsletterSubscriptionDiscountApiInterface
2524
{
@@ -28,10 +27,10 @@ interface NewsletterSubscriptionDiscountApiInterface
2827
*
2928
* If valid, returns an opt-in coupon.
3029
*
31-
* @param string $externalBusinessId
32-
* @param string $email
33-
* @param int $ruleId
34-
* @return \Magento\SalesRule\Api\Data\CouponInterface
30+
* @param string $externalBusinessId
31+
* @param string $email
32+
* @param int $ruleId
33+
* @return string
3534
*/
36-
public function subscribeForCoupon(string $externalBusinessId, string $email, int $ruleId): CouponInterface;
35+
public function subscribeForCoupon(string $externalBusinessId, string $email, int $ruleId): string;
3736
}

app/code/Meta/Sales/Model/Api/NewsletterSubscriptionDiscountApi.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
namespace Meta\Sales\Model\Api;
2222

2323
use Magento\Newsletter\Model\SubscriberFactory;
24-
use Magento\SalesRule\Api\Data\CouponInterface;
2524
use Magento\SalesRule\Model\RuleFactory;
2625
use Magento\SalesRule\Model\Coupon\MassgeneratorFactory;
2726
use Meta\BusinessExtension\Helper\FBEHelper;
@@ -106,10 +105,10 @@ public function __construct(
106105
* @param string $externalBusinessId The external business ID.
107106
* @param string $email The email address of the subscriber.
108107
* @param int $ruleId The ID of the sales rule.
109-
* @return CouponInterface The generated coupon.
108+
* @return string The generated coupon.
110109
* @throws LocalizedException If an error occurs during the process.
111110
*/
112-
public function subscribeForCoupon(string $externalBusinessId, string $email, int $ruleId): CouponInterface
111+
public function subscribeForCoupon(string $externalBusinessId, string $email, int $ruleId): string
113112
{
114113
$this->authenticator->authenticateRequest();
115114

@@ -128,14 +127,16 @@ public function subscribeForCoupon(string $externalBusinessId, string $email, in
128127
throw new LocalizedException(__('The specified discount rule does not exist.'));
129128
}
130129

130+
$coupon = $this->generateCoupon((int)$rule->getId());
131+
131132
// Subscribe the user to the newsletter
132133
$subscriber = $this->subscriberFactory->create();
133134
$subscriber->setStoreId($storeId);
134135
$subscriber->setSubscriberEmail($email);
135136
$subscriber->setSubscriberStatus(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED);
136137
$subscriber->save();
137138

138-
return $this->generateCoupon((int)$rule->getId());
139+
return $coupon;
139140
} catch (\Exception $e) {
140141
$this->fbeHelper->logExceptionImmediatelyToMeta(
141142
$e,
@@ -160,7 +161,7 @@ public function subscribeForCoupon(string $externalBusinessId, string $email, in
160161
* @param int $ruleId The sales rule ID.
161162
* @return string The generated coupon code.
162163
*/
163-
private function generateCoupon(int $ruleId): CouponInterface
164+
private function generateCoupon(int $ruleId): string
164165
{
165166
$rule = $this->ruleFactory->create()->load($ruleId);
166167
if (!$rule->getId()) {

0 commit comments

Comments
 (0)