chore(pay): close residual zibll edge contracts for content pay

Expand coupon scope to content categories, document points_deduction as runtime-off like zibll, reject card_pass on content cashier, and pass shop/content context into coupon validate.
This commit is contained in:
kate522 committed 2026-07-14 22:12:12 +08:00
1 parent dc28fafcc3
commit 2ead893923
6 files changed
+90 -24

No files matched your search

+23 -11
View File
@@ -161,30 +161,42 @@ class AKSRT_Coupon {
}
}
// Product scope check
// Product / content scope check.
// Supports shop product cats and content post cats.
if (!empty($coupon['product_scope']) && !empty($args['product_ids'])) {
$scope = is_array($coupon['product_scope']) ? $coupon['product_scope'] : json_decode($coupon['product_scope'], true);
if (is_array($scope) && !empty($scope)) {
$scope_type = (string) ($scope['type'] ?? '');
$scope_ids = array_map('intval', (array) ($scope['ids'] ?? []));
$scope_type = sanitize_key((string) ($scope['type'] ?? ''));
$scope_ids = array_map('intval', (array) ($scope['ids'] ?? []));
$product_ids = array_map('intval', (array) $args['product_ids']);
$taxonomies = array_values(array_filter(array_map('sanitize_key', (array) ($scope['taxonomies'] ?? []))));
if ($taxonomies === []) {
// content context prefers category; shop admin may pass aksrt_product_cat.
$context = sanitize_key((string) ($args['context'] ?? ''));
$taxonomies = ($context === 'content')
? ['category']
: ['aksrt_product_cat', 'category'];
}
if ($scope_type === 'include' && empty(array_intersect($product_ids, $scope_ids))) {
return ['valid' => false, 'message' => '该优惠码不适用于当前商品'];
return ['valid' => false, 'message' => __('该优惠码不适用于当前商品', 'aksrt')];
}
if ($scope_type === 'exclude' && !empty(array_intersect($product_ids, $scope_ids))) {
return ['valid' => false, 'message' => '该优惠码不适用于当前商品'];
return ['valid' => false, 'message' => __('该优惠码不适用于当前商品', 'aksrt')];
}
if ($scope_type === 'category') {
if (in_array($scope_type, ['category', 'content_category', 'post_category'], true)) {
$matched = false;
foreach ($product_ids as $pid) {
$cats = wp_get_post_terms($pid, 'aksrt_product_cat', ['fields' => 'ids']);
if (!is_wp_error($cats) && !empty(array_intersect($cats, $scope_ids))) {
$matched = true;
break;
foreach ($taxonomies as $tax) {
$cats = wp_get_post_terms($pid, $tax, ['fields' => 'ids']);
if (!is_wp_error($cats) && !empty(array_intersect(array_map('intval', (array) $cats), $scope_ids))) {
$matched = true;
break 2;
}
}
}
if (!$matched) {
return ['valid' => false, 'message' => '该优惠码不适用于当前商品分类'];
return ['valid' => false, 'message' => __('该优惠码不适用于当前分类', 'aksrt')];
}
}
}