<?php declare(strict_types = 1); namespace MailPoet\API\JSON\v1; if (!defined('ABSPATH')) exit; use MailPoet\API\JSON\Endpoint as APIEndpoint; use MailPoet\API\JSON\SuccessResponse; use MailPoet\Config\AccessControl; use MailPoet\WooCommerce\Helper; use MailPoet\WP\Functions as WPFunctions; class Coupons extends APIEndpoint { public const DEFAULT_PAGE_SIZE = 100; /** @var Helper */ public $helper; /*** @var WPFunctions */ private $wp; public $permissions = [ 'global' => AccessControl::PERMISSION_MANAGE_EMAILS, ]; public function __construct( WPFunctions $wp, Helper $helper ) { $this->wp = $wp; $this->helper = $helper; } public function getCoupons(array $data = []): SuccessResponse { $pageSize = $data['page_size'] ?? self::DEFAULT_PAGE_SIZE; $pageNumber = $data['page_number'] ?? 1; $discountType = $data['discount_type'] ?? null; $search = $data['search'] ?? null; $includeCouponIds = $data['include_coupon_ids'] ?? []; return $this->successResponse( $this->formatCoupons($this->helper->getCouponList( (int)$pageSize, (int)$pageNumber, $discountType, $search, $includeCouponIds )) ); } /** * @param array $couponPosts * @return array */ private function formatCoupons(array $couponPosts): array { return array_map(function (\WP_Post $post): array { $discountType = $this->wp->getPostMeta($post->ID, 'discount_type', true); return [ 'id' => $post->ID, 'text' => $post->post_title, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps 'excerpt' => $post->post_excerpt, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps 'discountType' => $discountType, ]; }, $couponPosts); } }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Analytics.php | File | 668 B | 0644 |
|
AutomatedLatestContent.php | File | 3.98 KB | 0644 |
|
AutomaticEmails.php | File | 2.83 KB | 0644 |
|
Captcha.php | File | 951 B | 0644 |
|
Coupons.php | File | 1.8 KB | 0644 |
|
CustomFields.php | File | 2.98 KB | 0644 |
|
DynamicSegments.php | File | 11.93 KB | 0644 |
|
FeatureFlags.php | File | 1.42 KB | 0644 |
|
Forms.php | File | 11.3 KB | 0644 |
|
Help.php | File | 2.8 KB | 0644 |
|
ImportExport.php | File | 5.76 KB | 0644 |
|
Mailer.php | File | 3.1 KB | 0644 |
|
NewsletterLinks.php | File | 1.01 KB | 0644 |
|
NewsletterTemplates.php | File | 4.29 KB | 0644 |
|
Newsletters.php | File | 16.01 KB | 0644 |
|
Premium.php | File | 3.03 KB | 0644 |
|
RedirectResponse.php | File | 347 B | 0644 |
|
Segments.php | File | 12.19 KB | 0644 |
|
SendingQueue.php | File | 9.93 KB | 0644 |
|
SendingTaskSubscribers.php | File | 5.42 KB | 0644 |
|
Services.php | File | 12.35 KB | 0644 |
|
Settings.php | File | 16.49 KB | 0644 |
|
Setup.php | File | 1.19 KB | 0644 |
|
SubscriberStats.php | File | 4.08 KB | 0644 |
|
Subscribers.php | File | 12.31 KB | 0644 |
|
Tags.php | File | 1.34 KB | 0644 |
|
UserFlags.php | File | 1.01 KB | 0644 |
|
WoocommerceSettings.php | File | 870 B | 0644 |
|
index.php | File | 6 B | 0644 |
|