public function init_form_fields() { global $woocommerce; parent::init_form_fields(); // ************************************************************************* // Free Shipping // ************************************************************************* // $this->form_fields['free_shipping_title'] = [ // 'type' => 'title', // 'title' => __( 'Free Shipping', 'bring-fraktguiden' ), // ]; // $this->form_fields['free_shipping_settings'] = [ // 'type' => 'checkbox', // 'title' => '', // 'description' => $description, // ]; // $this->form_fields['services'] = array('type' => 'services_table'); // ************************************************************************* // Pickup Point // ************************************************************************* $this->form_fields['pickup_point_title'] = ['type' => 'title', 'title' => __('Pickup Point Options', 'bring-fraktguiden')]; $this->form_fields['pickup_point_enabled'] = ['title' => __('Enable', 'bring-fraktguiden'), 'type' => 'checkbox', 'label' => __('Enable pickup point', 'bring-fraktguiden'), 'default' => 'no']; $this->form_fields['pickup_point_required'] = ['title' => __('Required', 'bring-fraktguiden'), 'type' => 'checkbox', 'label' => __('Make pickup point required on checkout', 'bring-fraktguiden'), 'default' => 'no']; // ************************************************************************* // MyBring // ************************************************************************* $has_api_uid_and_key = Fraktguiden_Helper::get_option('mybring_api_uid') && Fraktguiden_Helper::get_option('mybring_api_key'); $description = sprintf(__('In order to use Bring Booking you must be registered in <a href="%s" target="_blank">MyBring</a> and have an invoice agreement with Bring', 'bring-fraktguiden'), 'http://mybring.com/'); if (!$has_api_uid_and_key) { $description .= '<p style="font-weight: bold;color: red">' . __('API User ID or API Key missing!', 'bring-fraktguiden') . '</p>'; } $this->form_fields['mybring_title'] = ['title' => __('MyBring Account', 'bring-fraktguiden'), 'description' => $description, 'type' => 'title']; $this->form_fields['mybring_api_uid'] = ['title' => __('API User ID', 'bring-fraktguiden'), 'type' => 'text', 'label' => __('API User ID', 'bring-fraktguiden')]; $this->form_fields['mybring_api_key'] = ['title' => __('API Key', 'bring-fraktguiden'), 'type' => 'text', 'label' => __('API Key', 'bring-fraktguiden')]; // ************************************************************************* // Booking // ************************************************************************* $this->form_fields['booking_point_title'] = ['title' => __('Booking Options', 'bring-fraktguiden'), 'type' => 'title']; $this->form_fields['booking_enabled'] = ['title' => __('Enable', 'bring-fraktguiden'), 'type' => 'checkbox', 'label' => __('Enable booking', 'bring-fraktguiden'), 'default' => 'no']; $this->form_fields['booking_test_mode_enabled'] = ['title' => __('Testing', 'bring-fraktguiden'), 'type' => 'checkbox', 'label' => __('Test mode', 'bring-fraktguiden'), 'description' => __('For testing. Bookings will not be invoiced', 'bring-fraktguiden'), 'default' => 'yes']; $this->form_fields['booking_address_store_name'] = ['title' => __('Store Name', 'bring-fraktguiden'), 'type' => 'text', 'default' => get_bloginfo('name')]; $this->form_fields['booking_address_street1'] = ['title' => __('Street Address 1', 'bring-fraktguiden'), 'type' => 'text']; $this->form_fields['booking_address_street2'] = ['title' => __('Street Address 2', 'bring-fraktguiden'), 'type' => 'text']; $this->form_fields['booking_address_postcode'] = ['title' => __('Postcode', 'bring-fraktguiden'), 'type' => 'text']; $this->form_fields['booking_address_city'] = ['title' => __('City', 'bring-fraktguiden'), 'type' => 'text']; $this->form_fields['booking_address_country'] = ['title' => __('Country', 'bring-fraktguiden'), 'type' => 'select', 'class' => 'chosen_select', 'css' => 'width: 450px;', 'default' => $woocommerce->countries->get_base_country(), 'options' => $woocommerce->countries->countries]; $this->form_fields['booking_address_contact_person'] = ['title' => __('Contact Person', 'bring-fraktguiden'), 'type' => 'text']; $this->form_fields['booking_address_phone'] = ['title' => __('Phone', 'bring-fraktguiden'), 'type' => 'text']; $this->form_fields['booking_address_email'] = ['title' => __('Email', 'bring-fraktguiden'), 'type' => 'text']; $this->form_fields['auto_set_status_after_booking_success'] = ['title' => __('Order status after booking', 'bring-fraktguiden'), 'type' => 'select', 'description' => __('Order status to automatically set after successful booking', 'bring-fraktguiden'), 'class' => 'chosen_select', 'css' => 'width: 450px;', 'options' => array('none' => __('None', 'bring-fraktguiden')) + wc_get_order_statuses(), 'default' => 'none']; }
static function get_all_selected_services() { $selected_service_name = Fraktguiden_Helper::get_option('service_name'); $service_name = $selected_service_name ? $selected_service_name : 'ProductName'; $services = self::get_services_data(); $selected = self::get_option('services'); $result = []; foreach ($services as $key => $service) { if (in_array($key, $selected)) { $result[$key] = $service[$service_name]; } } return $result; }
/** * @param Bring_WC_Order_Adapter $order */ static function render_packages($order) { $shipping_item_tip = __('Shipping item id', 'bring-fraktguiden'); ?> <table class="bring-booking-packages"> <thead> <tr> <th title="<?php echo $shipping_item_tip; ?> "><?php _e('#', 'bring-fraktguiden'); ?> </th> <th><?php _e('Product', 'bring-fraktguiden'); ?> </th> <th><?php _e('Width', 'bring-fraktguiden'); ?> (cm)</th> <th><?php _e('Height', 'bring-fraktguiden'); ?> (cm)</th> <th><?php _e('Length', 'bring-fraktguiden'); ?> (cm)</th> <th><?php _e('Weight', 'bring-fraktguiden'); ?> (kg)</th> </tr> </thead> <tbody> <?php foreach ($order->get_packages_formatted(false, true) as $key => $package) { ?> <?php $shipping_item_id = $package['shipping_item_info']['item_id']; $service_data = Fraktguiden_Helper::get_service_data_for_key($package['shipping_item_info']['shipping_method']['service']); ?> <tr> <td title="<?php echo $shipping_item_tip; ?> "> <?php echo $shipping_item_id; ?> </td> <td> <?php echo $service_data[Fraktguiden_Helper::get_option('service_name')]; ?> <?php $pickup_point = $order->get_pickup_point_for_shipping_item($shipping_item_id); if (!empty($pickup_point)) { ?> <span class="tips" data-tip="<?php echo str_replace('|', '<br/>', $pickup_point['cached']); ?> "> [<?php _e('Pickup Point', 'bring-fraktguiden'); ?> ] </span> <?php } ?> </td> <td> <?php echo $package['dimensions']['widthInCm']; ?> </td> <td> <?php echo $package['dimensions']['heightInCm']; ?> </td> <td> <?php echo $package['dimensions']['lengthInCm']; ?> </td> <td> <?php echo $package['weightInKg']; ?> </td> </tr> <?php } ?> </tbody> </table> <?php }
/** * Prints rate json for a bring service. * * Only available from admin. * @todo: refactor!! */ static function wp_ajax_get_rate() { header('Content-type: application/json'); $result = ['success' => false, 'rate' => null, 'packages' => null]; if (isset($_GET['post_id']) && isset($_GET['service'])) { $order = new WC_Order($_GET['post_id']); $items = $order->get_items(); $fake_cart = []; foreach ($items as $item) { $fake_cart[uniqid()] = ['quantity' => $item['qty'], 'data' => new WC_Product_Simple($item['product_id'])]; } //include( '../../common/class-fraktguiden-packer.php' ); $packer = new Fraktguiden_Packer(); $product_boxes = $packer->create_boxes($fake_cart); $packer->pack($product_boxes, true); $package_params = $packer->create_packages_params(); //@todo: share / filter $standard_params = array('clientUrl' => $_SERVER['HTTP_HOST'], 'from' => Fraktguiden_Helper::get_option('from_zip'), 'fromCountry' => Fraktguiden_Helper::get_option('from_country'), 'to' => $order->shipping_postcode, 'toCountry' => $order->shipping_country, 'postingAtPostOffice' => Fraktguiden_Helper::get_option('post_office') == 'no' ? 'false' : 'true', 'additional' => Fraktguiden_Helper::get_option('evarsling') == 'yes' ? 'evarsling' : ''); $params = array_merge($standard_params, $package_params); $url = add_query_arg($params, WC_Shipping_Method_Bring::SERVICE_URL); $url .= '&product=' . $_GET['service']; // Make the request. $request = new WP_Bring_Request(); $response = $request->get($url); if ($response->status_code == 200) { $json = json_decode($response->get_body(), true); $service = $json['Product']['Price']['PackagePriceWithoutAdditionalServices']; $rate = Fraktguiden_Helper::get_option('vat') == 'exclude' ? $service['AmountWithoutVAT'] : $service['AmountWithVAT']; $result['success'] = true; $result['rate'] = $rate; $result['packages'] = json_encode($package_params); } } echo json_encode($result); die; }
/** * @param string $additional_info * @return array */ static function get_sender_address($additional_info = '') { $form_fields = ['booking_address_store_name', 'booking_address_street1', 'booking_address_street2', 'booking_address_postcode', 'booking_address_city', 'booking_address_country', 'booking_address_contact_person', 'booking_address_phone', 'booking_address_email']; $result = []; foreach ($form_fields as $field) { $result[$field] = Fraktguiden_Helper::get_option($field); } return ["name" => $result['booking_address_store_name'], "addressLine" => $result['booking_address_street1'], "addressLine2" => $result['booking_address_street2'], "postalCode" => $result['booking_address_postcode'], "city" => $result['booking_address_city'], "countryCode" => $result['booking_address_country'], "reference" => null, "additionalAddressInfo" => $additional_info, "contact" => ["name" => $result['booking_address_contact_person'], "email" => $result['booking_address_email'], "phoneNumber" => $result['booking_address_phone']]]; }