first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
.flexible-shipping-log button.hide {
display: none;
}
.flexible-shipping-log pre {
display: none;
}

View File

@@ -0,0 +1,39 @@
jQuery( document ).ready( function () {
jQuery( document ).on( 'click', '.flexible-shipping-log>button.show', function(event){
event.preventDefault();
let $parent = jQuery(this).parent();
$parent.find('.hide').show();
$parent.find('pre').show();
jQuery(this).hide();
});
jQuery( document ).on( 'click', '.flexible-shipping-log>button.hide', function(event){
event.preventDefault();
let $parent = jQuery(this).parent();
$parent.find('.show').show();
$parent.find('pre').hide();
jQuery(this).hide();
});
jQuery( document ).on( 'click', '.flexible-shipping-log>button.clipboard', function(event){
event.preventDefault();
let $temp = jQuery("<textarea>");
jQuery('body').append( $temp );
$temp.val(jQuery(this).parent().find('pre').text()).select();
document.execCommand('copy');
$temp.remove();
});
jQuery( document ).on( 'click', 'button.flexible-shipping-log-clipboard-all', function(event){
event.preventDefault();
let $temp = jQuery("<textarea>");
jQuery('body').append( $temp );
jQuery(this).parent().find('.flexible-shipping-log').find('pre').each(function(){
$temp.val( $temp.val() + "\n\n" + jQuery( this ).text() );
});
$temp.select();
document.execCommand('copy');
$temp.remove();
});
});

View File

