${function(){
const {discount_type, discount_value, prerequisite_value, prerequisite_type, obtain_product, max_free_shipping} = data.campaign?.reward.discount_code_activity || {};
let value = '';
let unit = '';
if (discount_type === 'fixed_amount') {
value = ``;
}
if (discount_type === 'percentage') {
value = `${parseInt(discount_value)}%`;
unit = `OFF`;
}
if (discount_type === 'free_shipping') {
if (max_free_shipping !== -1) {
value = `
FREE
SHIPPING
`;
} else {
value = `FREE`;
unit = `SHIPPING`;
}
}
if (discount_type === 'buy_x_get_y') {
const x = prerequisite_value;
const y = obtain_product.product_count;
const obtain_value = obtain_product.obtain_value;
if(obtain_product.obtain_type === 'free') {
value = `FREE`;
unit = `PRODUCT`;
}
if(obtain_product.obtain_type === 'percentage') {
value = `${obtain_value}%`;
unit = `OFF`;
}
if(obtain_product.obtain_type === 'fixed_amount') {
value = ``;
}
}
return `
${value}
${unit}
`;
}()}
${function(){
const {discount_type, prerequisite_value, prerequisite_type, obtain_product} = data.campaign?.reward.discount_code_activity || {};
if (discount_type !== 'buy_x_get_y') {
return `${data.campaign?.name}`;
}
return '';
}()}
${function(){
const {discount_type, prerequisite_value, prerequisite_type, obtain_product} = data.campaign?.reward.discount_code_activity || {};
if (discount_type === 'buy_x_get_y') {
const x = prerequisite_value;
const y = obtain_product.product_count;
const obtain_value = obtain_product.obtain_value;
if(obtain_product.obtain_type === 'free') {
if (prerequisite_type === 'quantity') {
return `Buy ${x} Get ${y} Free`;
} else if (prerequisite_type === 'subtotal') {
return `Buy Get ${y} Free`;
}
}
if(obtain_product.obtain_type === 'percentage') {
if (prerequisite_type === 'quantity') {
return `Buy ${x}, get ${y} at ${obtain_value}% OFF`;
} else if (prerequisite_type === 'subtotal') {
return `Buy , get ${y} at ${obtain_value}% OFF`;
}
}
if(obtain_product.obtain_type === 'fixed_amount') {
if (prerequisite_type === 'quantity') {
return `Buy ${x} get ${y} with off each`;
} else if (prerequisite_type === 'subtotal') {
return `Buy get ${y} with off each`;
}
}
}
return '';
}()}
${data.discount_code}
${function(){
const { prerequisite_type, prerequisite_value, discount_type, obtain_product, max_free_shipping } = data.campaign?.reward.discount_code_activity || {};
if (prerequisite_type === 'none' && discount_type === 'free_shipping' && max_free_shipping !== -1) {
return `Up to , no threshold`;
}
if (prerequisite_type === 'quantity' && discount_type === 'free_shipping' && max_free_shipping !== -1) {
return `Up to , the order is available when it contains at least ${parseInt(prerequisite_value)} items`;
}
if (prerequisite_type === 'subtotal' && discount_type === 'free_shipping' && max_free_shipping !== -1) {
return `Up to , available when the order amount exceeds `;
}
if (prerequisite_type === 'none') {
return `No threshold`;
}
if (prerequisite_type === 'quantity') {
return `The order is available when it contains at least ${parseInt(prerequisite_value)} items`;
}
if (prerequisite_type === 'subtotal') {
return `Available when the order amount exceeds `;
}
if (discount_type === 'free_shipping' && max_free_shipping !== -1 ) {
return `Up to `
}
}()}