diff --git a/mailpoet/assets/js/src/newsletter_editor/blocks/coupon/existingCoupons.tsx b/mailpoet/assets/js/src/newsletter_editor/blocks/coupon/existingCoupons.tsx index d4a731418a..203c6c6a03 100644 --- a/mailpoet/assets/js/src/newsletter_editor/blocks/coupon/existingCoupons.tsx +++ b/mailpoet/assets/js/src/newsletter_editor/blocks/coupon/existingCoupons.tsx @@ -13,7 +13,7 @@ import { uniqBy } from 'lodash'; import { MailPoet } from '../../../mailpoet'; import { GetValueCallback, SetValueCallback } from './types'; -const COUPONS_PER_PAGE = 20; +const COUPONS_PER_PAGE = 1000; export type Coupon = { id: number; @@ -84,7 +84,7 @@ class ExistingCoupons extends Component { page_number: this.state.pageNumber, discount_type: this.state.couponFilterDiscountType, search: this.state.couponSearch, - include_coupon_id: this.state.couponId, + include_coupon_ids: [this.state.couponId], }, }) .then((response) => { diff --git a/mailpoet/lib/API/JSON/v1/Coupons.php b/mailpoet/lib/API/JSON/v1/Coupons.php index 1d349bbda2..e667c14d6e 100644 --- a/mailpoet/lib/API/JSON/v1/Coupons.php +++ b/mailpoet/lib/API/JSON/v1/Coupons.php @@ -9,7 +9,7 @@ use MailPoet\WooCommerce\Helper; use MailPoet\WP\Functions as WPFunctions; class Coupons extends APIEndpoint { - public const DEFAULT_PAGE_SIZE = 10; + public const DEFAULT_PAGE_SIZE = 100; /** @var Helper */ public $helper; @@ -31,18 +31,17 @@ class Coupons extends APIEndpoint { public function getCoupons(array $data = []): SuccessResponse { $pageSize = $data['page_size'] ?? self::DEFAULT_PAGE_SIZE; - $pageNumber = $data['page_number'] ?? 0; + $pageNumber = $data['page_number'] ?? 1; $discountType = $data['discount_type'] ?? null; $search = $data['search'] ?? null; - $includeCouponId = $data['include_coupon_id'] ?? null; - + $includeCouponIds = $data['include_coupon_ids'] ?? []; return $this->successResponse( $this->formatCoupons($this->helper->getCouponList( (int)$pageSize, (int)$pageNumber, $discountType, $search, - (int)$includeCouponId + $includeCouponIds )) ); } diff --git a/mailpoet/lib/WooCommerce/Helper.php b/mailpoet/lib/WooCommerce/Helper.php index 21dc59fec1..b4c552a747 100644 --- a/mailpoet/lib/WooCommerce/Helper.php +++ b/mailpoet/lib/WooCommerce/Helper.php @@ -219,7 +219,7 @@ class Helper { int $pageNumber = 1, ?string $discountType = null, ?string $search = null, - ?int $includeCouponId = null + array $includeCouponIds = [] ): array { $args = [ 'posts_per_page' => $pageSize, @@ -241,9 +241,9 @@ class Helper { $includeCoupons = []; // We need to include the coupon with the given ID in the first page - if ($includeCouponId && $pageNumber === 1) { + if ($includeCouponIds && $pageNumber === 1) { $includeArgs = $args; - $includeArgs['include'] = [$includeCouponId]; + $includeArgs['include'] = $includeCouponIds; $includeCoupons = $this->wp->getPosts($includeArgs); }