1119 lines
43 KiB
PHP
1119 lines
43 KiB
PHP
<?php
|
|
|
|
if ( ! class_exists( 'WC_Paczkomaty_Shipping_Method' ) ) {
|
|
|
|
class WC_Paczkomaty_Shipping_Method extends WC_Shipping_Method {
|
|
use \VendorInPost\WPDesk\PickupPoints\WooCommerceSettings\RefreshPickupPointsTrait;
|
|
|
|
const SHIPPING_METHOD_ID = 'paczkomaty_shipping_method';
|
|
const SHIPPING_INTEGRATION_ID = 'paczkomaty';
|
|
|
|
/**
|
|
* API types.
|
|
*/
|
|
const API_TYPE_XML = 'XML';
|
|
const API_TYPE_SHIPX = 'shipX';
|
|
/**
|
|
* Setting fields (options).
|
|
*/
|
|
const SETTING_DEFAULT_PACKAGE_SIZE = 'default_package_size';
|
|
const SETTING_SELF_SEND = 'self_send';
|
|
const SETTING_SENDING_METHOD = 'sending_method';
|
|
const SETTING_DEFAULT_PARCEL_LOCKER = 'default_parcel_locker';
|
|
const SETTING_DEFAULT_POP = 'default_pop';
|
|
const SETTING_DEFAULT_DISPATCH_POINT = 'default_dispatch_point';
|
|
const SETTING_DOMYSLNY_PUNKT_NADANIA = 'domyslny_punkt_nadania';
|
|
|
|
/**
|
|
* Services
|
|
*/
|
|
const USLUGA_PACZKOMATY = 'paczkomaty';
|
|
const USLUGA_ALLEGRO_PACZKOMATY = 'allegro_paczkomaty';
|
|
const USLUGA_POLECONY = 'polecony';
|
|
const USLUGA_ALLEGRO_POLECONY = 'allegro_polecony';
|
|
const USLUGA_KURIER = 'kurier';
|
|
const USLUGA_ALLEGRO_KURIER = 'allegro_kurier';
|
|
|
|
/**
|
|
* Sending methods
|
|
*/
|
|
const SENDING_METHOD_PARCEL_LOCKER = 'parcel_locker';
|
|
const SENDING_METHOD_DISPATCH_ORDER = 'dispatch_order';
|
|
|
|
const SENDING_METHOD_PARCEL_LOCKER_XML_API = '1';
|
|
const SENDING_METHOD_DISPATCH_ORDER_XML_API = '3';
|
|
|
|
const LAST_REFRESH_MACHINES_FIELD = 'inpost_machines_last_refresh';
|
|
|
|
const OPTION_INSERT_INTO_SECTION = 'insert_into_section';
|
|
const OPTION_INSERT_BELOW_SECTION = 'insert_below_section';
|
|
const OPTION_NEW_SECTION = 'new_section_below_checkout_summary';
|
|
const SELECT_PLACEMENT = 'select_placement';
|
|
const SELECT_METHOD_SELECT = 'select';
|
|
const SELECT_METHOD_SELECT_AND_MAP = 'select_and_map';
|
|
const SELECT_METHOD_MAP = 'map';
|
|
const FAST_RETURNS_BUTTON_LABEL = 'fast_returns_button_label';
|
|
const FAST_RETURNS_URL = 'fast_returns_url';
|
|
const DISPATCH_POINT = 'dispatch_point';
|
|
const DISPATCH_POINT_NAME = 'dispatch_point_name';
|
|
const DISPATCH_POINT_PHONE = 'dispatch_point_phone';
|
|
const DISPATCH_POINT_EMAIL = 'dispatch_point_email';
|
|
const DISPATCH_POINT_COMMENTS = 'dispatch_point_comments';
|
|
const DISPATCH_POINT_OFFICE_HOURS = 'dispatch_point_office_hours';
|
|
const DISPATCH_POINT_POSTCODE = 'dispatch_point_postcode';
|
|
const DISPATCH_POINT_CITY = 'dispatch_point_city';
|
|
const DISPATCH_POINT_STREET = 'dispatch_point_street';
|
|
const DISPATCH_POINT_BUILDING_NUMBER = 'dispatch_point_building_number';
|
|
|
|
public const SENDER_DATA = 'sender_data';
|
|
public const FROM_ORGANIZATION = 'from_organization';
|
|
public const CUSTOM = 'custom';
|
|
public const SENDER_COMPANY_NAME = 'sender_company_name';
|
|
public const SENDER_EMAIL = 'sender_email';
|
|
public const SENDER_PHONE = 'sender_phone';
|
|
public const SENDER_STREET = 'sender_street';
|
|
public const SENDER_BUILDING_NUMBER = 'sender_building_number';
|
|
public const SENDER_POSTCODE = 'sender_postcode';
|
|
public const SENDER_CITY = 'sender_city';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
public $packageSizes;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
public $howToGive = array();
|
|
|
|
/**
|
|
* @var WPDesk_Paczkomaty_ShipX
|
|
*/
|
|
private $shipX;
|
|
|
|
/**
|
|
* @var WPDesk_Paczkomaty_ShipX_Cache
|
|
*/
|
|
private $shipX_cache;
|
|
|
|
/**
|
|
* @var \FS\InPost\PickupPoints\PickupPointsManager
|
|
*/
|
|
public static $pickup_points_manager;
|
|
|
|
public function __construct( $instance_id = 0 ) {
|
|
|
|
$this->id = self::SHIPPING_METHOD_ID;
|
|
$this->instance_id = absint( $instance_id );
|
|
|
|
$this->supports = array(
|
|
'settings',
|
|
);
|
|
|
|
$this->packageSizes = ( new WPDesk_Paczkomaty_Package_Sizes() )->get_package_sizes_with_select_label();
|
|
|
|
$this->howToGive[0] = '-- ' . __( 'wybierz', 'woocommerce-paczkomaty-inpost' ) . ' --';
|
|
$this->howToGive[1] = __( 'Paczkomat', 'woocommerce-paczkomaty-inpost' );
|
|
$this->howToGive[3] = __( 'Kurier', 'woocommerce-paczkomaty-inpost' );
|
|
|
|
|
|
$this->method_title = __( 'InPost', 'woocommerce-paczkomaty-inpost' );
|
|
$this->method_description = sprintf(
|
|
// Translators: links.
|
|
__( 'Wysyłka usługami InPost. Pamiętaj, aby po skonfigurowaniu ustawień w tym miejscu dodać metodę wysyłki z integracją InPost %1$sw strefie wysyłki%2$s dla Polski. %3$sInstrukcja konfiguracji →%4$s', 'woocommerce-paczkomaty-inpost' ),
|
|
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=shipping§ion' ) . '">',
|
|
'</a>',
|
|
'<a href="https://octol.io/inpost-method-docs-pl" target="_blank">',
|
|
'</a>'
|
|
);
|
|
|
|
$this->init();
|
|
|
|
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
|
|
|
|
add_filter( 'woocommerce_settings_api_sanitized_fields_' . $this->id, array(
|
|
$this,
|
|
'woocommerce_settings_api_sanitized_fields'
|
|
) );
|
|
|
|
add_filter( 'woocommerce_settings_api_form_fields_' . $this->id, array(
|
|
$this,
|
|
'woocommerce_settings_api_form_fields'
|
|
) );
|
|
|
|
}
|
|
|
|
/**
|
|
* Get shipX API.
|
|
*
|
|
* @return WPDesk_Paczkomaty_ShipX
|
|
*/
|
|
public function get_shipX() {
|
|
if ( empty( $this->shipX ) ) {
|
|
$test_mode = 'yes' !== $this->get_option( 'test_mode', '' ) ? false : true;
|
|
$this->shipX = new WPDesk_Paczkomaty_ShipX(
|
|
$this->get_option( 'token', '' ),
|
|
$this->get_option( 'token_test_mode', '' ),
|
|
$test_mode
|
|
);
|
|
$this->shipX->set_organization_id( $this->get_option( 'organization_id', '' ) );
|
|
}
|
|
|
|
return $this->shipX;
|
|
}
|
|
|
|
/**
|
|
* @return WPDesk_Paczkomaty_ShipX_Cache
|
|
*/
|
|
public function get_shipX_cache() {
|
|
if ( empty( $this->shipX_cache ) ) {
|
|
$shipX = $this->get_shipX();
|
|
if ( $shipX ) {
|
|
$this->shipX_cache = new WPDesk_Paczkomaty_ShipX_Cache( $shipX );
|
|
}
|
|
}
|
|
|
|
return $this->shipX_cache;
|
|
}
|
|
|
|
/**
|
|
* @param $form_fields
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function woocommerce_settings_api_form_fields( $form_fields ) {
|
|
return $form_fields;
|
|
}
|
|
|
|
/**
|
|
* @param $settings
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function woocommerce_settings_api_sanitized_fields( $settings ) {
|
|
$settings['kurier_webhook_url'] = site_url( '?shipx_webhook=' . $settings['kurier_webhook_token'] );
|
|
|
|
return $settings;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function process_admin_options() {
|
|
$parent_ret = parent::process_admin_options();
|
|
$shipX_cache = $this->get_shipX_cache();
|
|
if ( $shipX_cache ) {
|
|
$shipX_cache->clear_cache();
|
|
}
|
|
delete_option( 'paczkomaty_cached_timestamp' );
|
|
delete_transient( 'paczkomaty_dp' );
|
|
delete_transient( 'paczkomaty_paczkomaty_p_p' );
|
|
delete_transient( 'paczkomaty_paczkomaty_pt_p' );
|
|
|
|
return $parent_ret;
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
function init() {
|
|
|
|
$this->init_settings();
|
|
|
|
// Load the settings API
|
|
$this->settings['enabled'] = 'yes';
|
|
$this->enabled = 'yes';
|
|
$this->title = $this->get_option( 'title' );
|
|
|
|
$this->init_form_fields();
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
*/
|
|
function init_form_fields() {
|
|
/** @var WC_Paczkomaty_Shipping_Method $this */
|
|
|
|
$package_sizes = new WPDesk_Paczkomaty_Package_Sizes();
|
|
|
|
$token_description = sprintf(
|
|
__( 'Wprowadź token dla Twojej organizacji. Możesz uzyskać go od opiekuna InPost lub wygenerować go samodzielnie postępując zgodnie z %1$sinstrukcją%2$s. Token powinien mieć formę ciągu ok. 300 znaków złożonego z małych i dużych liter oraz cyfr. Jeżeli napotkałeś/-aś na błąd autoryzacji i informację o nieprawidłowym tokenie, upewnij się, że został on wprowadzony w całości, nie została zmieniona wielkość liter oraz nie zawiera on kropki na końcu.', 'woocommerce-paczkomaty-inpost' ),
|
|
'<a href="https://inpost.pl/sites/default/files/pdf/instrukcja-konfiguracji-api-shipx.pdf" target="_blank">',
|
|
'</a>'
|
|
);
|
|
|
|
$this->form_fields = [
|
|
[
|
|
'title' => __( 'Ustawienia główne', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'default' => '',
|
|
'description' => __( 'Wprowadzając token w poniższym polu uzyskasz możliwość tworzenia przesyłek InPost i generowania dla nich etykiet wysyłkowych. Token nie jest jednak wymagany, jeżeli chcesz jedynie zaoferować swoim klientom możliwość wyboru paczkomatu z listy lub z mapy podczas składania zamówienia, bez możliwości nadawania przesyłek za pomocą wtyczki. Funkcjonalności te będą dostępne standardowo, bez wprowadzenia tokena.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'token' => [
|
|
'title' => __( 'Token', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'textarea',
|
|
'default' => '',
|
|
'class' => 'api-token',
|
|
'desc_tip' => false,
|
|
'description' => $token_description,
|
|
],
|
|
'kurier_webhook_token' => [
|
|
'title' => __( 'Klucz', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'default' => md5( site_url() ),
|
|
'description' => __( 'Po zmianie tokena konieczna jest aktualizacja adresu webhooka po stronie InPost', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'kurier_webhook_url' => [
|
|
'title' => __( 'Adres URL dla API (webhook)', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'default' => site_url( '?shipx_webhook=' . $this->get_option( 'kurier_webhook_token', '' ) ),
|
|
'desc_tip' => true,
|
|
'description' => __( 'Wygenerowany adres URL zarejestruj w InPost, prześlij adres do swojego opiekuna InPost.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'organization_id' => [
|
|
'title' => __( 'Organizacja', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'options' => [],
|
|
'class' => 'shipx',
|
|
'default' => '',
|
|
'desc_tip' => true,
|
|
'description' => __( 'Jeśli zarejestrowałeś w InPost kilka organizacji wybierz właściwą dla twojego sklepu.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'services' => [
|
|
'title' => __( 'Usługi InPost', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'services',
|
|
'options' => [],
|
|
'default' => '',
|
|
'class' => 'shipx',
|
|
'desc_tip' => true,
|
|
'description' => __( 'Lista zawiera usługi obsługiwane przez wtyczkę oraz pokazuje status dostępności dla danej organizacji. Jeśli usługa nie jest dostępna skontaktuj się z opiekunem konta InPost.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
[
|
|
'title' => __( 'Nadawca', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'default' => '',
|
|
'desc_tip' => true,
|
|
'class' => 'shipx',
|
|
],
|
|
self::SENDER_DATA => [
|
|
'title' => __( 'Dane nadawcy', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'options' => [
|
|
self::FROM_ORGANIZATION => __( 'Dane z ustawień organizacji na koncie InPost', 'woocommerce-paczkomaty-inpost' ),
|
|
self::CUSTOM => __( 'Wprowadzę własne dane', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
],
|
|
self::SENDER_COMPANY_NAME => [
|
|
'title' => __( 'Nazwa firmy', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'class' => 'shipx sender_data_custom',
|
|
'default' => '',
|
|
],
|
|
self::SENDER_EMAIL => [
|
|
'title' => __( 'Adres e-mail', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'email',
|
|
'class' => 'shipx sender_data_custom',
|
|
'default' => '',
|
|
],
|
|
self::SENDER_PHONE => [
|
|
'title' => __( 'Numer telefonu', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'class' => 'shipx sender_data_custom',
|
|
'default' => '',
|
|
],
|
|
self::SENDER_STREET => [
|
|
'title' => __( 'Ulica', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'class' => 'shipx sender_data_custom',
|
|
'default' => '',
|
|
],
|
|
self::SENDER_BUILDING_NUMBER => [
|
|
'title' => __( 'Numer budynku', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'class' => 'shipx sender_data_custom',
|
|
'default' => '',
|
|
],
|
|
self::SENDER_POSTCODE => [
|
|
'title' => __( 'Kod pocztowy', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'class' => 'shipx sender_data_custom',
|
|
'default' => '',
|
|
],
|
|
self::SENDER_CITY => [
|
|
'title' => __( 'Miasto', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'class' => 'shipx sender_data_custom',
|
|
'default' => '',
|
|
],
|
|
[
|
|
'title' => __( 'Ustawienia przesyłek', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'default' => '',
|
|
'desc_tip' => true,
|
|
'class' => 'shipx',
|
|
],
|
|
'sending_method' => [
|
|
'title' => __( 'Domyślny sposób nadania', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'default' => 'dispatch_order',
|
|
'options' => [],
|
|
'class' => 'shipx',
|
|
'desc_tip' => true,
|
|
'description' => __( 'Domyślny sposób nadania nie jest wymagany do nadania przesyłki.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'default_parcel_locker' => [
|
|
'title' => __( 'Domyślny paczkomat nadawczy', 'woocommerce-paczkomaty-inpost' ),
|
|
'description' => '',
|
|
'type' => 'select',
|
|
'default' => '',
|
|
'options' => [],
|
|
'class' => 'select2_ajax_paczkomaty shipx sending_method sending_method_parcel_locker',
|
|
],
|
|
WC_Paczkomaty_Shipping_Method::SETTING_DEFAULT_PACKAGE_SIZE => [
|
|
'title' => __( 'Domyślny rozmiar paczki dla paczkomatów', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'options' => $package_sizes->get_package_sizes_with_select_label(),
|
|
'desc_tip' => true,
|
|
'description' => __( 'Domyślny rozmiar paczki dla paczkomatów używany w integracjach, np. Allegro.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
[
|
|
'title' => __( 'Generowanie przesyłek', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'default' => '',
|
|
'desc_tip' => true,
|
|
],
|
|
'auto_create' => [
|
|
'title' => __( 'Sposób generowania', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'default' => 'manual',
|
|
'options' => [
|
|
'manual' => __( 'Ręczne', 'woocommerce-paczkomaty-inpost' ),
|
|
'auto' => __( 'Automatyczne', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
],
|
|
'order_status' => [
|
|
'title' => __( 'Status zamówienia', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'default' => 'wc-completed',
|
|
'options' => wc_get_order_statuses(),
|
|
'description' => __( 'Wybierz status zamówienia przy którym zostanie automatycznie utworzona przesyłka.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'complete_order' => [
|
|
'title' => __( 'Zrealizuj zamówienie', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'checkbox',
|
|
'label' => __( 'Włącz zmianę statusu zamówienia na Zrealizowane', 'woocommerce-paczkomaty-inpost' ),
|
|
'default' => 'no',
|
|
'description' => __( 'Po nadaniu przesyłek status zamówienia zostanie automatycznie zmieniony na Zrealizowane.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
[
|
|
'title' => __( 'Etykiety', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'description' => '',
|
|
],
|
|
'label_format_type' => [
|
|
'title' => __( 'Format i typ etykiet', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'options' => [
|
|
'pdf:normal' => __( 'PDF A4 - jedna etykieta na stronę', 'woocommerce-paczkomaty-inpost' ),
|
|
'pdf:normal:group' => __( 'PDF A4 - wiele etykiet na stronę', 'woocommerce-paczkomaty-inpost' ),
|
|
'pdf:A6' => __( 'PDF A6', 'woocommerce-paczkomaty-inpost' ),
|
|
'epl:A6' => __( 'EPL', 'woocommerce-paczkomaty-inpost' ),
|
|
'zpl:A6' => __( 'ZPL', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'default' => 'pdf',
|
|
],
|
|
'auto_print' => [
|
|
'title' => __( 'Drukowanie', 'woocommerce-paczkomaty-inpost' ),
|
|
'label' => __( 'Włącz automatyczne drukowanie', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'checkbox',
|
|
'description' => '',
|
|
'custom_attributes' => [],
|
|
'default' => 'no',
|
|
'desc_tip' => false,
|
|
],
|
|
[
|
|
'title' => __( 'Wybór paczkomatu', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'description' => '',
|
|
],
|
|
'select_method' => [
|
|
'title' => __( 'Sposób wyboru paczkomatu', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'desc_tip' => __( 'Wybierz, w jaki sposób Twoi klienci będą mogli wybrać paczkomat do wysyłki zamawianych produktów.', 'woocommerce-paczkomaty-inpost' ),
|
|
'options' => [
|
|
self::SELECT_METHOD_SELECT => __( 'Tylko lista paczkomatów', 'woocommerce-paczkomaty-inpost' ),
|
|
self::SELECT_METHOD_SELECT_AND_MAP => __( 'Lista paczkomatów + wybór z mapy', 'woocommerce-paczkomaty-inpost' ),
|
|
self::SELECT_METHOD_MAP => __( 'Tylko wybór z mapy', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'default' => self::SELECT_METHOD_SELECT_AND_MAP,
|
|
],
|
|
'select_type' => [
|
|
'title' => __( 'Typ listy paczkomatów', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'description' => sprintf( __( 'Sprawdź opis typów listy paczkomatów w naszej %sdokumentacji%s.', 'woocommerce-paczkomaty-inpost' ), '<a href="https://octol.io/inpost-list-type-docs-pl" target="_blank">', '</a>' ),
|
|
'options' => [
|
|
'select' => __( 'Select', 'woocommerce-paczkomaty-inpost' ),
|
|
'select2' => __( 'Select2', 'woocommerce-paczkomaty-inpost' ),
|
|
'select2_ajax' => __( 'Select2 (AJAX)', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'default' => 'select2_ajax',
|
|
],
|
|
self::SELECT_PLACEMENT => [
|
|
'title' => __( 'Miejsce wyświetlania', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'options' => [
|
|
self::OPTION_INSERT_INTO_SECTION => __( 'Bezpośrednio pod metodą wysyłki', 'woocommerce-paczkomaty-inpost' ),
|
|
self::OPTION_INSERT_BELOW_SECTION => __( 'Pod wszystkimi metodami wysyłki', 'woocommerce-paczkomaty-inpost' ),
|
|
self::OPTION_NEW_SECTION => __( 'Nowa sekcja pod podsumowaniem zamówienia', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'description' => __( 'Uwaga! Ustawienie miejsca wyświetlania wyboru paczkomatu dotyczy wyłącznie formularza zamówienia wyświetlanego przez shortcode. W formularzu blokowym wybór paczkomatu dostępny jest wyłącznie pod wszystkimi metodami wysyłki.', 'woocommerce-paczkomaty-inpost' ),
|
|
'default' => self::OPTION_INSERT_BELOW_SECTION,
|
|
'desc_tip' => __( 'Wskaż, w którym miejscu na stronie finalizacji zamówienia ma zostać wyświetlony Twoim klientom mechanizm wyboru paczkomatu do wysyłki zamawianych produktów.', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
[
|
|
'title' => __( 'Protokoły nadania i zlecenia odbioru przesyłek', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'description' => '',
|
|
],
|
|
self::DISPATCH_POINT => [
|
|
'title' => __( 'Punkt odbioru przesyłek przez kuriera', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'description' => sprintf(
|
|
__( 'Wskaż punkt odbioru zdefiniowany na Twoim koncie InPost (Moje konto → Moje punkty odbioru), z którego kurier ma odebrać nadawane przez Ciebie przesyłki lub wprowadź jego dane ręcznie. Protokoły nadania/zlecenia odbioru zostaną wygenerowane dla wybranego punktu. Dowiedz się więcej na temat %1$sprotokołów nadania i zleceń odbioru przesyłek InPost →%2$s', 'woocommerce-paczkomaty-inpost' ),
|
|
'<a href="https://octol.io/inpost-zlecenie-odbioru" target="_blank">',
|
|
'</a>'
|
|
),
|
|
'options' => [],
|
|
],
|
|
self::DISPATCH_POINT_NAME => [
|
|
'title' => __( 'Nazwa punktu', 'woocommerce-paczkomaty-inpost' ) . ' *',
|
|
'class' => 'dispatch-point dispatch-point-required',
|
|
'type' => 'text',
|
|
],
|
|
self::DISPATCH_POINT_PHONE => [
|
|
'title' => __( 'Telefon', 'woocommerce-paczkomaty-inpost' ) . ' *',
|
|
'class' => 'dispatch-point dispatch-point-required',
|
|
'type' => 'text',
|
|
],
|
|
self::DISPATCH_POINT_EMAIL => [
|
|
'title' => __( 'E-mail', 'woocommerce-paczkomaty-inpost' ) . ' *',
|
|
'class' => 'dispatch-point dispatch-point-required',
|
|
'type' => 'email',
|
|
],
|
|
self::DISPATCH_POINT_COMMENTS => [
|
|
'title' => __( 'Wskazówki dla kuriera', 'woocommerce-paczkomaty-inpost' ),
|
|
'class' => 'dispatch-point',
|
|
'type' => 'textarea',
|
|
],
|
|
self::DISPATCH_POINT_OFFICE_HOURS => [
|
|
'title' => __( 'Godziny pracy', 'woocommerce-paczkomaty-inpost' ),
|
|
'class' => 'dispatch-point',
|
|
'type' => 'text',
|
|
],
|
|
self::DISPATCH_POINT_POSTCODE => [
|
|
'title' => __( 'Kod pocztowy', 'woocommerce-paczkomaty-inpost' ) . ' *',
|
|
'class' => 'dispatch-point dispatch-point-required',
|
|
'type' => 'text',
|
|
],
|
|
self::DISPATCH_POINT_CITY => [
|
|
'title' => __( 'Miasto', 'woocommerce-paczkomaty-inpost' ) . ' *',
|
|
'class' => 'dispatch-point dispatch-point-required',
|
|
'type' => 'text',
|
|
],
|
|
self::DISPATCH_POINT_STREET => [
|
|
'title' => __( 'Ulica', 'woocommerce-paczkomaty-inpost' ) . ' *',
|
|
'class' => 'dispatch-point dispatch-point-required',
|
|
'type' => 'text',
|
|
],
|
|
self::DISPATCH_POINT_BUILDING_NUMBER => [
|
|
'title' => __( 'Nr budynku i lokalu', 'woocommerce-paczkomaty-inpost' ) . ' *',
|
|
'class' => 'dispatch-point dispatch-point-required',
|
|
'type' => 'text',
|
|
],
|
|
[
|
|
'title' => __( 'Szybkie zwroty', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'description' => '',
|
|
],
|
|
self::FAST_RETURNS_URL => [
|
|
'title' => __( 'Adres profilu sklepu w serwisie Szybkie Zwroty', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'placeholder' => 'https://szybkiezwroty.pl/twojsklep',
|
|
'description' => sprintf(
|
|
__( 'Wprowadź pełny adres profilu Twojego sklepu w serwisie SzybkieZwroty.pl. Dowiedz się więcej na temat %1$sSzybkich Zwrotów →%2$s', 'woocommerce-paczkomaty-inpost' ),
|
|
'<a href="https://octol.io/inpost-szybkie-zwroty" target="_blank">',
|
|
'</a>'
|
|
),
|
|
],
|
|
self::FAST_RETURNS_BUTTON_LABEL => [
|
|
'title' => __( 'Tekst przycisku', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'placeholder' => __( 'Szybkie Zwroty', 'woocommerce-paczkomaty-inpost' ),
|
|
'desc_tip' => sprintf(
|
|
__( 'Wprowadź tekst, który będzie widoczny na dodatkowym przycisku służącym do obsługi zwrotów, wyświetlanym klientom na liście zamówień i na stronie szczegółów zamówienia, po zalogowaniu, w zakładce %1$sMoje konto → Zamówienia.%2$s', 'woocommerce-paczkomaty-inpost' ),
|
|
'<strong>',
|
|
'</strong>'
|
|
),
|
|
'default' => __( 'Szybkie Zwroty', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
[
|
|
'title' => __( 'Opcje zaawansowane', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'description' => '',
|
|
],
|
|
'test_mode' => [
|
|
'title' => __( 'Tryb testowy', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'checkbox',
|
|
'label' => __( 'Włącz tryb testowy', 'woocommerce-paczkomaty-inpost' ),
|
|
],
|
|
'token_test_mode' => [
|
|
'title' => __( 'Token dla trybu testowego', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'textarea',
|
|
'desc_tip' => false,
|
|
'class' => 'test_mode_shipx api-token',
|
|
'description' => $token_description,
|
|
'default' => '',
|
|
],
|
|
'logging' => [
|
|
'title' => __( 'Zapis zdarzeń', 'woocommerce-paczkomaty-inpost' ),
|
|
'label' => __( 'Włącz zapis zdarzeń do logów', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'checkbox',
|
|
'description' => sprintf( __( 'Zapis zdarzeń należy włączać tylko podczas diagnozowania problemów. Zdarzenia zapisywane są w %sdzienniku WooCommerce%s.', 'woocommerce-paczkomaty-inpost' ), '<a href="' . admin_url( 'admin.php?page=wc-status&tab=logs' ) . '" target="_blank">', '</a>' ),
|
|
'custom_attributes' => [],
|
|
'default' => 'no',
|
|
'desc_tip' => false,
|
|
],
|
|
'refresh_points' => [
|
|
'type' => 'refresh_pickup_points',
|
|
'service' => 'inpost',
|
|
],
|
|
[
|
|
'title' => sprintf(
|
|
__( 'API XML zostanie wyłączone przez InPost! Rekomendujemy uzyskanie dostępu do nowego API ShipX u opiekuna konta InPost. Nowe API oferuje więcej możliwości, %1$ssprawdź%2$s.', 'woocommerce-paczkomaty-inpost' ),
|
|
'<a target="_blank" href="https://www.wpdesk.pl/blog/api-shipx-api-xml/">',
|
|
'</a>'
|
|
),
|
|
'type' => 'title',
|
|
'default' => '',
|
|
'class' => 'xml_api_message paczkomaty',
|
|
'desc_tip' => true,
|
|
],
|
|
[
|
|
'title' => __( 'API XML (Paczkomaty)', 'woocommerce-paczkomaty-inpost' ),
|
|
'description' => __( 'UWAGA: API XML nie jest rozwijane przez InPost od czerwca 2017 roku', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'default' => '',
|
|
'desc_tip' => true,
|
|
],
|
|
'paczkomaty' => [
|
|
'title' => __( 'API XML (Paczkomaty)', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'checkbox',
|
|
'label' => __( 'Zaznacz aby nadawać do Paczkomatów przez API XML', 'woocommerce-paczkomaty-inpost' ),
|
|
'default' => 'no',
|
|
],
|
|
'email' => [
|
|
'title' => __( 'Login', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'password' => [
|
|
'title' => __( 'Hasło', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'password',
|
|
'default' => '',
|
|
'custom_attributes' => [ 'autocomplete' => 'new-password' ],
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'test_mode_email' => [
|
|
'title' => __( 'Login dla trybu testowego', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'class' => 'paczkomaty test_mode_paczkomaty',
|
|
'default' => '',
|
|
],
|
|
'test_mode_password' => [
|
|
'title' => __( 'Hasło dla trybu testowego', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'password',
|
|
'class' => 'paczkomaty test_mode_paczkomaty',
|
|
'default' => '',
|
|
],
|
|
'self_send' => [
|
|
'title' => __( 'Domyślny sposób nadania', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'select',
|
|
'default' => '1',
|
|
'options' => $this->howToGive,
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_data' => [
|
|
'title' => __( 'Dane nadawcy', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'title',
|
|
'default' => '',
|
|
'desc_tip' => true,
|
|
'description' => __( 'Dane nadawcy wymagane dla usługi Paczka E-Commerce Allegro (API XML)', 'woocommerce-paczkomaty-inpost' ),
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_name' => [
|
|
'title' => __( 'Imię', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_surName' => [
|
|
'title' => __( 'Nazwisko', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_companyName' => [
|
|
'title' => __( 'Nazwa firmy', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_email' => [
|
|
'title' => __( 'E-mail', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_phoneNum' => [
|
|
'title' => __( 'Telefon', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_street' => [
|
|
'title' => __( 'Ulica', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_street_number' => [
|
|
'title' => __( 'Nr domu i mieszkania', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_town' => [
|
|
'title' => __( 'Miejscowość', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
'polecony_sender_zipCode' => [
|
|
'title' => __( 'Kod pocztowy', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'text',
|
|
'desc_tip' => true,
|
|
'default' => '',
|
|
'class' => 'paczkomaty',
|
|
],
|
|
];
|
|
|
|
$test_mode_after = 'yes' === $this->get_option( 'test_mode', 'no' ) ? 'token_test_mode' : 'token';
|
|
$form_fields = $this->form_fields;
|
|
$this->form_fields = [];
|
|
foreach ( $form_fields as $field_name => $field ) {
|
|
$this->form_fields[ $field_name ] = $field;
|
|
if ( $field_name === $test_mode_after ) {
|
|
$this->form_fields['connection_status'] = [
|
|
'title' => __( 'Status połączenia', 'woocommerce-paczkomaty-inpost' ),
|
|
'type' => 'status',
|
|
'default' => '',
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function get_organizations() {
|
|
$organizations = array();
|
|
$shipX_cache = $this->get_shipX_cache();
|
|
if ( $shipX_cache ) {
|
|
try {
|
|
$organizations = $shipX_cache->get_organizations();
|
|
} catch ( Exception $e ) {
|
|
}
|
|
}
|
|
|
|
return $organizations;
|
|
}
|
|
|
|
/**
|
|
* @param array $organizations
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_organization_options( $organizations ) {
|
|
$organization_options = [ '' => __( '- Wybierz organizację -', 'woocommerce-paczkomaty-inpost' ) ];
|
|
foreach ( $organizations as $organization ) {
|
|
$organization_options[ $organization->id ] = $organization->name;
|
|
}
|
|
if ( empty( $organization_options ) && $this->get_option( 'organization_id' ) ) {
|
|
$organization_options[ $this->get_option( 'organization_id' ) ] = $this->get_option( 'organization_id' );
|
|
}
|
|
|
|
return $organization_options;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function get_services() {
|
|
$services = array();
|
|
$shipX = $this->get_shipX();
|
|
if ( $shipX ) {
|
|
try {
|
|
$services = $shipX->get_services();
|
|
} catch ( Exception $e ) {
|
|
error_log( print_r( $e->getMessage(), true ) );
|
|
}
|
|
}
|
|
|
|
return $services;
|
|
}
|
|
|
|
/**
|
|
* @param array $services
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_service_options( $services ) {
|
|
$service_options = array();
|
|
foreach ( $services as $service ) {
|
|
$service_options[ $service->id ] = $service->name;
|
|
}
|
|
|
|
return $service_options;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function get_sending_methods() {
|
|
$sending_methods = array();
|
|
$shipX = $this->get_shipX();
|
|
if ( ! $shipX ) {
|
|
$shipX = new WPDesk_Paczkomaty_ShipX( '', '' );
|
|
}
|
|
try {
|
|
$sending_methods = $shipX->get_sending_methods();
|
|
$sending_methods = $sending_methods->items;
|
|
} catch ( Exception $e ) {
|
|
error_log( print_r( $e->getMessage(), true ) );
|
|
}
|
|
|
|
return $sending_methods;
|
|
}
|
|
|
|
/**
|
|
* @param $sending_methods
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_sending_method_options( $sending_methods ) {
|
|
$sending_method_options = array();
|
|
foreach ( $sending_methods as $sending_method ) {
|
|
$sending_method_options[ $sending_method->id ] = $sending_method->name;
|
|
}
|
|
if ( count( $sending_method_options ) == 0 ) {
|
|
if ( $this->get_option( 'sending_method', '' ) ) {
|
|
$sending_method_options[ $this->get_option( 'sending_method' ) ] = $this->get_option( 'sending_method' );
|
|
}
|
|
}
|
|
|
|
return $sending_method_options;
|
|
}
|
|
|
|
/**
|
|
* Get points as options.
|
|
*
|
|
* @param array $points_types .
|
|
* @param bool $show_all_options Whether to return all options or only selected.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_points_options( $points_types = array( 'parcel_locker' ), $show_all_options = true ) {
|
|
$points_options = array();
|
|
$cache_options = self::$pickup_points_manager->get_points( $points_types );
|
|
|
|
if ( $option_name = $this->get_option( 'default_parcel_locker', '' ) ) {
|
|
$option_label = isset( $cache_options[ $option_name ] ) ? $cache_options[ $option_name ] : $option_name;
|
|
$points_options[ $option_name ] = $option_label;
|
|
}
|
|
|
|
if ( $option_name = $this->get_option( 'default_pop', '' ) ) {
|
|
$option_label = isset( $cache_options[ $option_name ] ) ? $cache_options[ $option_name ] : $option_name;
|
|
$points_options[ $option_name ] = $option_label;
|
|
}
|
|
|
|
if ( $show_all_options ) {
|
|
$points_options = array_merge( $points_options, $cache_options );
|
|
}
|
|
|
|
return $points_options;
|
|
}
|
|
|
|
/**
|
|
* @return bool|string
|
|
* @throws Exception
|
|
* @throws WPDesk_Paczkomaty_ShipX_Exception
|
|
*/
|
|
public function ping() {
|
|
$ping = false;
|
|
$shipX = $this->get_shipX();
|
|
if ( $shipX ) {
|
|
$shipX->ping();
|
|
$ping = true;
|
|
}
|
|
|
|
return $ping;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function get_auto_print_options() {
|
|
$auto_print_options = array();
|
|
$flexible_printing = apply_filters( 'flexible_printing', false );
|
|
|
|
$auto_print_description = '';
|
|
$auto_print_custom_attributes = array();
|
|
|
|
|
|
if ( $flexible_printing ) {
|
|
if ( $this->get_option( 'auto_print', '' ) == 'yes' ) {
|
|
$flexible_printing_integration_url = apply_filters( 'flexible_printing_integration_url', 'paczkomaty_shipping_method' );
|
|
$auto_print_description = sprintf( __( 'Aby przejść do ustawień wydruku kliknij %stutaj%s.', 'woocommerce-paczkomaty-inpost' ), '<a target="_blank" href="' . $flexible_printing_integration_url . '">', '</a>' );
|
|
} else {
|
|
$auto_print_description = __( 'Konfiguracja wydruku dostępna po włączeniu opcji i zapisaniu ustawień.', 'woocommerce-paczkomaty-inpost' );
|
|
}
|
|
} else {
|
|
$this->settings['auto_print'] = 'no';
|
|
$flexible_printing_buy_url = 'https://octol.io/inpost-printing-cross-pl';
|
|
$auto_print_description = sprintf(
|
|
__( 'Drukuj etykiety bezpośrednio na drukarce (bez pobierania pliku) lub zapisuj automatycznie na dysku. %sKup Flexible Printing →%s.', 'woocommerce-paczkomaty-inpost' ),
|
|
'<a href="' . $flexible_printing_buy_url . '" target="_blank">',
|
|
'</a>'
|
|
);
|
|
$auto_print_custom_attributes = array( 'disabled' => 'disabled' );
|
|
}
|
|
|
|
$auto_print_options['description'] = $auto_print_description;
|
|
$auto_print_options['custom_attributes'] = $auto_print_custom_attributes;
|
|
|
|
return $auto_print_options;
|
|
}
|
|
|
|
/**
|
|
* @param array $form_fields .
|
|
*
|
|
* @return array
|
|
*/
|
|
private function add_beacon_search_data_to_fields( array $form_fields ) {
|
|
foreach ( $form_fields as $field_name => $field ) {
|
|
|
|
if ( empty( $field['class'] ) ) {
|
|
$field['class'] = 'hs-beacon-search';
|
|
} else {
|
|
$field['class'] .= ' hs-beacon-search';
|
|
}
|
|
if ( isset( $field['title'] ) ) {
|
|
if ( ! isset( $field['custom_attributes'] ) ) {
|
|
$field['custom_attributes'] = array();
|
|
}
|
|
$field['custom_attributes']['data-beacon_search'] = $field['title'];
|
|
}
|
|
$form_fields[ $field_name ] = $field;
|
|
}
|
|
|
|
return $form_fields;
|
|
}
|
|
|
|
/**
|
|
* @param array $form_fields
|
|
* @param bool $echo
|
|
*
|
|
* @return string
|
|
*/
|
|
function generate_settings_html( $form_fields = array(), $echo = true ) {
|
|
|
|
$form_fields = $this->add_beacon_search_data_to_fields( $form_fields );
|
|
|
|
$punkty_nadania = array();
|
|
|
|
if ( $this->get_option( 'domyslny_punkt_nadania', '' ) != '' ) {
|
|
$punkty_nadania[ $this->get_option( 'domyslny_punkt_nadania', '' ) ] = $this->get_option( 'domyslny_punkt_nadania', '' );
|
|
}
|
|
|
|
if ( $this->get_parcel_lockers_api() === self::API_TYPE_XML ) {
|
|
$punkty_nadania = inpost_listmachines( 't' );
|
|
} else {
|
|
$punkty_nadania = self::$pickup_points_manager->get_points( WPDesk_Paczkomaty_ShipX_Cache::PARCEL_LOCKER_ONLY );
|
|
}
|
|
|
|
$connection_status = 'not_connected';
|
|
$connection_message = __( 'Brak połączenia.', 'woocommerce-paczkomaty-inpost' );
|
|
try {
|
|
$ping = $this->ping();
|
|
if ( $this->ping() ) {
|
|
$connection_status = 'connected';
|
|
$connection_message = __( 'OK', 'woocommerce-paczkomaty-inpost' );
|
|
}
|
|
} catch ( Exception $e ) {
|
|
$connection_message = $e->getMessage();
|
|
}
|
|
|
|
$organizations = $this->get_organizations();
|
|
$services = apply_filters( 'woocommerce_paczkomaty_inpost_shipX_services', $this->get_services() );
|
|
$sending_methods = $this->get_sending_methods();
|
|
$auto_print_options = $this->get_auto_print_options();
|
|
|
|
$parcel_locker_options = $this->get_points_options( WPDesk_Paczkomaty_ShipX_Cache::PARCEL_LOCKER, false );
|
|
|
|
$form_fields['dispatch_point']['options'] = [ '' => __( '-- Wybierz punkt odbioru --', 'woocommerce-paczkomaty-inpost' ) ];
|
|
try {
|
|
$form_fields['dispatch_point']['options'] += $this->get_shipX_cache()->get_dispatch_points_options();
|
|
} catch ( Exception $e ) {
|
|
$dispatch_point = $this->get_option( 'dispatch_point', '' );
|
|
if ( $dispatch_point !== '' ) {
|
|
$form_fields['dispatch_point']['options'] += [ $dispatch_point => $dispatch_point ];
|
|
}
|
|
}
|
|
$form_fields['dispatch_point']['options']['custom'] = __( 'Wprowadź ręcznie dane punktu', 'woocommerce-paczkomaty-inpost' );
|
|
$form_fields['organization_id']['options'] = $this->get_organization_options( $organizations );
|
|
if ( count( $form_fields['organization_id']['options'] ) > 1 ) {
|
|
$form_fields['organization_id']['custom_attributes'] = [ 'required' => 'required' ];
|
|
}
|
|
$form_fields['services']['options'] = apply_filters( 'woocommerce_paczkomaty_inpost_shipX_services_options', $this->get_service_options( $services ) );
|
|
$form_fields['sending_method']['options'] = apply_filters( 'woocommerce_paczkomaty_inpost_shipX_sending_methods_options', $this->get_sending_method_options( $sending_methods ) );
|
|
$form_fields['default_parcel_locker']['options'] = $parcel_locker_options;
|
|
$form_fields['auto_print']['description'] = $auto_print_options['description'];
|
|
$form_fields['auto_print']['custom_attributes'] = $auto_print_options['custom_attributes'];
|
|
|
|
if ( empty( $this->settings['kurier_webhook_token'] ) ) {
|
|
$this->settings['kurier_webhook_token'] = md5( site_url() );
|
|
}
|
|
$this->settings['kurier_webhook_url'] = site_url( '?shipx_webhook=' . $this->settings['kurier_webhook_token'] );
|
|
|
|
$html = '';
|
|
ob_start();
|
|
include( 'views/settings-script.php' );
|
|
$html = ob_get_clean();
|
|
|
|
if ( $echo ) {
|
|
echo $html;
|
|
parent::generate_settings_html( $form_fields, $echo );
|
|
} else {
|
|
return $html . parent::generate_settings_html( $form_fields, $echo );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array $key
|
|
* @param array $data
|
|
*
|
|
* @return string
|
|
*/
|
|
public function generate_services_html( $key, $data ) {
|
|
$field_key = $this->get_field_key( $key );
|
|
$defaults = array(
|
|
'title' => '',
|
|
'disabled' => false,
|
|
'class' => '',
|
|
'css' => '',
|
|
'placeholder' => '',
|
|
'type' => 'text',
|
|
'desc_tip' => false,
|
|
'description' => '',
|
|
'custom_attributes' => array(),
|
|
);
|
|
$data = wp_parse_args( $data, $defaults );
|
|
ob_start();
|
|
?>
|
|
<tr valign="top">
|
|
<th scope="row" class="titledesc">
|
|
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?>
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
</label>
|
|
</th>
|
|
<td class="forminp" id="shipX_services">
|
|
<span class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>"
|
|
id="<?php echo esc_attr( $field_key ); ?>">
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* @param array $key
|
|
* @param array $data
|
|
*
|
|
* @return string
|
|
*/
|
|
public function generate_status_html( $key, $data ) {
|
|
$field_key = $this->get_field_key( $key );
|
|
$defaults = array(
|
|
'title' => '',
|
|
'disabled' => false,
|
|
'class' => '',
|
|
'css' => '',
|
|
'placeholder' => '',
|
|
'type' => 'text',
|
|
'desc_tip' => false,
|
|
'description' => '',
|
|
'custom_attributes' => array(),
|
|
);
|
|
$data = wp_parse_args( $data, $defaults );
|
|
ob_start();
|
|
?>
|
|
<tr valign="top">
|
|
<th scope="row" class="titledesc">
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
<label for="<?php echo esc_attr( $field_key ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
</th>
|
|
<td class="forminp">
|
|
<span class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>"
|
|
id="<?php echo esc_attr( $field_key ); ?>">
|
|
</span>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function get_parcel_lockers_api() {
|
|
$parcel_lockers_api = self::API_TYPE_SHIPX;
|
|
if ( $this->get_option( 'paczkomaty', 'no' ) == 'yes' ) {
|
|
$parcel_lockers_api = self::API_TYPE_XML;
|
|
}
|
|
|
|
return $parcel_lockers_api;
|
|
}
|
|
|
|
/**
|
|
* @param array $package
|
|
*/
|
|
public function calculate_shipping( $package = array() ) {
|
|
}
|
|
|
|
}
|
|
|
|
}
|