-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add site_id to the SFCC datasource #353
Changes from all commits
1b77596
9946819
ea20532
13f6b52
a483815
1a225ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ protected static function get_service_config_schema(): array { | |
'enable_blocks' => Types::nullable( Types::boolean() ), | ||
'organization_id' => Types::string(), | ||
'shortcode' => Types::string(), | ||
// ToDo: Remove the nullable, once existing SFCC data sources have been migrated. | ||
'site_id' => Types::nullable( Types::string() ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is set to nullable only until the existing test sites are migrated. After that, the nullable part can be dropped. Same thing as below, it's an interim fix to add the |
||
] ); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,16 @@ public static function register_blocks(): void { | |
|
||
foreach ( $data_source_configs as $config ) { | ||
$data_source = SalesforceB2CDataSource::from_array( $config ); | ||
|
||
if ( false === ( $config['service_config']['enable_blocks'] ?? true ) ) { | ||
continue; | ||
} | ||
|
||
|
||
// ToDo: Remove this once existing SFCC data sources have been migrated. | ||
if ( empty( $config['service_config']['site_id'] ) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is present to stop existing test sites from breaking. It adds the previous value as a default value. Once these test sites have been migrated, this can be removed. I've added this as an interim fix to add the |
||
$config['service_config']['site_id'] = 'RefArchGlobal'; | ||
} | ||
|
||
self::register_blocks_for_salesforce_data_source( $data_source ); | ||
} | ||
} | ||
|
@@ -31,12 +36,18 @@ private static function get_queries( SalesforceB2CDataSource $data_source ): arr | |
$base_endpoint = $data_source->get_endpoint(); | ||
$service_config = $data_source->to_array()['service_config']; | ||
|
||
// ToDo: Remove this once existing SFCC data sources have been migrated. | ||
if ( empty( $service_config['site_id'] ) ) { | ||
$service_config['site_id'] = 'RefArchGlobal'; | ||
} | ||
|
||
$get_request_headers = function () use ( $base_endpoint, $service_config ): array|WP_Error { | ||
$access_token = SalesforceB2CAuth::generate_token( | ||
$base_endpoint, | ||
$service_config['organization_id'], | ||
$service_config['client_id'], | ||
$service_config['client_secret'] | ||
$service_config['client_secret'], | ||
$service_config['site_id'] | ||
); | ||
$request_headers = [ 'Content-Type' => 'application/json' ]; | ||
|
||
|
@@ -52,10 +63,11 @@ private static function get_queries( SalesforceB2CDataSource $data_source ): arr | |
'data_source' => $data_source, | ||
'endpoint' => function ( array $input_variables ) use ( $base_endpoint, $service_config ): string { | ||
return sprintf( | ||
'%s/product/shopper-products/v1/organizations/%s/products/%s?siteId=RefArchGlobal', | ||
'%s/product/shopper-products/v1/organizations/%s/products/%s?siteId=%s', | ||
$base_endpoint, | ||
$service_config['organization_id'], | ||
$input_variables['product_id'] | ||
$input_variables['product_id'], | ||
$service_config['site_id'] | ||
); | ||
}, | ||
'input_schema' => [ | ||
|
@@ -105,9 +117,10 @@ private static function get_queries( SalesforceB2CDataSource $data_source ): arr | |
'data_source' => $data_source, | ||
'endpoint' => function ( array $input_variables ) use ( $base_endpoint, $service_config ): string { | ||
return sprintf( | ||
'%s/search/shopper-search/v1/organizations/%s/product-search?siteId=RefArchGlobal&q=%s', | ||
'%s/search/shopper-search/v1/organizations/%s/product-search?siteId=%s&q=%s', | ||
$base_endpoint, | ||
$service_config['organization_id'], | ||
$service_config['site_id'], | ||
urlencode( $input_variables['search'] ) | ||
); | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ import { TextControl } from '@wordpress/components'; | |
import { useMemo } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
import { DataSourceForm } from '../components/DataSourceForm'; | ||
import { DataSourceForm } from '@/data-sources/components/DataSourceForm'; | ||
import PasswordInputControl from '@/data-sources/components/PasswordInputControl'; | ||
import { useDataSources } from '@/data-sources/hooks/useDataSources'; | ||
import { | ||
SettingsComponentProps, | ||
SalesforceB2CConfig, | ||
SalesforceB2CServiceConfig, | ||
SettingsComponentProps, | ||
} from '@/data-sources/types'; | ||
import { useForm } from '@/hooks/useForm'; | ||
import SalesforceCommerceB2CIcon from '@/settings/icons/SalesforceCommerceB2CIcon'; | ||
|
@@ -30,8 +30,20 @@ export const SalesforceB2CSettings = ( { | |
} ); | ||
|
||
const shouldAllowSubmit = useMemo( () => { | ||
return state.shortcode && state.organization_id && state.client_id && state.client_secret; | ||
}, [ state.shortcode, state.organization_id, state.client_id, state.client_secret ] ); | ||
return ( | ||
state.site_id && | ||
state.shortcode && | ||
state.organization_id && | ||
state.client_id && | ||
state.client_secret | ||
); | ||
}, [ | ||
state.site_id, | ||
state.shortcode, | ||
state.organization_id, | ||
state.client_id, | ||
state.client_secret, | ||
] ); | ||
|
||
const onSaveClick = async () => { | ||
if ( ! validState ) { | ||
|
@@ -86,6 +98,18 @@ export const SalesforceB2CSettings = ( { | |
__next40pxDefaultSize | ||
/> | ||
|
||
<TextControl | ||
type="text" | ||
label={ __( 'Site ID', 'remote-data-blocks' ) } | ||
onChange={ siteId => { | ||
handleOnChange( 'site_id', siteId ?? '' ); | ||
} } | ||
value={ state.site_id ?? 'RefArchGlobal' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Provided a default value similar to what we had before of |
||
help={ __( 'The site ID. Example: RefArchGlobal' ) } | ||
autoComplete="off" | ||
__next40pxDefaultSize | ||
/> | ||
|
||
<TextControl | ||
type="text" | ||
label={ __( 'Client ID', 'remote-data-blocks' ) } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this was different than the
site_id
hardcoded elsewhere ofRefArchGlobal
so I've corrected this.