Skip to content

Commit

Permalink
Tweak 'Coupon Code' field (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Jul 3, 2023
1 parent 9219939 commit 6b81f1f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
24 changes: 24 additions & 0 deletions resources/js/components/Fieldtypes/CouponCodeFieldtype.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<template>
<text-fieldtype
:meta="meta"
:config="{
classes: 'uppercase font-mono',
focus: 'code',
autoselect: true,
input_type: 'text',
}"
:value="value"
@input="updateDebounced"
@keydown.native.space.prevent
/>
</template>

<script>
export default {
name: 'CouponCodeFieldtype',
mixins: [Fieldtype],
props: ['meta'],
}
</script>
2 changes: 2 additions & 0 deletions resources/js/cp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Fieldtypes

import CouponCodeFieldtype from './components/Fieldtypes/CouponCodeFieldtype.vue'
import CouponValueFieldtype from './components/Fieldtypes/CouponValueFieldtype.vue'
import GatewayFieldtype from './components/Fieldtypes/GatewayFieldtype.vue'
import MoneyFieldtype from './components/Fieldtypes/MoneyFieldtype.vue'
Expand All @@ -10,6 +11,7 @@ import PaymentStatusIndexFieldtype from './components/Fieldtypes/PaymentStatusIn
import ProductVariantFieldtype from './components/Fieldtypes/ProductVariantFieldtype.vue'
import ProductVariantsFildtype from './components/Fieldtypes/ProductVariantsFieldtype.vue'

Statamic.$components.register('coupon-code-fieldtype', CouponCodeFieldtype)
Statamic.$components.register('coupon-value-fieldtype', CouponValueFieldtype)
Statamic.$components.register('gateway-fieldtype', GatewayFieldtype)
Statamic.$components.register('money-fieldtype', MoneyFieldtype)
Expand Down
5 changes: 2 additions & 3 deletions src/Coupons/CouponBlueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ public static function getBlueprint(): FieldsBlueprint
'display' => 'Main',
'fields' => [
'code' => [
'type' => 'text',
'localizable' => true,
'generate' => true,
'type' => 'coupon_code',
'display' => __('Coupon Code'),
'validate' => [
'required',
],
'listable' => true,
'instructions' => __('Customers will use this code to redeem the coupon.'),
],
'description' => [
'type' => 'textarea',
Expand Down
18 changes: 18 additions & 0 deletions src/Fieldtypes/CouponCodeFieldtype.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace DoubleThreeDigital\SimpleCommerce\Fieldtypes;

use Illuminate\Support\Str;
use Statamic\Fieldtypes\Text;

class CouponCodeFieldtype extends Text
{
protected $selectable = false;

protected $component = 'coupon-code';

public function process($data)
{
return Str::of($data)->upper()->__toString();
}
}
3 changes: 2 additions & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class ServiceProvider extends AddonServiceProvider
];

protected $fieldtypes = [
Fieldtypes\CouponValueFieldtype::class,
Fieldtypes\CountryFieldtype::class,
Fieldtypes\CouponCodeFieldtype::class,
Fieldtypes\CouponFieldtype::class,
Fieldtypes\CouponValueFieldtype::class,
Fieldtypes\GatewayFieldtype::class,
Fieldtypes\MoneyFieldtype::class,
Fieldtypes\OrderStatusFieldtype::class,
Expand Down

0 comments on commit 6b81f1f

Please sign in to comment.