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 { MailPoet } from '../../../mailpoet';
|
||||||
import { GetValueCallback, SetValueCallback } from './types';
|
import { GetValueCallback, SetValueCallback } from './types';
|
||||||
|
|
||||||
const COUPONS_PER_PAGE = 20;
|
const COUPONS_PER_PAGE = 1000;
|
||||||
|
|
||||||
export type Coupon = {
|
export type Coupon = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -84,7 +84,7 @@ class ExistingCoupons extends Component<Props, State> {
|
|||||||
page_number: this.state.pageNumber,
|
page_number: this.state.pageNumber,
|
||||||
discount_type: this.state.couponFilterDiscountType,
|
discount_type: this.state.couponFilterDiscountType,
|
||||||
search: this.state.couponSearch,
|
search: this.state.couponSearch,
|
||||||
include_coupon_id: this.state.couponId,
|
include_coupon_ids: [this.state.couponId],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@@ -9,7 +9,7 @@ use MailPoet\WooCommerce\Helper;
|
|||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class Coupons extends APIEndpoint {
|
class Coupons extends APIEndpoint {
|
||||||
public const DEFAULT_PAGE_SIZE = 10;
|
public const DEFAULT_PAGE_SIZE = 100;
|
||||||
|
|
||||||
/** @var Helper */
|
/** @var Helper */
|
||||||
public $helper;
|
public $helper;
|
||||||
@@ -31,18 +31,17 @@ class Coupons extends APIEndpoint {
|
|||||||
|
|
||||||
public function getCoupons(array $data = []): SuccessResponse {
|
public function getCoupons(array $data = []): SuccessResponse {
|
||||||
$pageSize = $data['page_size'] ?? self::DEFAULT_PAGE_SIZE;
|
$pageSize = $data['page_size'] ?? self::DEFAULT_PAGE_SIZE;
|
||||||
$pageNumber = $data['page_number'] ?? 0;
|
$pageNumber = $data['page_number'] ?? 1;
|
||||||
$discountType = $data['discount_type'] ?? null;
|
$discountType = $data['discount_type'] ?? null;
|
||||||
$search = $data['search'] ?? null;
|
$search = $data['search'] ?? null;
|
||||||
$includeCouponId = $data['include_coupon_id'] ?? null;
|
$includeCouponIds = $data['include_coupon_ids'] ?? [];
|
||||||
|
|
||||||
return $this->successResponse(
|
return $this->successResponse(
|
||||||
$this->formatCoupons($this->helper->getCouponList(
|
$this->formatCoupons($this->helper->getCouponList(
|
||||||
(int)$pageSize,
|
(int)$pageSize,
|
||||||
(int)$pageNumber,
|
(int)$pageNumber,
|
||||||
$discountType,
|
$discountType,
|
||||||
$search,
|
$search,
|
||||||
(int)$includeCouponId
|
$includeCouponIds
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -219,7 +219,7 @@ class Helper {
|
|||||||
int $pageNumber = 1,
|
int $pageNumber = 1,
|
||||||
?string $discountType = null,
|
?string $discountType = null,
|
||||||
?string $search = null,
|
?string $search = null,
|
||||||
?int $includeCouponId = null
|
array $includeCouponIds = []
|
||||||
): array {
|
): array {
|
||||||
$args = [
|
$args = [
|
||||||
'posts_per_page' => $pageSize,
|
'posts_per_page' => $pageSize,
|
||||||
@@ -241,9 +241,9 @@ class Helper {
|
|||||||
|
|
||||||
$includeCoupons = [];
|
$includeCoupons = [];
|
||||||
// We need to include the coupon with the given ID in the first page
|
// 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 = $args;
|
||||||
$includeArgs['include'] = [$includeCouponId];
|
$includeArgs['include'] = $includeCouponIds;
|
||||||
$includeCoupons = $this->wp->getPosts($includeArgs);
|
$includeCoupons = $this->wp->getPosts($includeArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user