DocsChatSettingsProvider.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types=1 ); |
| 4 | |
| 5 | namespace WPDesk\FS\HookProvider\Admin; |
| 6 | |
| 7 | use FSVendor\Octolize\Docs\Chat\ChatSettings; |
| 8 | use FSVendor\Octolize\Docs\Chat\ChatSettingsProvider as ChatSettingsProviderInterface; |
| 9 | use FSVendor\Octolize\Docs\Chat\ConsentSettings; |
| 10 | |
| 11 | /** |
| 12 | * Provides Flexible Shipping settings and context for the docs chat. |
| 13 | */ |
| 14 | final class DocsChatSettingsProvider implements ChatSettingsProviderInterface { |
| 15 | |
| 16 | private string $plugin_name; |
| 17 | |
| 18 | public function __construct( string $plugin_name ) { |
| 19 | $this->plugin_name = $plugin_name; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @param array<string, mixed> $settings Current chat settings. |
| 24 | * @param array<string, mixed> $request_data Request data. |
| 25 | * |
| 26 | * @return array<string, mixed> |
| 27 | */ |
| 28 | public function prepare_settings( array $settings, array $request_data ): array { |
| 29 | $chat_settings = new ChatSettings(); |
| 30 | $chat_settings->set_consent_settings( $this->prepare_consent_settings() ); |
| 31 | $chat_settings->set_plugin( $this->plugin_name ); |
| 32 | $chat_settings->set_plugin_settings( ( new \WPDesk_Flexible_Shipping_Settings() )->settings ); |
| 33 | |
| 34 | $instance_id = $request_data['instance_id'] ?? ''; |
| 35 | $chat_settings->set_current_page( $instance_id ? 'Shipping method' : 'Plugin Settings' ); |
| 36 | |
| 37 | if ( $instance_id ) { |
| 38 | $shipping_method = \WC_Shipping_Zones::get_shipping_method( (int) $instance_id ); |
| 39 | if ( $shipping_method instanceof \WC_Shipping_Method ) { |
| 40 | $chat_settings->set_shipping_method_settings( $shipping_method->instance_settings ); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return array_merge( $settings, $chat_settings->get_settings() ); |
| 45 | } |
| 46 | |
| 47 | private function prepare_consent_settings(): ConsentSettings { |
| 48 | $consent_settings = new ConsentSettings(); |
| 49 | $consent_settings->set_title( __( 'Do you consent to sending data to the chat?', 'flexible-shipping' ) ); |
| 50 | $consent_settings->set_message( __( 'To start the chat, we need to send your inputs and technical data to the chat service.', 'flexible-shipping' ) ); |
| 51 | $consent_settings->set_accept( __( 'Accept', 'flexible-shipping' ) ); |
| 52 | $consent_settings->set_decline( __( 'Decline', 'flexible-shipping' ) ); |
| 53 | $consent_settings->set_privacy_policy_url( ' ' ); |
| 54 | $consent_settings->set_privacy_link_label( ' ' ); |
| 55 | $consent_settings->set_support_url( 'https://wordpress.org/support/plugin/flexible-shipping/' ); |
| 56 | $consent_settings->set_support_text( __( 'If you don’t want to give consent, you can contact our support using this: ', 'flexible-shipping' ) ); |
| 57 | $consent_settings->set_support_link_label( __( 'support forum', 'flexible-shipping' ) ); |
| 58 | |
| 59 | return $consent_settings; |
| 60 | } |
| 61 | } |
| 62 |