Пример #1
0
 public function load()
 {
     if (!$this->woocommerceAvailable()) {
         return;
     }
     $this->loadLanguage();
     $this->loadFunctions();
     $this->loadClasses();
     WBS_Profile_Manager::setup();
     WBS_Upgrader::setup($this->pluginFile);
 }
 public static function instance($resetCache = false)
 {
     if (!isset(self::$instance)) {
         self::$instance = new self();
         add_filter('woocommerce_shipping_methods', array(self::$instance, '_registerProfiles'));
     }
     if ($resetCache) {
         unset(self::$instance->orderedProfiles);
         unset(self::$instance->profileInstances);
     }
     return self::$instance;
 }
    private static function listProfiles(array $profiles)
    {
        $current_profile_id = WBS_Profile_Manager::instance()->current_profile_id();
        ?>
            <table id="woowbs_shipping_methods" class="wc_shipping widefat">
                <thead>
                <tr>
                    <th class="name">   <?php 
        esc_html_e('Name', 'woowbs');
        ?>
                  </th>
                    <th>                <?php 
        esc_html_e('Destination', 'woowbs');
        ?>
           </th>
                    <th>                <?php 
        esc_html_e('Weight', 'woowbs');
        ?>
                </th>
                    <th>                <?php 
        esc_html_e('Subtotal', 'woowbs');
        ?>
              </th>
                    <th>                <?php 
        esc_html_e('Cost', 'woowbs');
        ?>
                  </th>
                    <th class="status"> <?php 
        esc_html_e('Active', 'woowbs');
        ?>
                </th>
                    <th>                <?php 
        esc_html_e('Actions');
        ?>
                         </th>
                </tr>
                </thead>
                <tbody>
                <?php 
        /** @var WC_Weight_Based_Shipping[] $profiles */
        ?>
                <?php 
        foreach ($profiles as $profile) {
            ?>
                    <tr
                        <?php 
            echo $profile->profile_id === $current_profile_id ? 'class="wbs-current"' : null;
            ?>
                        data-settings-url="<?php 
            echo esc_html(WbsRuleUrls::edit($profile));
            ?>
"
                        >
                        <td class="name"><?php 
            echo esc_html($profile->name);
            ?>
</td>

                        <td class="countries">
                            <?php 
            if ($profile->availability === 'all') {
                ?>
                                <?php 
                esc_html_e('Any', 'woowbs');
                ?>
                            <?php 
            } else {
                ?>
                                <?php 
                if ($profile->availability === 'excluding') {
                    ?>
                                    <?php 
                    esc_html_e('All except', 'woowbs');
                    ?>
                                <?php 
                }
                ?>
                                <?php 
                echo esc_html(join(', ', $profile->countries));
                ?>
                            <?php 
            }
            ?>
                        </td>

                        <?php 
            foreach (array($profile->weight, $profile->subtotal) as $range) {
                ?>
                            <td>
                                <?php 
                echo isset($range->min) || isset($range->max) ? ($range->minInclusive || !isset($range->min) ? '[' : '(') . esc_html(wc_format_localized_decimal((double) $range->min)) . '&nbsp;–&nbsp;' . (isset($range->max) ? esc_html(wc_format_localized_decimal($range->max)) : '<span style="font-family:monospace">&infin;</span>') . ($range->maxInclusive ? ']' : ')') : 'Any';
                ?>
                            </td>
                        <?php 
            }
            ?>

                        <td>
                            <?php 
            echo esc_html($profile->makeCostString());
            ?>
                        </td>

                        <td class="status">
                            <?php 
            if ($profile->enabled == 'yes') {
                ?>
                                <span class="status-enabled tips" data-tip="<?php 
                esc_html_e('Enabled', 'woowbs');
                ?>
"><?php 
                esc_html_e('Enabled', 'woowbs');
                ?>
</span>
                            <?php 
            } else {
                ?>
                                -
                            <?php 
            }
            ?>
                        </td>

                        <td class="actions">
                            <a class="button" href="<?php 
            echo esc_html(WbsRuleUrls::duplicate($profile));
            ?>
">
                                <?php 
            esc_html_e('Duplicate', 'woowbs');
            ?>
                            </a>

                            <a class="button" href="<?php 
            echo esc_html(WbsRuleUrls::delete($profile));
            ?>
"
                               onclick="return confirm('<?php 
            esc_html_e('Are you sure you want to delete this rule?', 'woowbs');
            ?>
');">
                                <?php 
            esc_html_e('Delete');
            ?>
                            </a>
                        </td>
                    </tr>
                <?php 
        }
        ?>
                </tbody>
            </table>
            <script>
                jQuery((function($)
                {
                    var $table = $("#woowbs_shipping_methods");
                    $table.find('tbody').on("sortcreate", function() { $(this).sortable('destroy'); });
                    $table.find('td').click(function(e) { if (e.target == this) location.href = $(this).parent().data('settingsUrl'); });
                })(jQuery));
            </script>

            <!--suppress CssUnusedSymbol -->
            <style>
                #woowbs_shipping_methods td { cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
                #woowbs_shipping_methods .actions { white-space: nowrap; }
                #woowbs_shipping_methods .countries { max-width: 15em; }
                #woowbs_shipping_methods .wbs-current td { background-color: #eee; }
                #woowbs_shipping_methods tr:hover td { background-color: #ddd; }
                tr.wbs-title th { padding: 2em 0 0 0; }
                tr.wbs-title h4 { font-size: 1.2em; }
                .wc-settings-sub-title { padding-top: 2em; }
                .form-table { border-top: 1px solid #aaa; }
                tr.wbs-profiles > td { padding: 0; }

                .wbs-destination label { display: none; }
                .wbs-destination .forminp { padding-top: 0; }
                .wbs-destination fieldset { margin-top: -15px !important; }

                .wbs-subtotal .forminp { padding-bottom: 0}
                .wbs-subtotal + tr > * { padding-top: 0 }
                .wbs-subtotal + tr label { display: none; }
                .wbs-minifield { width: 15.7em; }
                .wbs-minifield.wc_input_decimal { text-align: right; }
                .wbs-minifield-container { display: block ! important; }
                .wbs-minifield-label { display: inline-block; min-width: 3em; }
                .wbs-range-simple .wbs-minifield-label { min-width: 5em; }
                .wbs-range-simple .wbs-minifield { min-width: 19.7em; }
                .wbs-weight-rate .wbs-minifield-label { min-width: 5em; }
                .wbs-weight-rate .wbs-minifield { width: 17.3em; }

                .wbs-input-group {
                    display: inline-block;
                    height: 29px;
                    box-sizing: border-box;
                }

                .wbs-input-group-addon {
                    display: inline-block;
                    box-sizing: border-box;
                    height: 100%;
                    width: 2.5em;
                    text-align: center;
                    border: 1px solid #ddd;
                    padding: 3px 0;
                }

                .wbs-input-group-addon:first-child {
                    border-right: 0;
                    float: left;
                }

                .wbs-input-group-addon:last-child {
                    border-left: 0;
                    float: right;
                }

                .wbs-input-group input[type="text"] {
                    display: inline-block;
                    height: 100%;
                    box-sizing: border-box;
                    margin: 0;
                }

                .wbs-code {
                    font-size: inherit;
                    padding: 0 0.5em;
                    font-family: monospace;
                }

                .shippingrows {
                    overflow: hidden;
                }

                .shippingrows th, .shippingrows td {
                    width: auto;
                    white-space: nowrap;
                    padding: 1em;
                }

                .shippingrows .wc_input_decimal {
                    width: 7em;
                }

                .flat_rate .wbs-minifield-container {
                    display: inline !important;
                    margin-left: 1em;
                }

                .flat_rate .wbs-minifield-container:first-child {
                    margin-left: 0;
                }

                .flat_rate .wbs-minifield-label {
                    display: inline;
                }

                .flat_rate .wbs-minifield {
                    width: 6em;
                }

                .flat_rate_tpl {
                    display: none;
                }
            </style>
            <?php 
    }
Пример #4
0
 private function checkForUpgrade()
 {
     $updateCurrentVersion = false;
     $currentVersion = null;
     $pluginData = get_plugin_data($this->pluginFile, false, false);
     $currentVersion = $pluginData['Version'];
     $previousVersion = get_option('woowbs_version');
     if (empty($previousVersion)) {
         $hasSomeRules = !!WBS_Profile_Manager::listAvailableProfileIds();
         $hasSomeRules = $hasSomeRules || !!WBS_Profile_Manager::listAvailableProfileIds('woocommerce_', 'WC_Weight_Based_Shipping_');
         $previousVersion = $hasSomeRules ? '2.6.8' : $currentVersion;
         $updateCurrentVersion = true;
     }
     if ($previousVersion !== $currentVersion) {
         $updateCurrentVersion = true;
         if (version_compare($previousVersion, '2.2.1') < 0) {
             $this->upgradeNotices->add(WBS_Upgrade_Notice::createBehaviourChangeNotice('2.2.1', '
                     Previously, weight-based shipping option has not been shown to user if total
                     weight of their cart is zero. Since version 2.2.1 this is changed so shipping
                     option is available to user with price set to Handling Fee. If it does not
                     suite your needs well you can return previous behavior by setting Min Weight
                     to something a bit greater zero, e.g. 0.001, so that zero-weight orders will
                     not match constraints and the shipping option will not be shown.
                 '));
         }
         if (version_compare($previousVersion, '2.4.0') < 0) {
             $profiles = WBS_Profile_Manager::instance()->profiles();
             foreach ($profiles as $profile) {
                 $option = $profile->get_wp_option_name();
                 $config = get_option($option);
                 $config['extra_weight_only'] = 'no';
                 update_option($option, $config);
             }
         }
         if (version_compare($previousVersion, '2.6.3') < 0) {
             $this->upgradeNotices->add(WBS_Upgrade_Notice::createBehaviourChangeNotice('2.6.2', '
                     Previously, base Handling Fee has not been added to the shipping price if user
                     cart contained only items with shipping classes specified in the Shipping
                     Classes Overrides section. Starting from version 2.6.2 base Handling Fee is
                     applied in any case. This behavior change is only affecting you if you use
                     Shipping Classes Overrides. If you don\'t use it just ignore this message.
                 '));
         }
         if (version_compare($previousVersion, '4.0.0') < 0) {
             // Rename settings options
             if ($ruleIdsToUpdate = WBS_Profile_Manager::listAvailableProfileIds('woocommerce_', 'WC_Weight_Based_Shipping_')) {
                 foreach ($ruleIdsToUpdate as $oldSettingsName => $id) {
                     $settings = get_option($oldSettingsName);
                     # Don't remove old settings entry. Keep it as a backup.
                     //delete_option($oldSettingsName);
                     $newSettingsName = WBS_Profile_Manager::getRuleSettingsOptionName($id);
                     if (!get_option($newSettingsName)) {
                         update_option($newSettingsName, $settings);
                     }
                 }
                 // Reset cache to load renamed rules
                 WBS_Profile_Manager::instance(true);
             }
             $rangeFieldsMap = array('weight' => array('min_weight', 'max_weight', false), 'subtotal' => array('min_subtotal', 'max_subtotal', false), 'price_clamp' => array('min_price', 'max_price', true));
             foreach (WBS_Profile_Manager::instance()->profiles() as $profile) {
                 $option = $profile->get_wp_option_name();
                 $config = get_option($option);
                 // Convert conditions
                 foreach ($rangeFieldsMap as $newField => $oldFields) {
                     if (!isset($config[$newField])) {
                         $range = null;
                         $min = (double) @$config[$oldFields[0]];
                         $max = (double) @$config[$oldFields[1]];
                         if ($min || $max) {
                             $range = new WbsRange($min ? $min : null, $max ? $max : null, true, $oldFields[2] || !!$max);
                         }
                         if (!isset($range)) {
                             $range = new WbsRange();
                         }
                         $config[$newField] = $range->toArray();
                     }
                     unset($config[$oldFields[0]]);
                     unset($config[$oldFields[1]]);
                 }
                 $weightRange = WbsRange::fromArray(@$config['weight']);
                 $extraWeightOnly = @$config['extra_weight_only'];
                 unset($config['extra_weight_only']);
                 // Convert progressive rate
                 if (!isset($config['weight_rate'])) {
                     $config['weight_rate'] = self::convertToProgressiveRate(@$config['rate'], @$config['weight_step'], $extraWeightOnly, $weightRange->min)->toArray();
                     unset($config['weight_step']);
                     unset($config['rate']);
                 }
                 // Convert shipping class rates
                 if (!isset($config['shipping_class_rates'])) {
                     /** @var WBS_Shipping_Class_Override_Set $oldRates */
                     if (($oldRates = @$config['shipping_class_overrides']) && ($oldRates = $oldRates->getOverrides())) {
                         $rates = new WbsBucketRates();
                         /** @var WBS_Shipping_Rate_Override $oldRate */
                         foreach ($oldRates as $oldRate) {
                             $rates->add(new WbsBucketRate($oldRate->getClass(), $oldRate->getFee(), self::convertToProgressiveRate($oldRate->getRate(), @$oldRate->getWeightStep(), $extraWeightOnly, $weightRange->min)));
                         }
                         $config['shipping_class_rates'] = $rates;
                     }
                     unset($config['shipping_class_overrides']);
                 }
                 update_option($option, $config);
             }
         }
     }
     if ($updateCurrentVersion) {
         update_option('woowbs_version', $currentVersion);
     }
 }
Пример #5
0
 public static function create(array $additionals = array())
 {
     return self::genericWithProfile(WBS_Profile_Manager::instance()->new_profile_id(), $additionals);
 }