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()
|
availableDiscountTypes: App.getConfig()
|
||||||
.get('coupon.discount_types')
|
.get('coupon.discount_types')
|
||||||
.toJSON(),
|
.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({
|
.on({
|
||||||
'select2:select': function (event) {
|
'select2:select': function (event) {
|
||||||
const coupon = event.params.data.text;
|
const couponId = event.params.data.id;
|
||||||
model.set('existingCoupon', coupon);
|
const couponCode = event.params.data.text;
|
||||||
model.set('code', coupon);
|
model.set('couponId', couponId);
|
||||||
|
model.set('code', couponCode);
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.trigger('change');
|
.trigger('change');
|
||||||
@@ -258,6 +261,7 @@ Module.CouponBlockSettingsView = base.BlockSettingsView.extend({
|
|||||||
);
|
);
|
||||||
// reset code placeholder
|
// reset code placeholder
|
||||||
this.model.set('code', App.getConfig().get('coupon.code_placeholder'));
|
this.model.set('code', App.getConfig().get('coupon.code_placeholder'));
|
||||||
|
this.model.set('couponId', null);
|
||||||
} else if (value === 'useExisting') {
|
} else if (value === 'useExisting') {
|
||||||
this.$('.mailpoet_field_coupon_source_create_new').addClass(
|
this.$('.mailpoet_field_coupon_source_create_new').addClass(
|
||||||
'mailpoet_hidden',
|
'mailpoet_hidden',
|
||||||
@@ -268,6 +272,12 @@ Module.CouponBlockSettingsView = base.BlockSettingsView.extend({
|
|||||||
// set selected code from available
|
// set selected code from available
|
||||||
this.model.set(
|
this.model.set(
|
||||||
'code',
|
'code',
|
||||||
|
this.$('.mailpoet_field_coupon_existing_coupon')
|
||||||
|
.find(':selected')
|
||||||
|
.html(),
|
||||||
|
);
|
||||||
|
this.model.set(
|
||||||
|
'couponId',
|
||||||
this.$('.mailpoet_field_coupon_existing_coupon')
|
this.$('.mailpoet_field_coupon_existing_coupon')
|
||||||
.find(':selected')
|
.find(':selected')
|
||||||
.val(),
|
.val(),
|
||||||
|
@@ -23,7 +23,7 @@ class Coupon {
|
|||||||
public function render($element, $columnBaseWidth) {
|
public function render($element, $columnBaseWidth) {
|
||||||
$couponCode = self::CODE_PLACEHOLDER;
|
$couponCode = self::CODE_PLACEHOLDER;
|
||||||
if (!empty($element['couponId'])) {
|
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);
|
$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']);
|
$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',
|
'post_status' => 'publish',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return array_map(function(\WP_Post $post): string {
|
return array_map(function(\WP_Post $post): array {
|
||||||
return $post->post_title; // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
return [
|
||||||
|
'id' => $post->ID,
|
||||||
|
'text' => $post->post_title, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||||
|
];
|
||||||
}, $couponPosts);
|
}, $couponPosts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,7 +50,7 @@
|
|||||||
<div class="mailpoet_form_field_select_option mailpoet_form_field_input_nowrap">
|
<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">
|
<select name="existing_coupon" class="mailpoet_select mailpoet_select_large mailpoet_field_coupon_existing_coupon">
|
||||||
{{#each availableCoupons}}
|
{{#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}}
|
{{/each}}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user