Use coupon id instead of text
[MAILPOET-4761]
This commit is contained in:
@ -177,7 +177,9 @@ Module.CouponBlockSettingsView = base.BlockSettingsView.extend({
|
||||
availableDiscountTypes: App.getConfig()
|
||||
.get('coupon.discount_types')
|
||||
.toJSON(),
|
||||
availableCoupons: App.getConfig().get('coupon.available_coupons'),
|
||||
availableCoupons: App.getConfig()
|
||||
.get('coupon.available_coupons')
|
||||
.toJSON(),
|
||||
},
|
||||
);
|
||||
},
|
||||
@ -238,9 +240,10 @@ Module.CouponBlockSettingsView = base.BlockSettingsView.extend({
|
||||
})
|
||||
.on({
|
||||
'select2:select': function (event) {
|
||||
const coupon = event.params.data.text;
|
||||
model.set('existingCoupon', coupon);
|
||||
model.set('code', coupon);
|
||||
const couponId = event.params.data.id;
|
||||
const couponCode = event.params.data.text;
|
||||
model.set('couponId', couponId);
|
||||
model.set('code', couponCode);
|
||||
},
|
||||
})
|
||||
.trigger('change');
|
||||
@ -258,6 +261,7 @@ Module.CouponBlockSettingsView = base.BlockSettingsView.extend({
|
||||
);
|
||||
// reset code placeholder
|
||||
this.model.set('code', App.getConfig().get('coupon.code_placeholder'));
|
||||
this.model.set('couponId', null);
|
||||
} else if (value === 'useExisting') {
|
||||
this.$('.mailpoet_field_coupon_source_create_new').addClass(
|
||||
'mailpoet_hidden',
|
||||
@ -268,6 +272,12 @@ Module.CouponBlockSettingsView = base.BlockSettingsView.extend({
|
||||
// set selected code from available
|
||||
this.model.set(
|
||||
'code',
|
||||
this.$('.mailpoet_field_coupon_existing_coupon')
|
||||
.find(':selected')
|
||||
.html(),
|
||||
);
|
||||
this.model.set(
|
||||
'couponId',
|
||||
this.$('.mailpoet_field_coupon_existing_coupon')
|
||||
.find(':selected')
|
||||
.val(),
|
||||
|
@ -23,7 +23,7 @@ class Coupon {
|
||||
public function render($element, $columnBaseWidth) {
|
||||
$couponCode = self::CODE_PLACEHOLDER;
|
||||
if (!empty($element['couponId'])) {
|
||||
$couponCode = $this->helper->wcGetCouponCodeById($element['couponId']);
|
||||
$couponCode = $this->helper->wcGetCouponCodeById((int)$element['couponId']);
|
||||
}
|
||||
$element['styles']['block']['width'] = $this->calculateWidth($element, $columnBaseWidth);
|
||||
$styles = 'display:inline-block;-webkit-text-size-adjust:none;mso-hide:all;text-decoration:none;text-align:center;' . StylesHelper::getBlockStyles($element, $exclude = ['textAlign']);
|
||||
|
@ -188,8 +188,11 @@ class Helper {
|
||||
'post_status' => 'publish',
|
||||
]);
|
||||
|
||||
return array_map(function(\WP_Post $post): string {
|
||||
return $post->post_title; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
return array_map(function(\WP_Post $post): array {
|
||||
return [
|
||||
'id' => $post->ID,
|
||||
'text' => $post->post_title, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
];
|
||||
}, $couponPosts);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@
|
||||
<div class="mailpoet_form_field_select_option mailpoet_form_field_input_nowrap">
|
||||
<select name="existing_coupon" class="mailpoet_select mailpoet_select_large mailpoet_field_coupon_existing_coupon">
|
||||
{{#each availableCoupons}}
|
||||
<option value="{{ this }}" {{#ifCond ../model.existingCoupon '==' this}}selected="selected"{{/ifCond}}>{{ this }}</option>
|
||||
<option value="{{ id }}" {{#ifCond ../model.couponId '==' id}}selected="selected"{{/ifCond}}>{{ text }}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user