Plugin Directory

Changeset 3344736


Ignore:
Timestamp:
08/14/2025 02:15:41 PM (6 months ago)
Author:
calliko
Message:
  • Added translation of the text "Total" in the points write-off form.
  • Fixed the output of cashback for unregistered users.
  • Fixed the output of cashback in woocommerce blocks.
Location:
bonus-for-woo
Files:
586 added
9 edited

Legend:

Unmodified
Added
Removed
  • bonus-for-woo/trunk/_inc/bonus-computy-script.js

    r3342285 r3344736  
    222222            isRequestInProgress = true;
    223223            lastRequestTime = now;
    224             console.log('шляпа')
     224
    225225            $.post('/wp-admin/admin-ajax.php', params)
    226226                .done(data => {
     227                   // console.log('Ответ от сервера:', data);
    227228                    try {
    228229                        callback(data);
     
    232233                })
    233234                .fail((xhr, status, error) => {
    234                     console.error("Ошибка запроса:", xhr.responseText, status, error);
     235                    console.error("Ошибка запроса:", {
     236                        status,
     237                        error,
     238                        response: xhr.responseText
     239                    });
    235240                })
    236241                .always(() => {
     
    239244        };
    240245
     246
     247
    241248        const observeDOM = () => {
    242249            if (observer) {
     
    244251            }
    245252
     253            const target = document.querySelector('.wc-block-cart, .wc-block-checkout');
     254            if (!target) return;
     255
    246256            observer = new MutationObserver(debounce(() => {
    247257                initBlocks();
    248258            }, 300));
    249259
    250             observer.observe(document.body, {
     260            observer.observe(target, {
    251261                childList: true,
    252262                subtree: true
     
    270280        };
    271281
     282        let cashbackTimeout = null;
     283
     284        const debouncePost = (params, callback, delay = 300) => {
     285            clearTimeout(cashbackTimeout);
     286            cashbackTimeout = setTimeout(() => {
     287                $.post('/wp-admin/admin-ajax.php', params)
     288                    .done(data => callback(data, null))
     289                    .fail((xhr, status, error) => callback(null, {
     290                        status,
     291                        error,
     292                        response: xhr.responseText
     293                    }));
     294            }, delay);
     295        };
     296
    272297        const loadCashbackBlock = () => {
    273             safePost({
    274                 action: 'woo_blocks_cashback'
    275             }, (data) => {
     298          //  console.log('кешбэк где?');
     299            debouncePost({ action: 'woo_blocks_cashback' }, (data, err) => {
     300                if (err) {
     301                    console.warn('Ошибка кешбэка:', err);
     302                    return;
     303                }
     304              //  console.log('кешбэк тут');
    276305                const $existing = $('.bfw-order-cashback-blocks');
    277306                const $wrapper = $('.wc-block-components-totals-footer-item');
     
    282311                    $wrapper.after(`<div class="order-cashback bfw-order-cashback-blocks">${data}</div>`);
    283312                }
    284             });
    285         };
     313            }, 300); // 300 мс пауза
     314        };
     315
    286316
    287317        const initBlocks = debounce(() => {
     
    309339            setTimeout(() => {
    310340                loadSpisanieBlock();
     341
    311342                loadCashbackBlock();
    312343                $('.bfw-order-cashback-blocks, .bfw-spisanie-blocks').removeClass('opacity05');
  • bonus-for-woo/trunk/classes/BfwAdmin.php

    r3331015 r3344736  
    681681
    682682        $trans7 = __('Text in the form of writing off points.', 'bonus-for-woo') . '<br>' . __('Use shortcodes:', 'bonus-for-woo') . '<br>[points]-' . __('Number of points', 'bonus-for-woo') . '<br>[discount]-' . __('amount received', 'bonus-for-woo');
     683        $trans75 = __('Text of the number of points.', 'bonus-for-woo');
     684
    683685        $trans8 = __('The text "Use points" when opening the points write-off form.', 'bonus-for-woo');
    684686        $trans9 = __('"Bonus points" name.', 'bonus-for-woo') . BfwFunctions::helpTip(__('Main title. Used throughout the bonus system.', 'bonus-for-woo'), 'danger');
     
    699701        add_settings_field('bonus_field8', $trans8, array('BfwAdmin', 'fill_primer_field8'), 'trans_page_bonus', 'bonus_section_id');
    700702        add_settings_field('bonus_field7', $trans7, array('BfwAdmin', 'fill_primer_field7'), 'trans_page_bonus', 'bonus_section_id');
     703
     704        add_settings_field('bonus_field75', $trans75, array('BfwAdmin', 'fill_primer_field75'), 'trans_page_bonus', 'bonus_section_id');
    701705
    702706
     
    23592363        <input style="width: 170px" type="text" name="bonus_option_name[bonustext-in-cart4]"
    23602364               value="<?php echo esc_attr($value4) ?>" placeholder="<?php echo __('Apply', 'bonus-for-woo'); ?>"/>
     2365    <?php }
     2366
     2367    public static function fill_primer_field75(): void
     2368    {
     2369        $val = get_option('bonus_option_name');
     2370        $value5 = $val['bonustext-in-cart5'] ?? __('Total', 'bonus-for-woo');
     2371        ?>
     2372         <input style="width: 170px" type="text" name="bonus_option_name[bonustext-in-cart5]"
     2373               value="<?php echo esc_attr($value5) ?>" placeholder="<?php echo __('Total', 'bonus-for-woo'); ?>"/>
    23612374    <?php }
    23622375
  • bonus-for-woo/trunk/classes/BfwCashback.php

    r3342282 r3344736  
    5656
    5757        $user_role = $Role->getRole($user_id);
    58         $user_percent = $user_role['percent'] ?? 0;
     58        if (is_user_logged_in()){
     59            $user_percent = $user_role['percent'] ?? 0;
     60        }else{
     61            $user_percent = BfwRoles::maxPercent();
     62        }
     63
    5964
    6065        if ($user_percent != 0) {
  • bonus-for-woo/trunk/classes/BfwFunctions.php

    r3330617 r3344736  
    140140        $response = wp_remote_get(base64_decode('aHR0cHM6Ly9jb21wdXR5LnJ1L0FQSS9hcGkucGhwPw==') . http_build_query($get));
    141141        if($alternate_server===1){
    142         $response = wp_remote_get(base64_decode('aHR0cHM6Ly9jb21wdXR5LmFsd2F5c2RhdGEubmV0L0FQSS9hcGkucGhwPw==') . http_build_query($get));
     142            //todo переделать
     143      //  $response = wp_remote_get(base64_decode('aHR0cHM6Ly9jb21wdXR5LmFsd2F5c2RhdGEubmV0L0FQSS9hcGkucGhwPw==') . http_build_query($get));
    143144        }
    144145
  • bonus-for-woo/trunk/classes/BfwPoints.php

    r3316826 r3344736  
    564564            $bonustext_in_cart4 = $val['bonustext-in-cart4'];
    565565        }
     566
     567        $bonustext_in_cart5 = $val['bonustext-in-cart5'] ?? __('Total', 'bonus-for-woo');
     568
    566569        $head = '<div class="bfw-write-off-block"> <div class="bfw-spisanie-blocks-button">
    567570    <span class="bfw-spisanie-blocks-button-text">' . $use_points_on_cart . '</span>
     
    569572  </div><div class="computy_skidka_form">';
    570573
    571         $foot = ' <div class="text_total_points">' . __('Total', 'bonus-for-woo') . ': ' . $computy_point . ' ' . self::pointsLabel($computy_point) . '</div></div></div>';
     574        $foot = ' <div class="text_total_points">' . $bonustext_in_cart5 . ': ' . $computy_point . ' ' . self::pointsLabel($computy_point) . '</div></div></div>';
    572575
    573576        $not_use_points_text = $head . ' <div class="text_how_many_points">' . __('You cannot use points on this order.', 'bonus-for-woo') . '</div>' . $foot;
  • bonus-for-woo/trunk/classes/BfwRouter.php

    r3330617 r3344736  
    149149        /*-------Вывод кешбэка в корзине woocommerce blocks-------*/
    150150        add_action('wp_ajax_woo_blocks_cashback', array('BfwCashback', 'getCashbackInCartBlocks'));
     151        add_action('wp_ajax_nopriv_woo_blocks_cashback', array('BfwCashback', 'getCashbackInCartBlocks'));
    151152        add_action('wp_ajax_woo_blocks_spisanie', array('BfwPoints', 'bfwoo_spisaniebonusov_in_cart_blocks'));
     153        add_action('wp_ajax_nopriv_woo_blocks_spisanie', array('BfwPoints', 'bfwoo_spisaniebonusov_in_cart_blocks'));
    152154
    153155
  • bonus-for-woo/trunk/classes/BfwSingleProduct.php

    r3316826 r3344736  
    3232        $val = get_option('bonus_option_name');
    3333        // Рассчитываем количество бонусных баллов
    34         if(is_array($val) && isset($val['buy_balls-cashback']) && (int)$val['buy_balls-cashback'] === $id){
     34        if (is_array($val) && isset($val['buy_balls-cashback']) && (int)$val['buy_balls-cashback'] === $id) {
    3535            $percent = 100;
    3636        }
     
    4949            $productc = wc_get_product($id);
    5050            if ($productc && $productc->is_on_sale()) {
    51                  return $price_width_bonuses;
    52             }
    53         }
    54 
    55 
    56         $tovars =array();
     51                return $price_width_bonuses;
     52            }
     53        }
     54
     55
     56        $tovars = array();
    5757        // Проверяем, есть ли исключенные товары для кешбэка
    5858        if (BfwRoles::isPro() && isset($val['exclude-tovar-cashback'])) {
     
    6363        $categoriexs = $val['exclude-category-cashback'] ?? 'not';
    6464
    65         if(empty($val['how-mach-bonus-title'])){
     65        if (empty($val['how-mach-bonus-title'])) {
    6666            $hmb_title = __('Cashback:', 'bonus-for-woo');
    67         }else{
     67        } else {
    6868            $hmb_title = $val['how-mach-bonus-title'];
    6969        }
     
    110110        $price = 0;
    111111
    112           $constant_cashback = get_post_meta($product->get_id(), '_constant_cashback_percentage', true);
     112        $constant_cashback = get_post_meta($product->get_id(), '_constant_cashback_percentage', true);
    113113
    114114        if ($type === 'simple') {
     
    118118            $minPrice = $product->get_variation_sale_price('min', true);
    119119
    120               $constant_cashback = get_post_meta($product->get_id(), '_constant_cashback_percentage_variation', true);
     120            $constant_cashback = get_post_meta($product->get_id(), '_constant_cashback_percentage_variation', true);
    121121
    122122            $price = $maxPrice;
     
    133133
    134134
    135                         if((float)$constant_cashback>0){
    136                             $percent = $constant_cashback;
    137                         }
     135            if ((float)$constant_cashback > 0) {
     136                $percent = $constant_cashback;
     137            }
    138138
    139139            if ($percent === 0 && BfwRoles::isInvalve($userid)) {
     
    247247     * @version 7.0.0
    248248     */
    249     public static function cashbackFromOneProduct(int $product_id, int $user_id=-1, int $variation_id = null): float{
     249    public static function cashbackFromOneProduct(int $product_id, int $user_id = -1, int $variation_id = null): float
     250    {
    250251
    251252        $val = get_option('bonus_option_name');
     
    259260        // Если это вариация - просто возвращаем ее цену
    260261        if ($product->is_type('variation')) {
    261             $price = (float) $product->get_price();
     262            $price = (float)$product->get_price();
    262263        } elseif ($variation_id && $variation = wc_get_product($variation_id)) {
    263264            // Если передан ID вариации и она существует
    264265            if ($variation->is_type('variation') && $variation->get_parent_id() == $product_id) {
    265                 $price = (float) $variation->get_price();
     266                $price = (float)$variation->get_price();
    266267                $constant_cashback = get_post_meta($variation->get_id(), '_constant_cashback_percentage_variation', true) ?? false;
    267268            }
    268         }
    269         elseif ($product->is_type('variable')) {
     269        } elseif ($product->is_type('variable')) {
    270270            $constant_cashback = get_post_meta($product->get_id(), '_constant_cashback_percentage_variation', true) ?? false;
    271271            // Если это вариативный товар - возвращаем минимальную цену
    272             $price = (float) $product->get_variation_price('min', true);
    273         }else{
     272            $price = (float)$product->get_variation_price('min', true);
     273        } else {
    274274            $constant_cashback = get_post_meta($product_id, '_constant_cashback_percentage', true) ?? false;
    275275            // Для всех остальных типов товаров
    276             $price = (float) $product->get_price();
    277         }
    278         if(empty($price)){return 0.0;}
     276            $price = (float)$product->get_price();
     277        }
     278        if (empty($price)) {
     279            return 0.0;
     280        }
    279281
    280282//есть ли исключения у продукта
    281         $tovars =array();
     283        $tovars = array();
    282284        // Проверяем, есть ли исключенные товары для кешбэка
    283285        if (BfwRoles::isPro() && isset($val['exclude-tovar-cashback'])) {
     
    299301            $productc = wc_get_product($product_id);
    300302            if ($productc->is_on_sale()) {
    301                     return 0.0;
     303                return 0.0;
    302304            }
    303305        }
     
    305307
    306308//процент кешбэка пользователя
    307             if($user_id === -1){
    308                 $user_id = get_current_user_id();
    309                 if(empty($user_id)){return 0.0;}
    310             }
     309        if ($user_id === -1) {
     310            $user_id = get_current_user_id();
     311            if (empty($user_id)) {
     312                return 0.0;
     313            }
     314        }
    311315
    312316        //Если пользователь не залогинен, то максимальный кешбэк
     
    314318            global $wpdb;
    315319
    316             $percent = (float) $wpdb->get_var(
    317                 $wpdb->prepare(
    318                     "SELECT MAX(CAST(percent AS SIGNED)) FROM {$wpdb->prefix}bfw_computy"
    319                 )
     320            $percent = (float)$wpdb->get_var(
     321                "SELECT MAX(CAST(percent AS SIGNED)) FROM {$wpdb->prefix}bfw_computy"
    320322            );
    321323            $percent = empty($percent) ? 0 : $percent;
    322         }else{
     324        } else {
    323325            $percent = $Role->getRole($user_id)['percent'];
    324326        }
    325327
    326328
    327         if($constant_cashback){
    328             $percent  = (float)$constant_cashback;
    329         }
    330 
    331             //Если товар со 100% кешбэком
    332         if((int)$val['buy_balls-cashback']===$product_id){
     329        if ($constant_cashback) {
     330            $percent = (float)$constant_cashback;
     331        }
     332
     333        //Если товар со 100% кешбэком
     334        if ((int)$val['buy_balls-cashback'] === $product_id) {
    333335            $percent = 100;
    334336        }
    335337
    336         if(isset($val['cashback_for_first_order']) && $val['cashback_for_first_order']>0 && (new BfwFunctions())->get_customer_order_count($user_id)===0){
     338        if (isset($val['cashback_for_first_order']) && $val['cashback_for_first_order'] > 0 && (new BfwFunctions())->get_customer_order_count($user_id) === 0) {
    337339            $percent = $val['cashback_for_first_order'];
    338340        }
    339341
    340342
    341 
    342          if(!$Role->isInvalve($user_id)){
     343        if (!$Role->isInvalve($user_id) && is_user_logged_in()) {
    343344            return 0.0;//есть ли исключения у пользователя
    344345        }
     
    346347//процент кешбэка продукта
    347348
    348         return $price*($percent/100);
    349     }
    350 
    351 
     349        return $price * ($percent / 100);
     350    }
    352351
    353352
  • bonus-for-woo/trunk/index.php

    r3342282 r3344736  
    22/*
    33 * Plugin Name:     Bonus for Woo
    4  * Version:         7.2.2
     4 * Version:         7.3.0
    55 * Text Domain:     bonus-for-woo
    66 * Plugin URI:      https://computy.ru/blog/bonus-for-woo-wordpress
     
    2323    exit;
    2424}
    25 define('BONUS_COMPUTY_VERSION', '7.2.2'); /*версия плагина*/
     25define('BONUS_COMPUTY_VERSION', '7.3.0'); /*версия плагина*/
    2626define('BONUS_COMPUTY_VERSION_DB', '6'); /*версия базы данных*/
    2727define('BONUS_COMPUTY_PLUGIN_DIR', plugin_dir_path(__FILE__));
  • bonus-for-woo/trunk/readme.txt

    r3342282 r3344736  
    77WC requires at least: 6.0
    88WC tested up to: 10.0.4
    9 Stable tag: 7.2.2
     9Stable tag: 7.3.0
    1010Requires PHP: 7.4
    1111License: GPLv3 or later
     
    108108== Changelog ==
    109109
     110= 7.3.0 - 2025-08-14 =
     111* Added translation of the text "Total" in the points write-off form.
     112* Fixed the output of cashback for unregistered users.
     113* Fixed the output of cashback in woocommerce blocks.
     114
    110115= 7.2.2 - 2025-08-10 =
    111116* Fixed cashback output when using points.
Note: See TracChangeset for help on using the changeset viewer.