| 1 |
<?php |
| 2 |
/** |
| 3 |
* Coupon catalog proxy behavior. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\API\V2\Proxy |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\API\V2\Proxy; |
| 9 |
|
| 10 |
/** |
| 11 |
* Relaxes WooCommerce coupon read permission only during the forward. |
| 12 |
*/ |
| 13 |
final class Coupons_Proxy_Behavior extends Scoped_Proxy_Behavior { |
| 14 |
/** POS read grant for this collection only. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $permission_collection = 'coupons'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Install this resource's hooks and return their removal tuples. |
| 22 |
* |
| 23 |
* @return array<int, array{0: string, 1: callable, 2: int}> |
| 24 |
*/ |
| 25 |
protected function install(): array { |
| 26 |
|
| 27 |
// Coupon date/modified sorts tie routinely (imports share timestamps); |
| 28 |
// pin the id tiebreak so multi-page walks stay stable (see Stable_Sort). |
| 29 |
$stable_sort = static function ( $args ) { |
| 30 |
return Stable_Sort::with_post_id_tiebreak( (array) $args ); |
| 31 |
}; |
| 32 |
add_filter( 'woocommerce_rest_shop_coupon_object_query', $stable_sort ); |
| 33 |
|
| 34 |
return array( |
| 35 |
array( 'woocommerce_rest_shop_coupon_object_query', $stable_sort, 10 ), |
| 36 |
); |
| 37 |
} |
| 38 |
} |
| 39 |
|