File tree Expand file tree Collapse file tree 6 files changed +418
-6
lines changed Expand file tree Collapse file tree 6 files changed +418
-6
lines changed Original file line number Diff line number Diff line change 1+ import app from "../../snipcart.app.mjs" ;
2+
3+ export default {
4+ key : "snipcart-create-discount" ,
5+ name : "Create Discount" ,
6+ description : "Create a new Discount. [See the documentation](https://docs.snipcart.com/v3/api-reference/discounts#post-discounts)" ,
7+ version : "0.0.1" ,
8+ type : "action" ,
9+ props : {
10+ app,
11+ name : {
12+ propDefinition : [
13+ app ,
14+ "name" ,
15+ ] ,
16+ } ,
17+ maxNumberOfUsages : {
18+ propDefinition : [
19+ app ,
20+ "maxNumberOfUsages" ,
21+ ] ,
22+ } ,
23+ trigger : {
24+ propDefinition : [
25+ app ,
26+ "trigger" ,
27+ ] ,
28+ reloadProps : true ,
29+ } ,
30+ code : {
31+ propDefinition : [
32+ app ,
33+ "code" ,
34+ ] ,
35+ disabled : true ,
36+ hidden : true ,
37+ } ,
38+ totalToReach : {
39+ propDefinition : [
40+ app ,
41+ "totalToReach" ,
42+ ] ,
43+ disabled : true ,
44+ hidden : true ,
45+ } ,
46+ type : {
47+ propDefinition : [
48+ app ,
49+ "type" ,
50+ ] ,
51+ reloadProps : true ,
52+ } ,
53+ amount : {
54+ propDefinition : [
55+ app ,
56+ "amount" ,
57+ ] ,
58+ disabled : true ,
59+ hidden : true ,
60+ } ,
61+ rate : {
62+ propDefinition : [
63+ app ,
64+ "rate" ,
65+ ] ,
66+ disabled : true ,
67+ hidden : true ,
68+ } ,
69+ } ,
70+ async additionalProps ( ) {
71+ const props = { } ;
72+ if ( this . trigger === "Code" ) {
73+ props . code = {
74+ type : "string" ,
75+ label : "Code" ,
76+ description : "Code for the discount" ,
77+ } ;
78+ }
79+ if ( this . trigger === "Total" ) {
80+ props . totalToReach = {
81+ type : "string" ,
82+ label : "Total to Reach" ,
83+ description : "Minimum amount required to activate the discount" ,
84+ } ;
85+ }
86+ if ( this . type === "FixedAmount" ) {
87+ props . amount = {
88+ type : "string" ,
89+ label : "Amount" ,
90+ description : "Discount amount. Required when discount type is `FixedAmount`" ,
91+ } ;
92+ }
93+ if ( this . type === "Rate" ) {
94+ props . rate = {
95+ type : "string" ,
96+ label : "Rate" ,
97+ description : "Discount percentage, i.e.: `10`. Required when discount type is `Rate`" ,
98+ } ;
99+ }
100+ return props ;
101+ } ,
102+ async run ( { $ } ) {
103+ const response = await this . app . createDiscount ( {
104+ $,
105+ data : {
106+ name : this . name ,
107+ maxNumberOfUsages : this . maxNumberOfUsages ,
108+ trigger : this . trigger ,
109+ code : this . code ,
110+ totalToReach : this . totalToReach ,
111+ type : this . type ,
112+ amount : this . amount ,
113+ rate : this . rate ,
114+ discount : this . discount ,
115+ } ,
116+ } ) ;
117+
118+ $ . export ( "$summary" , `Successfully created Discount with ID '${ response . id } '` ) ;
119+
120+ return response ;
121+ } ,
122+ } ;
Original file line number Diff line number Diff line change 1+ import app from "../../snipcart.app.mjs" ;
2+
3+ export default {
4+ key : "snipcart-delete-discount" ,
5+ name : "Delete Discount" ,
6+ description : "Delete a Discount. [See the documentation](https://docs.snipcart.com/v3/api-reference/discounts#delete-discountsid)" ,
7+ version : "0.0.1" ,
8+ type : "action" ,
9+ props : {
10+ app,
11+ discountId : {
12+ propDefinition : [
13+ app ,
14+ "discountId" ,
15+ ] ,
16+ } ,
17+ } ,
18+ async run ( { $ } ) {
19+ const response = await this . app . deleteDiscount ( {
20+ $,
21+ id : this . discountId ,
22+ } ) ;
23+
24+ $ . export ( "$summary" , `Successfully deleted Discount with ID '${ this . discountId } '` ) ;
25+
26+ return response ;
27+ } ,
28+ } ;
Original file line number Diff line number Diff line change 1+ import app from "../../snipcart.app.mjs" ;
2+
3+ export default {
4+ key : "snipcart-update-discount" ,
5+ name : "Update Discount" ,
6+ description : "Update a Discount. [See the documentation](https://docs.snipcart.com/v3/api-reference/discounts#put-discountsid)" ,
7+ version : "0.0.1" ,
8+ type : "action" ,
9+ props : {
10+ app,
11+ discountId : {
12+ propDefinition : [
13+ app ,
14+ "discountId" ,
15+ ] ,
16+ } ,
17+ name : {
18+ propDefinition : [
19+ app ,
20+ "name" ,
21+ ] ,
22+ } ,
23+ maxNumberOfUsages : {
24+ propDefinition : [
25+ app ,
26+ "maxNumberOfUsages" ,
27+ ] ,
28+ } ,
29+ trigger : {
30+ propDefinition : [
31+ app ,
32+ "trigger" ,
33+ ] ,
34+ reloadProps : true ,
35+ } ,
36+ code : {
37+ propDefinition : [
38+ app ,
39+ "code" ,
40+ ] ,
41+ disabled : true ,
42+ hidden : true ,
43+ } ,
44+ totalToReach : {
45+ propDefinition : [
46+ app ,
47+ "totalToReach" ,
48+ ] ,
49+ disabled : true ,
50+ hidden : true ,
51+ } ,
52+ type : {
53+ propDefinition : [
54+ app ,
55+ "type" ,
56+ ] ,
57+ reloadProps : true ,
58+ } ,
59+ amount : {
60+ propDefinition : [
61+ app ,
62+ "amount" ,
63+ ] ,
64+ disabled : true ,
65+ hidden : true ,
66+ } ,
67+ rate : {
68+ propDefinition : [
69+ app ,
70+ "rate" ,
71+ ] ,
72+ disabled : true ,
73+ hidden : true ,
74+ } ,
75+ } ,
76+ async additionalProps ( ) {
77+ const props = { } ;
78+ if ( this . trigger === "Code" ) {
79+ props . code = {
80+ type : "string" ,
81+ label : "Code" ,
82+ description : "Code for the discount" ,
83+ } ;
84+ }
85+ if ( this . trigger === "Total" ) {
86+ props . totalToReach = {
87+ type : "string" ,
88+ label : "Total to Reach" ,
89+ description : "Minimum amount required to activate the discount" ,
90+ } ;
91+ }
92+ if ( this . type === "FixedAmount" ) {
93+ props . amount = {
94+ type : "string" ,
95+ label : "Amount" ,
96+ description : "Discount amount. Required when discount type is `FixedAmount`" ,
97+ } ;
98+ }
99+ if ( this . type === "Rate" ) {
100+ props . rate = {
101+ type : "string" ,
102+ label : "Rate" ,
103+ description : "Discount percentage, i.e.: `10`. Required when discount type is `Rate`" ,
104+ } ;
105+ }
106+ return props ;
107+ } ,
108+ async run ( { $ } ) {
109+ const response = await this . app . updateDiscount ( {
110+ $,
111+ id : this . discountId ,
112+ data : {
113+ name : this . name ,
114+ maxNumberOfUsages : this . maxNumberOfUsages ,
115+ trigger : this . trigger ,
116+ code : this . code ,
117+ totalToReach : this . totalToReach ,
118+ type : this . type ,
119+ amount : this . amount ,
120+ rate : this . rate ,
121+ discount : this . discount ,
122+ } ,
123+ } ) ;
124+
125+ $ . export ( "$summary" , `Successfully updated Discount with ID '${ response . id } '` ) ;
126+
127+ return response ;
128+ } ,
129+ } ;
Original file line number Diff line number Diff line change 1+ export default {
2+ TRIGGER_OPTIONS : [
3+ "Total" ,
4+ "Code" ,
5+ ] ,
6+ TYPE_OPTIONS : [
7+ "FixedAmount" ,
8+ "Rate" ,
9+ ] ,
10+ } ;
You can’t perform that action at this time.
0 commit comments