Change Coupon API parameter from include_coupon_id to include_coupon_id
[MAILPOET-5123]
This commit is contained in:
@@ -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<Props, State> {
|
||||
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) => {
|
||||
|
@@ -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
|
||||
))
|
||||
);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user