@@ -0,0 +1,43 @@
{
"name": "wpdesk\/wp-wpdesk-fs-table-rate",
"authors": [
{
"name": "Krzysiek",
"email": "krzysiek@wpdesk.pl"
},
{
"name": "Grzegorz",
"email": "grzegorz@wpdesk.net"
}
],
"require": {
"php": ">=7.2",
"wpdesk\/wp-view": "^1.1|^2.0.0",
"psr\/log": "^1.1|2|3",
"wpdesk\/wp-builder": "^2.0"
},
"require-dev": {
"phpunit\/phpunit": "*",
"mockery\/mockery": "*",
"10up\/wp_mock": "*"
},
"autoload": {
"psr-4": {
"FSVendor\\WPDesk\\FS\\TableRate\\": "src\/"
}
},
"autoload-dev": {},
"extra": {
"text-domain": "wp-wpdesk-fs-table-rate",
"translations-folder": "lang",
"po-files": {
"pl_PL": "pl_PL.po"
}
},
"scripts": {
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
"phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
"phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage"
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Based on options.
*
* @package WPDesk\FS\TableRate
*/
namespace FSVendor\WPDesk\FS\TableRate;
/**
* Can provide options.
*/
abstract class AbstractOptions
{
/**
* @return array
*/
public abstract function get_options();
/**
* @param $option_value
*
* @return string
*/
public function get_option_label($option_value)
{
$options = $this->get_options();
return isset($options[$option_value]) ? $options[$option_value] : $option_value;
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Based on options.
*
* @package WPDesk\FS\TableRate
*/
namespace FSVendor\WPDesk\FS\TableRate;
/**
* Can provide Based On options.
*/
class BasedOnOptions extends \FSVendor\WPDesk\FS\TableRate\AbstractOptions
{
/**
* @return array
*/
public function get_options()
{
return \apply_filters('flexible_shipping_method_rule_options_based_on', array('none' => \__('None', 'flexible-shipping'), 'value' => \__('Price', 'flexible-shipping'), 'weight' => \__('Weight', 'flexible-shipping')));
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* Class CartCalculationOptions
*
* @package WPDesk\FSPro\TableRate
*/
namespace FSVendor\WPDesk\FS\TableRate;
/**
* Can provide calculation method options.
*/
class CalculationMethodOptions extends \FSVendor\WPDesk\FS\TableRate\AbstractOptions
{
/**
* @return array
*/
public function get_options()
{
return array('sum' => \__('Sum', 'flexible-shipping'));
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Array logger.
*
* @package WPDesk\FS\TableRate\Logger
*/
namespace FSVendor\WPDesk\FS\TableRate\Logger;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
use FSVendor\WPDesk\View\Renderer\SimplePhpRenderer;
use FSVendor\WPDesk\View\Resolver\ChainResolver;
use FSVendor\WPDesk\View\Resolver\DirResolver;
/**
* Can log to array.
*/
class ArrayLogger implements \Psr\Log\LoggerInterface
{
use LoggerTrait;
/**
* @var array
*/
private $messages = array();
/**
* @param mixed $level .
* @param string $message .
* @param array $context .
*/
public function log($level, $message, array $context = array()) : void
{
$this->messages[] = array('level' => $level, 'message' => $message, 'context' => $context);
}
/**
* @return array
*/
public function get_messages()
{
return $this->messages;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Class Assets
* @package WPDesk\FS\TableRate\Logger
*/
namespace FSVendor\WPDesk\FS\TableRate\Logger;
use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Can enqueue assets.
*/
class Assets implements \FSVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
const HANDLE = 'flexible_shipping_notices';
private $assets_url;
private $scripts_version;
/**
* Assets constructor.
*
* @param $assets_url
* @param $scripts_version
*/
public function __construct($assets_url, $scripts_version)
{
$this->assets_url = $assets_url;
$this->scripts_version = $scripts_version;
}
/**
* Hooks.
*/
public function hooks()
{
\add_action('wp_enqueue_scripts', array($this, 'enqueue_assets'));
}
/**
* Enqueue assets.
*
* @internal
*/
public function enqueue_assets()
{
if (\current_user_can('manage_woocommerce')) {
\wp_register_script(self::HANDLE, \trailingslashit($this->assets_url) . 'js/notices.js', array('jquery'), $this->scripts_version, \true);
\wp_enqueue_script(self::HANDLE);
\wp_register_style(self::HANDLE, \trailingslashit($this->assets_url) . 'css/notices.css', array(), $this->scripts_version);
\wp_enqueue_style(self::HANDLE);
}
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* Interface CanFormatForLog
* @package WPDesk\FS\TableRate\Logger
*/
namespace FSVendor\WPDesk\FS\TableRate\Logger;
/**
* Can format for log.
*/
interface CanFormatForLog
{
/**
* @return string
*/
public function format_for_log();
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* Notice logger.
*
* @package WPDesk\FS\TableRate\Logger
*/
namespace FSVendor\WPDesk\FS\TableRate\Logger;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
use FSVendor\WPDesk\View\Renderer\SimplePhpRenderer;
use FSVendor\WPDesk\View\Resolver\ChainResolver;
use FSVendor\WPDesk\View\Resolver\DirResolver;
/**
* Can log to WC Notice.
*/
class NoticeLogger implements \Psr\Log\LoggerInterface
{
use LoggerTrait;
/**
* @var array
*/
private $messages = array();
/**
* @var bool
*/
private $notice_enabled;
/**
* @var string
*/
private $shipping_method_title;
/**
* @var string
*/
private $shipping_method_url;
/**
* NoticeLogger constructor.
*
* @param string $shipping_method_title .
* @param string $shipping_method_url .
* @param bool $notice_enabled .
*/
public function __construct($shipping_method_title, $shipping_method_url, $notice_enabled)
{
$this->notice_enabled = $notice_enabled;
$this->shipping_method_url = $shipping_method_url;
$this->shipping_method_title = $shipping_method_title;
}
/**
* @param mixed $level .
* @param string $message .
* @param array $context .
*/
public function log($level, $message, array $context = array()) : void
{
if ($this->notice_enabled) {
if (isset($context['section'])) {
$context = $context['section'];
if (!isset($this->messages[$context])) {
$this->messages[$context] = array();
}
$this->messages[$context][] = array('level' => $level, 'message' => $message, 'context' => $context);
}
}
}
/**
* Show notice if logger is enabled.
*/
public function show_notice_if_enabled()
{
if ($this->notice_enabled && \count($this->messages)) {
$content = $this->prepare_notice_content();
if (!\wc_has_notice($content, 'notice')) {
\wc_add_notice($content, 'notice');
/**
* Do actions when Flexible Shipping debug notice is added.
*
* @param string $content Notice content.
*/
\do_action('flexible_shipping_debug_notice_added', $content);
}
}
}
/**
* Prepare notice content.
*
* @return string
*/
private function prepare_notice_content()
{
$renderer = new \FSVendor\WPDesk\View\Renderer\SimplePhpRenderer(new \FSVendor\WPDesk\View\Resolver\DirResolver(__DIR__ . '/view'));
$content = $renderer->render('display-notice-header', array('shipping_method_url' => $this->shipping_method_url, 'shipping_method_title' => $this->shipping_method_title));
foreach ($this->messages as $section => $section_messages) {
$section_content = $this->prepare_content_from_section_messages($section_messages);
$content .= $renderer->render('display-notice-content-single-value', array('section' => $section, 'section_content' => $section_content));
}
$content .= $renderer->render('display-notice-footer');
return $content;
}
/**
* @param array $section_messages .
*
* @return string
*/
private function prepare_content_from_section_messages(array $section_messages)
{
$content = '';
foreach ($section_messages as $message) {
$content .= $message['message'] . \PHP_EOL;
}
return \trim($content);
}
}

View File

@@ -0,0 +1,94 @@
<?php
/**
* Shipping method logger.
*
* @package WPDesk\FS\TableRate\Logger
*/
namespace FSVendor\WPDesk\FS\TableRate\Logger;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
/**
* Can log shipping method messages.
*/
class ShippingMethodLogger implements \Psr\Log\LoggerInterface
{
use LoggerTrait;
/**
* @var LoggerInterface
*/
private $fs_logger;
/**
* @var LoggerInterface
*/
private $notice_logger;
/**
* ShippingMethodLogger constructor.
*
* @param LoggerInterface $fs_logger
* @param NoticeLogger $notice_logger
*/
public function __construct(\Psr\Log\LoggerInterface $fs_logger, \Psr\Log\LoggerInterface $notice_logger)
{
$this->fs_logger = $fs_logger;
$this->notice_logger = $notice_logger;
}
/**
* @param mixed $level .
* @param string $message .
* @param array $context .
*/
public function log($level, $message, array $context = array()) : void
{
$this->fs_logger->log($level, $message, $context);
$this->notice_logger->log($level, $message, $context);
}
/**
* Log entries from array logger.
*
* @param ArrayLogger $array_logger
* @param array $context
*/
public function log_from_array_logger(\FSVendor\WPDesk\FS\TableRate\Logger\ArrayLogger $array_logger, array $context = array())
{
foreach ($array_logger->get_messages() as $message) {
$this->log($message['level'], $message['message'], \array_merge($message['context'], $context));
}
}
/**
* Show notice if enabled.
*/
public function show_notice_if_enabled()
{
$this->notice_logger->show_notice_if_enabled();
}
/**
* @return array
*/
public function get_configuration_section_context()
{
return array('section' => \__('shipping method configuration', 'flexible-shipping'));
}
/**
* @return array
*/
public function get_input_data_context()
{
return array('section' => \__('input data', 'flexible-shipping'));
}
/**
* @return array
*/
public function get_rule_context($rule_triggered)
{
return array('section' => \sprintf(\__('rules (%1$s)', 'flexible-shipping'), $rule_triggered ? \__('triggered', 'flexible-shipping') : \__('not triggered', 'flexible-shipping')));
}
/**
* @return array
*/
public function get_results_context()
{
return array('section' => \__('the result of shipping method\'s usage', 'flexible-shipping'));
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace FSVendor;
/**
* @var string $section
* @var string $section_content
*/
?><br/>
<div class="flexible-shipping-log">
<button class="small show"><?php
echo \sprintf(\__('Show %1$s', 'flexible-shipping'), $section);
?></button>
<button class="small hide"><?php
echo \sprintf(\__('Hide %1$s', 'flexible-shipping'), $section);
?></button>
<button class="small clipboard"><?php
echo \sprintf(\__('Copy %1$s', 'flexible-shipping'), $section);
?></button>
<pre><?php
echo \esc_html($section_content);
?> </pre>
</div><?php

View File

@@ -0,0 +1,10 @@
<?php
namespace FSVendor;
/**
*
*/
?><br/><button class="small flexible-shipping-log-clipboard-all"><?php
echo \esc_html(\__('Copy all data', 'flexible-shipping'));
?></button><?php

View File

@@ -0,0 +1,11 @@
<?php
namespace FSVendor;
/**
* @var string $shipping_method_url
* @var string $shipping_method_title
*/
echo \sprintf(\__('FS Debug mode for %1$s%2$s%3$s shipping method.', 'flexible-shipping'), '<a href="' . \esc_attr($shipping_method_url) . '" target="_blank">', \esc_html($shipping_method_title), '</a>');
?><br/>
<?php

View File

@@ -0,0 +1,25 @@
<?php
/**
* Class CartCalculationOptions
*
* @package WPDesk\FS\TableRate\Settings
*/
namespace FSVendor\WPDesk\FS\TableRate\Settings;
use FSVendor\WPDesk\FS\TableRate\AbstractOptions;
/**
* Can provide cart calculation options.
*/
class CartCalculationOptions extends \FSVendor\WPDesk\FS\TableRate\AbstractOptions
{
const CART = 'cart';
const PACKAGE = 'package';
/**
* @return array
*/
public function get_options()
{
return array(self::CART => \__('Cart value', 'flexible-shipping'), self::PACKAGE => \__('Package value', 'flexible-shipping'));
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Trait CheckboxValue
*
* @package WPDesk\FS\TableRate\Settings
*/
namespace FSVendor\WPDesk\FS\TableRate\Settings;
/**
* Checkbox value methods.
*/
trait CheckboxValue
{
/**
* @param $checkbox_value
*
* @return string
*/
protected function get_as_translated_checkbox_value($checkbox_value)
{
if (\in_array($checkbox_value, array('yes', 'no'))) {
return 'yes' === $checkbox_value ? \__('yes', 'flexible-shipping') : \__('no', 'flexible-shipping');
}
return $checkbox_value;
}
}

View File

@@ -0,0 +1,16 @@
<?php
/**
* Integration settings.
*
* @package WPDesk\FS\TableRate\Settings
*/
namespace FSVendor\WPDesk\FS\TableRate\Settings;
/**
* FS Integration settings on shipping method.
*/
interface IntegrationSettings
{
public function get_name();
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Integration settings Factory.
*
* @package WPDesk\FS\TableRate\Settings
*/
namespace FSVendor\WPDesk\FS\TableRate\Settings;
/**
* Can create Integration settings.
*/
class IntegrationSettingsFactory
{
const INTEGRATION_NONE = 'none';
/**
* @param array $shipping_method_array
*
* @return IntegrationSettingsImplementation
*/
public static function create_from_shipping_method_settings($shipping_method_array)
{
return new \FSVendor\WPDesk\FS\TableRate\Settings\IntegrationSettingsImplementation(isset($shipping_method_array['method_integration']) ? $shipping_method_array['method_integration'] : self::INTEGRATION_NONE);
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Class IntegrationSettingsImplementation
* @package WPDesk\FS\TableRate\Settings
*/
namespace FSVendor\WPDesk\FS\TableRate\Settings;
use FSVendor\WPDesk\FS\TableRate\Logger\CanFormatForLog;
/**
* Integration settings implementation.
*/
class IntegrationSettingsImplementation implements \FSVendor\WPDesk\FS\TableRate\Settings\IntegrationSettings, \FSVendor\WPDesk\FS\TableRate\Logger\CanFormatForLog
{
/**
* @var string
*/
private $name;
/**
* IntegrationSettingsImplementation constructor.
*
* @param string $name
*/
public function __construct($name)
{
$this->name = $name;
}
/**
* @return string
*/
public function get_name()
{
return $this->name;
}
/**
* @return string
*/
public function format_for_log()
{
$integrations_options = \apply_filters('flexible_shipping_integration_options', array('' => \__('None', 'flexible-shipping')));
return \sprintf(\__('Integration: %1$s', 'flexible-shipping'), isset($integrations_options[$this->name]) ? $integrations_options[$this->name] : $this->name) . "\n";
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* Method settings.
* @package WPDesk\FS\TableRate\Settings
*/
namespace FSVendor\WPDesk\FS\TableRate\Settings;
/**
* FS Shipping method settings.
*/
interface MethodSettings
{
/**
* @return array
*/
public function get_raw_settings();
/**
* @return string
*/
public function get_id();
/**
* @return string
*/
public function get_enabled();
/**
* @return string
*/
public function get_title();
/**
* @return string
*/
public function get_description();
/**
* @return string
*/
public function get_free_shipping();
/**
* @return string
*/
public function get_free_shipping_label();
/**
* @return string
*/
public function get_free_shipping_cart_notice();
/**
* @return string
*/
public function get_calculation_method();
/**
* @return string
* @deprecated
*/
public function get_visible();
/**
* @return string
*/
public function get_visibility();
/**
* @return string
*/
public function get_default();
/**
* @return string
*/
public function get_debug_mode();
/**
* @return string
*/
public function get_integration();
/**
* @return IntegrationSettings|null
*/
public function get_integration_settings();
/**
* @return array
*/
public function get_rules_settings();
/**
* @return string
*/
public function get_tax_status();
/**
* @return string
*/
public function get_prices_include_tax();
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* Method Factory.
*
* @package WPDesk\FS\TableRate\Settings
*/
namespace FSVendor\WPDesk\FS\TableRate\Settings;
use FSVendor\WPDesk\FS\Helpers\ShippingMethod;
/**
* Can create Method.
*/
class MethodSettingsFactory
{
const FIELD_METHOD_FREE_SHIPPING = 'method_free_shipping';
/**
* @param array $shipping_method_array
* @param bool $method_default_disable Should disable method_default_setting?
*
* @return MethodSettings
*/
public static function create_from_array($shipping_method_array, $method_default_disable = \true)
{
$shipping_method_array = self::clean_settings($shipping_method_array);
$method_default = isset($shipping_method_array['method_default']) ? $shipping_method_array['method_default'] : 'no';
$method_default = $method_default_disable ? 'no' : $method_default;
return new \FSVendor\WPDesk\FS\TableRate\Settings\MethodSettingsImplementation($shipping_method_array, isset($shipping_method_array['id']) ? $shipping_method_array['id'] : 'no', isset($shipping_method_array['method_enabled']) ? $shipping_method_array['method_enabled'] : 'yes', isset($shipping_method_array['method_title']) ? $shipping_method_array['method_title'] : '', isset($shipping_method_array['method_description']) ? $shipping_method_array['method_description'] : '', isset($shipping_method_array['tax_status']) ? $shipping_method_array['tax_status'] : '', isset($shipping_method_array['prices_include_tax']) ? $shipping_method_array['prices_include_tax'] : 'no', isset($shipping_method_array['method_free_shipping']) ? $shipping_method_array['method_free_shipping'] : '', isset($shipping_method_array['method_free_shipping_label']) ? $shipping_method_array['method_free_shipping_label'] : '', isset($shipping_method_array['method_free_shipping_cart_notice']) ? $shipping_method_array['method_free_shipping_cart_notice'] : 'no', isset($shipping_method_array['method_calculation_method']) ? $shipping_method_array['method_calculation_method'] : 'sum', isset($shipping_method_array['cart_calculation']) ? $shipping_method_array['cart_calculation'] : 'cart', isset($shipping_method_array['method_visibility']) ? $shipping_method_array['method_visibility'] : 'no', $method_default, isset($shipping_method_array['method_debug_mode']) ? $shipping_method_array['method_debug_mode'] : 'no', isset($shipping_method_array['method_integration']) ? $shipping_method_array['method_integration'] : 'no', \FSVendor\WPDesk\FS\TableRate\Settings\IntegrationSettingsFactory::create_from_shipping_method_settings($shipping_method_array), isset($shipping_method_array['method_rules']) ? $shipping_method_array['method_rules'] : array());
}
/**
* @param array $shipping_method_array
*
* @return MethodSettings
*/
public static function create_from_array_and_tax_status($shipping_method_array, $tax_status)
{
$shipping_method_array['tax_status'] = $tax_status;
return self::create_from_array($shipping_method_array, \false);
}
/**
* If free shipping is 0 (zero) should get same results as empty value.
*
* @see https://trello.com/c/UNGnC093/3048-flexible-shipping-307-co%C5%9B-popsu%C5%82o
*
* @param array $shipping_method_array .
*
* @return array
*/
private static function clean_settings(array $shipping_method_array)
{
if (!isset($shipping_method_array[self::FIELD_METHOD_FREE_SHIPPING]) || '0' === \trim($shipping_method_array[self::FIELD_METHOD_FREE_SHIPPING])) {
$shipping_method_array[self::FIELD_METHOD_FREE_SHIPPING] = '';
}
return $shipping_method_array;
}
}

View File

@@ -0,0 +1,282 @@
<?php
/**
* Method Settings Implementation.
*
* @package WPDesk\FS\TableRate\Settings
*/
namespace FSVendor\WPDesk\FS\TableRate\Settings;
use FSVendor\WPDesk\FS\TableRate\CalculationMethodOptions;
use FSVendor\WPDesk\FS\TableRate\Logger\CanFormatForLog;
/**
* Class MethodSettingsImplementation
*/
class MethodSettingsImplementation implements \FSVendor\WPDesk\FS\TableRate\Settings\MethodSettings, \FSVendor\WPDesk\FS\TableRate\Logger\CanFormatForLog
{
use CheckboxValue;
/**
* @var array
*/
private $raw_settings;
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $enabled;
/**
* @var string
*/
private $title;
/**
* @var string
*/
private $description;
/**
* @var float
*/
private $free_shipping;
/**
* @var string
*/
private $free_shipping_label;
/**
* @var bool
*/
private $free_shipping_cart_notice;
/**
* @var string
*/
private $calculation_method;
/**
* @var string
*/
private $cart_calculation;
/**
* @var bool
*/
private $visibility;
/**
* @var bool
*/
private $default;
/**
* @var bool
*/
private $debug_mode;
/**
* @var string
*/
private $integration;
/**
* @var IntegrationSettingsImplementation
*/
private $integration_settings;
/**
* @var RuleSettings[]
*/
private $rules_settings;
/**
* @var string
*/
private $tax_status;
/**
* @var string
*/
private $prices_include_tax;
/**
* MethodSettingsImplementation constructor.
*
* @param array $raw_settings
* @param string $id
* @param string $enabled
* @param string $title
* @param string $description
* @param string $tax_status
* @param string $prices_include_tax
* @param string $free_shipping
* @param string $free_shipping_label
* @param string $free_shipping_cart_notice
* @param string $calculation_method
* @param string $cart_calculation
* @param string $visibility
* @param string $default
* @param string $debug_mode
* @param string $integration
* @param IntegrationSettingsImplementation $integration_settings
* @param array $rules_settings
*/
public function __construct(array $raw_settings, $id, $enabled, $title, $description, $tax_status, $prices_include_tax, $free_shipping, $free_shipping_label, $free_shipping_cart_notice, $calculation_method, $cart_calculation, $visibility, $default, $debug_mode, $integration, \FSVendor\WPDesk\FS\TableRate\Settings\IntegrationSettingsImplementation $integration_settings, array $rules_settings)
{
$this->raw_settings = $raw_settings;
$this->id = $id;
$this->enabled = $enabled;
$this->title = $title;
$this->description = $description;
$this->tax_status = $tax_status;
$this->prices_include_tax = $prices_include_tax;
$this->free_shipping = $free_shipping;
$this->free_shipping_label = $free_shipping_label;
$this->free_shipping_cart_notice = $free_shipping_cart_notice;
$this->calculation_method = $calculation_method;
$this->cart_calculation = $cart_calculation;
$this->visibility = $visibility;
$this->default = $default;
$this->debug_mode = $debug_mode;
$this->integration = $integration;
$this->integration_settings = $integration_settings;
$this->rules_settings = $rules_settings;
}
/**
* @return array
*/
public function get_raw_settings()
{
return $this->raw_settings;
}
/**
* @return string
*/
public function get_id()
{
return $this->id;
}
/**
* @return bool
*/
public function get_enabled()
{
return $this->enabled;
}
/**
* @return string
*/
public function get_title()
{
return $this->title;
}
/**
* @return string
*/
public function get_description()
{
return $this->description;
}
/**
* @return float
*/
public function get_free_shipping()
{
return $this->free_shipping;
}
/**
* @return string
*/
public function get_free_shipping_label()
{
return $this->free_shipping_label;
}
/**
* @return bool
*/
public function get_free_shipping_cart_notice()
{
return $this->free_shipping_cart_notice;
}
/**
* @return string
*/
public function get_calculation_method()
{
return $this->calculation_method;
}
/**
* @return string
*/
public function get_cart_calculation()
{
return $this->cart_calculation;
}
/**
* @return string
* @deprecated
*/
public function get_visible()
{
return $this->visibility;
}
/**
* @return string
*/
public function get_visibility()
{
return $this->visibility;
}
/**
* @return bool
*/
public function get_default()
{
return $this->default;
}
/**
* @return bool
*/
public function get_debug_mode()
{
return $this->debug_mode;
}
/**
* @return string
*/
public function get_integration()
{
return $this->integration;
}
/**
* @return IntegrationSettingsImplementation
*/
public function get_integration_settings()
{
return $this->integration_settings;
}
/**
* @return RuleSettings[]
*/
public function get_rules_settings()
{
return $this->rules_settings;
}
/**
* @return string
*/
public function get_tax_status()
{
return $this->tax_status;
}
/**
* @return string
*/
public function get_prices_include_tax()
{
return $this->prices_include_tax;
}
/**
* @return string
*/
public function format_for_log()
{
return \sprintf(\__('Method settings:%1$s Enabled: %2$s Method Title: %3$s Method Description: %4$s Tax status: %5$s Costs includes tax: %6$s Free Shipping: %7$s Free Shipping Label: %8$s \'Left to free shipping\' notice: %9$s Rules Calculation: %10$s Cart Calculation: %11$s Visibility (Show only for logged in users): %12$s Default: %13$s Debug mode: %14$s', 'flexible-shipping'), "\n", $this->get_as_translated_checkbox_value($this->get_enabled()) . "\n", $this->get_title() . "\n", $this->get_description() . "\n", $this->get_tax_status_translated() . "\n", $this->get_prices_include_tax() . "\n", $this->get_free_shipping() . "\n", $this->get_free_shipping_label() . "\n", $this->get_as_translated_checkbox_value($this->get_free_shipping_cart_notice()) . "\n", (new \FSVendor\WPDesk\FS\TableRate\CalculationMethodOptions())->get_option_label($this->get_calculation_method()) . "\n", (new \FSVendor\WPDesk\FS\TableRate\Settings\CartCalculationOptions())->get_option_label($this->get_cart_calculation()) . "\n", $this->get_as_translated_checkbox_value($this->get_visibility()) . "\n", $this->get_as_translated_checkbox_value($this->get_default()) . "\n", $this->get_as_translated_checkbox_value($this->get_debug_mode()) . "\n") . $this->integration_settings->format_for_log();
}
/**
* @return string
*/
public function get_tax_status_translated()
{
$tax_status_options = array('taxable' => \__('Taxable', 'flexible-shipping'), 'none' => \_x('None', 'Tax status', 'flexible-shipping'));
return isset($tax_status_options[$this->tax_status]) ? $tax_status_options[$this->tax_status] : $this->tax_status;
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Rounding.
*
* @package WPDesk\FS\TableRate
*/
namespace FSVendor\WPDesk\FS\TableRate\Weight;
use FSVendor\WPDesk\FS\TableRate\Settings\RuleSettings;
/**
* Can compute rounding precision from Flexible Shipping rules.
*/
class Rounding
{
/**
* @var array
*/
private $shipping_method_rules;
/**
* WeightRounding constructor.
*
* @param RuleSettings[] $shipping_method_rules .
*/
public function __construct(array $shipping_method_rules)
{
$this->shipping_method_rules = $shipping_method_rules;
}
/**
* @return int
*/
public function get_rounding_from_rules()
{
$rounding = 0;
foreach ($this->shipping_method_rules as $rule) {
$rounding = \max($rounding, $this->get_rounding_from_rule($rule));
}
return $rounding;
}
/**
* @param RuleSettings $rule .
*
* @return int
*/
private function get_rounding_from_rule($rule)
{
if ($rule->is_based_on_weight()) {
return \max($this->get_rounding_from_value($rule->get_min()), $this->get_rounding_from_value($rule->get_max()));
}
return 0;
}
/**
* @param string $value String representation for float.
*
* @return int
*/
private function get_rounding_from_value($value)
{
$parts = \explode('.', $value);
if (isset($parts[1])) {
return \strlen($parts[1]);
}
return 0;
}
}