Skip to content

Commit c6004b9

Browse files
authored
Merge pull request #102 from Bit-Apps-Pro/feat/wc-new-triggers
refactor wooCommerce trigger with some bug fixes
2 parents 13975ad + 99bb3d2 commit c6004b9

File tree

7 files changed

+1117
-771
lines changed

7 files changed

+1117
-771
lines changed

frontend-dev/src/components/AllIntegrations/OmniSend/OmniSendFieldMap.jsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import { useRecoilValue } from 'recoil'
2-
import { useEffect } from 'react'
2+
import { $btcbi } from '../../../GlobalStates'
33
import { __ } from '../../../Utils/i18nwrap'
4-
import MtInput from '../../Utilities/MtInput'
5-
import { addFieldMap, delFieldMap, handleCustomValue, handleFieldMapping } from './IntegrationHelpers'
64
import { SmartTagField } from '../../../Utils/StaticData/SmartTagField'
7-
import { $btcbi } from '../../../GlobalStates'
8-
import { generateMappedField } from './OmniSendCommonFunc'
95
import TagifyInput from '../../Utilities/TagifyInput'
6+
import { addFieldMap, delFieldMap, handleCustomValue, handleFieldMapping } from './IntegrationHelpers'
107

118
export default function OmniSendFieldMap({ i, formFields, field, omniSendConf, setOmniSendConf, type }) {
129
const btcbi = useRecoilValue($btcbi)

frontend-dev/src/components/AllIntegrations/OmniSend/OmniSendIntegLayout.jsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import MultiSelect from 'react-multiple-select-dropdown-lite'
21
import { useEffect, useRef } from 'react'
2+
import MultiSelect from 'react-multiple-select-dropdown-lite'
33
import { __ } from '../../../Utils/i18nwrap'
44
import Loader from '../../Loaders/Loader'
5+
import ActionProFeatureComponent from '../IntegrationHelpers/ActionProFeatureComponent'
6+
import { ProFeatureTitle } from '../IntegrationHelpers/ActionProFeatureLabels'
57
import { addFieldMap } from './IntegrationHelpers'
6-
import OmniSendFieldMap from './OmniSendFieldMap'
78
import OmniSendActions from './OmniSendActions'
89
import { generateMappedField } from './OmniSendCommonFunc'
9-
import ActionProFeatureComponent from '../IntegrationHelpers/ActionProFeatureComponent'
10-
import { ProFeatureTitle } from '../IntegrationHelpers/ActionProFeatureLabels'
10+
import OmniSendFieldMap from './OmniSendFieldMap'
1111

1212
export default function OmniSendIntegLayout({
1313
formFields,
@@ -18,7 +18,6 @@ export default function OmniSendIntegLayout({
1818
setLoading,
1919
setSnackbar
2020
}) {
21-
const isInitialMount = useRef(true)
2221
const channels = [
2322
{
2423
label: __('Email', 'bit-integrations'),
@@ -57,18 +56,10 @@ export default function OmniSendIntegLayout({
5756
fields[1].required = false
5857
}
5958
newConf[type] = val
59+
newConf.field_map = generateMappedField(newConf.omniSend_fields)
60+
6061
setOmniSendConf({ ...newConf })
6162
}
62-
useEffect(() => {
63-
if (isInitialMount.current) {
64-
isInitialMount.current = false
65-
} else {
66-
const newConf = { ...omniSendConf }
67-
const tmp = generateMappedField(newConf)
68-
newConf.field_map = tmp
69-
setOmniSendConf(newConf)
70-
}
71-
}, [omniSendConf.channels])
7263

7364
return (
7465
<>

frontend-dev/src/components/Triggers/FormPlugin.jsx

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
1+
import { create } from 'mutative'
12
import { useState } from 'react'
23
import MultiSelect from 'react-multiple-select-dropdown-lite'
34
import 'react-multiple-select-dropdown-lite/dist/index.css'
4-
import { useRecoilState, useSetRecoilState } from 'recoil'
5-
import { $flowStep, $formFields, $newFlow } from '../../GlobalStates'
5+
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'
6+
import { $btcbi, $flowStep, $formFields, $newFlow } from '../../GlobalStates'
67
import useFetch from '../../hooks/useFetch'
78
import bitsFetch from '../../Utils/bitsFetch'
89
import { __ } from '../../Utils/i18nwrap'
910
import Loader from '../Loaders/Loader'
1011
import LoaderSm from '../Loaders/LoaderSm'
1112
import Note from '../Utilities/Note'
1213
import SnackMsg from '../Utilities/SnackMsg'
13-
import TriggerMultiOption from './TriggerMultiOption'
1414
import { FormPluginStateHelper } from './TriggerHelpers/TriggerStateHelper'
15-
import { create } from 'mutative'
15+
import TriggerMultiOption from './TriggerMultiOption'
1616

1717
const FormPlugin = () => {
1818
const [newFlow, setNewFlow] = useRecoilState($newFlow)
1919
const setFlowStep = useSetRecoilState($flowStep)
2020
const setFormFields = useSetRecoilState($formFields)
21+
const [snack, setSnackbar] = useState({ show: false, msg: '' })
22+
const [isLoad, setIsLoad] = useState(false)
23+
const btcbi = useRecoilValue($btcbi)
24+
const { isPro } = btcbi
25+
2126
const { data, isLoading } = useFetch({
2227
payload: {},
2328
action: newFlow.triggerDetail.list.action,
2429
method: newFlow.triggerDetail.list.method
2530
})
26-
const [snack, setSnackbar] = useState({ show: false, msg: '' })
27-
const [isLoad, setIsLoad] = useState(false)
2831

2932
const setFlowData = (val, type) => {
30-
setNewFlow((prevState) =>
31-
create(prevState, (draft) => {
33+
setNewFlow(prevState =>
34+
create(prevState, draft => {
3235
draft.triggerData[type] = val
3336
})
3437
)
3538
}
3639

37-
const setTriggerData = (val) => {
40+
const setTriggerData = val => {
3841
const tmpNewFlow = { ...newFlow }
3942

4043
if (!val) {
@@ -49,11 +52,11 @@ const FormPlugin = () => {
4952
newFlow?.triggerDetail?.name === 'PiotnetAddon' ||
5053
newFlow?.triggerDetail?.name === 'CartFlow'
5154
) {
52-
const filterData = data?.data?.filter((item) => item.id === val)[0]?.post_id || null
55+
const filterData = data?.data?.filter(item => item.id === val)[0]?.post_id || null
5356
queryData = { ...queryData, postId: filterData }
5457
}
5558

56-
bitsFetch(queryData, newFlow.triggerDetail.fields.action).then((resp) => {
59+
bitsFetch(queryData, newFlow.triggerDetail.fields.action).then(resp => {
5760
if (resp.success) {
5861
tmpNewFlow.triggerData = {
5962
formID: val,
@@ -80,7 +83,7 @@ const FormPlugin = () => {
8083
let taskNote = ''
8184

8285
if (newFlow.triggerData?.formID) {
83-
const selectedTask = data?.data?.filter((item) => item.id == newFlow.triggerData?.formID)
86+
const selectedTask = data?.data?.filter(item => item.id == newFlow.triggerData?.formID)
8487
if (selectedTask?.length > 0 && selectedTask[0]?.note) {
8588
taskNote = selectedTask[0].note
8689
}
@@ -111,11 +114,14 @@ const FormPlugin = () => {
111114
<MultiSelect
112115
className="msl-wrp-options"
113116
defaultValue={newFlow.triggerData?.formID}
114-
options={data?.data?.map((form) => ({
115-
label: form.title,
116-
value: form.id.toString()
117+
options={data?.data?.map(form => ({
118+
label: isFormSelectable(isPro, form?.isPro || false)
119+
? form?.title
120+
: form?.title + ' (Pro)',
121+
value: form.id.toString(),
122+
disabled: !isFormSelectable(isPro, form?.isPro || false)
117123
}))}
118-
onChange={(val) => setTriggerData(val)}
124+
onChange={val => setTriggerData(val)}
119125
singleSelect
120126
style={{ width: '100%', minWidth: 400, maxWidth: 450 }}
121127
/>
@@ -150,3 +156,5 @@ const FormPlugin = () => {
150156
)
151157
}
152158
export default FormPlugin
159+
160+
const isFormSelectable = (isProPluginActivated, formIsPro = false) => !formIsPro || isProPluginActivated

includes/Core/Util/Helper.php

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace BitCode\FI\Core\Util;
44

5+
use BitCode\FI\Triggers\TriggerController;
56
use DateTime;
7+
use DateTimeZone;
8+
use Exception;
69
use stdClass;
710
use WP_Error;
8-
use Exception;
9-
use DateTimeZone;
10-
use BitCode\FI\Triggers\TriggerController;
1111

1212
/**
1313
* bit-integration helper class
@@ -299,6 +299,72 @@ public static function acfGetFieldGroups($type = [])
299299
});
300300
}
301301

302+
public static function getAcfFieldData($acfFieldGroups, $postId)
303+
{
304+
if (!class_exists('ACF')) {
305+
return [];
306+
}
307+
308+
$data = [];
309+
310+
foreach ($acfFieldGroups as $group) {
311+
foreach (acf_get_fields($group['ID']) as $field) {
312+
$data[$field['_name']] = get_post_meta($postId, $field['_name'])[0];
313+
}
314+
}
315+
316+
return $data;
317+
}
318+
319+
public static function getWCCustomCheckoutData($order)
320+
{
321+
if (!class_exists('WooCommerce')) {
322+
return [];
323+
}
324+
325+
$data = [];
326+
$order = \is_object($order) ? (array) $order : $order;
327+
$checkoutFields = WC()->checkout()->get_checkout_fields();
328+
329+
foreach ($checkoutFields as $group) {
330+
foreach ($group as $field) {
331+
if (!empty($field['custom'])) {
332+
$data[$field['name']] = $order[$field['name']];
333+
}
334+
}
335+
}
336+
337+
return $data;
338+
}
339+
340+
public static function getFlexibleCheckoutData($order)
341+
{
342+
if (!class_exists('WooCommerce')) {
343+
return [];
344+
}
345+
346+
$data = [];
347+
$order = \is_object($order) ? (array) $order : $order;
348+
$checkoutFields = WC()->checkout()->get_checkout_fields();
349+
350+
foreach ($checkoutFields as $groupKey => $group) {
351+
if ($groupKey == 'shipping') {
352+
continue;
353+
}
354+
355+
foreach ($group as $fieldKey => $field) {
356+
if (empty($field['custom_field'])) {
357+
continue;
358+
}
359+
360+
$fieldKey = $field['name'] ?? $fieldKey;
361+
$data[$fieldKey] = $order[$fieldKey] ?? '';
362+
}
363+
}
364+
365+
return $data;
366+
}
367+
302368
public static function isPrimaryKeysMatch($recordData, $PrimaryKeys)
303369
{
304370
foreach ($PrimaryKeys as $primaryKey) {

0 commit comments

Comments
 (0)