Plugin Directory

Changeset 3047333


Ignore:
Timestamp:
03/07/2024 04:43:55 PM (2 years ago)
Author:
homescript
Message:

update to version 1.2

Location:
doko-box-builder/trunk
Files:
7 added
11 edited

Legend:

Unmodified
Added
Removed
  • doko-box-builder/trunk/README.txt

    r3001399 r3047333  
    11=== DokoBuilder : DIY Product Bundle for WooCommerce  ===
    2 Contributors: homescriptone, freemius
     2Contributors: homescript, freemius
    33Donate link: https://www.buymeacoffee.com/homescriptone
    44Tags: woocommerce, product bundles, box-wrapping, gift, wrap, bundle, diy
    55Requires at least: 4.4
    66Tested up to: 6.4
    7 Stable tag: 1.1.2
     7Stable tag: 1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6060
    6161== Changelog ==
     62<h4> 1.2 - 8 March 2024 <h4>
     63<ul>
     64    <li> Add ability to manage product stock </li>
     65    <li> Add compatibility with WooCommerce 8.4 </li>
     66</ul>
     67
    6268<h4> 1.1.2 - 11 November 2023 <h4>
    6369<ul>
  • doko-box-builder/trunk/admin/class-hs-doko-admin.php

    r3001399 r3047333  
    99 * @package doko
    1010 */
     11namespace HS\Doko;
     12
    1113/**
    1214 * The admin-specific functionality of the plugin.
     
    4042     * @return mixed|void
    4143     */
    42     private function get_default_cpt_args( $menu_icon = false )
     44    private function get_default_cpt_args( $menu_icon = false, $args = array() )
    4345    {
    4446        /**
     
    4749         * @since 1.0.0
    4850         */
    49         return apply_filters( 'doko_cpt_args', array(
     51        $args = wp_parse_args( $args, apply_filters( 'doko_cpt_args', array(
    5052            'hierarchical'        => false,
    5153            'supports'            => array( 'title' ),
     
    6062            'can_export'          => true,
    6163            'menu_icon'           => $menu_icon,
    62         ) );
     64        ) ) );
     65        return $args;
    6366    }
    6467   
     
    101104         * class.
    102105         */
    103         global  $post_type ;
    104         $list_cpts = array( 'doko-bundles' );
    105        
    106         if ( in_array( $post_type, $list_cpts, true ) || isset( $_GET['post_type'] ) && 'doko-bundles' === $_GET['post_type'] ) {
     106        global  $post_type, $parent_file ;
     107        $allowed_slugs = hs_dk_get_allowed_slug();
     108       
     109        if ( in_array( $post_type, $allowed_slugs['post_type'], true ) || in_array( $parent_file, $allowed_slugs['page'], true ) ) {
    107110            wp_enqueue_style(
    108111                'select2',
     
    156159         * class.
    157160         */
    158         global  $post_type, $post ;
    159         $list_cpts = array( 'doko-bundles' );
    160        
    161         if ( in_array( $post_type, $list_cpts, true ) && is_object( $post ) || isset( $_GET['post_type'] ) && 'doko-bundles' === $_GET['post_type'] ) {
     161        global  $post_type, $parent_file ;
     162        $allowed_slugs = hs_dk_get_allowed_slug();
     163       
     164        if ( in_array( $post_type, $allowed_slugs['post_type'], true ) || in_array( $parent_file, $allowed_slugs['page'], true ) ) {
    162165            wp_enqueue_script(
    163166                'hs-quilljs-js',
     
    242245    public function add_menus()
    243246    {
    244         add_submenu_page(
    245             null,
    246             esc_html__( 'Manage Dynamic Rules', 'doko' ),
    247             esc_html__( 'Manage Dynamic Rules', 'doko' ),
    248             'manage_options',
    249             'manage-dynamic-rules',
    250             array( $this, 'get_conditional_rules_page' )
    251         );
    252         add_submenu_page(
    253             'edit.php?post_type=doko-bundles',
    254             esc_html__( 'Documentation', 'doko' ),
    255             esc_html__( 'Documentation', 'doko' ),
    256             'manage_options',
    257             'doko-docs',
    258             array( $this, 'redirect_to_docs' )
    259         );
    260247    }
    261248   
     
    403390            'normal'
    404391        );
     392        add_meta_box(
     393            'doko-bundle-rules',
     394            'Associate Rule to Bundle',
     395            array( $this, 'get_associated_rule_to_bundle__premium_only' ),
     396            'doko-bundles-rules',
     397            'normal'
     398        );
     399        add_meta_box(
     400            'doko-rules',
     401            'Rules',
     402            array( $this, 'get_rules__premium_only' ),
     403            'doko-bundles-rules',
     404            'normal'
     405        );
     406        do_action( 'doko_add_metaboxes' );
     407    }
     408   
     409    public function get_dynamic_rules()
     410    {
     411        $posted_data = filter_input_array( INPUT_POST );
     412        $bundle_id = $posted_data['bundle_id'];
     413        $data_id = uniqid() . $bundle_id;
     414        $args = $this->generate_content_args( $data_id );
     415        $args['bundle_id'] = $bundle_id;
     416        $args['current_index'] = $posted_data['current_index'];
     417        $data = array(
     418            'html' => $this->generate_rules_content( $data_id, $args ),
     419            'args' => $args,
     420        );
     421        echo  wp_json_encode( $data ) ;
     422        wp_die();
    405423    }
    406424   
     
    481499        formulus_input_table( 'doko-box-settings', $table_args );
    482500        ?>
    483             <input type="hidden" name="doko_nonce" value="<?php
     501         <input type="hidden" name="doko_nonce" value="<?php
    484502        echo  esc_html( wp_create_nonce( 'doko_nonce' ) ) ;
    485503        ?>" />
     
    516534    }
    517535   
     536    public static function get_rules_data_to_unset()
     537    {
     538        return apply_filters( 'doko_data_rules_to_unset', array( 'rules' ) );
     539    }
     540   
    518541    public static function get_data_to_unset()
    519542    {
     
    541564        ?>
    542565                <span class="product-data-wrapper type_box ">
    543                     <button class="button button-primary" id="add-btn-off"><?php
     566                    <button class="button button-primary hs-add-screen" id="add-btn-off"><?php
    544567        esc_html_e( 'Add Screen ', 'doko' );
    545568        ?></button>
    546                     </ul>
    547569                </span>
    548570                <div class="woocommerce_variations wc-metaboxes">
     
    568590        ?>" />
    569591        <?php
     592    }
     593   
     594    private function generate_bundle_rule_fields( $args = array(), $saved_data = false )
     595    {
     596        $bundle_id = $args['bundle_id'];
     597        /**
     598         * Rule Bundle Data.
     599         */
     600        $pbundle_data = get_post_meta( $bundle_id, 'doko', true );
     601        $bundle_data = $pbundle_data;
     602        if ( isset( $args['parent_bundle_id'] ) ) {
     603            /**
     604             * Bundle Data.
     605             */
     606            $bundle_data = get_post_meta( $args['parent_bundle_id'], 'doko', true );
     607        }
     608        extract( $args );
     609        $bundle_screens = array(
     610            'first-step' => 'First step',
     611        );
     612        $first_step_mode = $bundle_data['box-selection-mode'] ?? "";
     613        $box_products = $bundle_data['box-products'] ?? "";
     614        $box_categories = $bundle_data['box-categories'] ?? "";
     615        $first_step_options = array(
     616            'mode'           => $first_step_mode,
     617            'box-products'   => $box_products,
     618            'box-categories' => $box_categories,
     619        );
     620        $fields_to_unset = self::get_data_to_unset();
     621        foreach ( $fields_to_unset as $field ) {
     622            if ( isset( $bundle_data[$field] ) ) {
     623                unset( $bundle_data[$field] );
     624            }
     625        }
     626        foreach ( $bundle_data as $bkey => $bvalue ) {
     627            $bundle_screens[$bkey] = $bvalue['screen-name'];
     628        }
     629        $products = array(
     630            'products' => array(),
     631        );
     632        $bundle_id = $args['parent_bundle_id'];
     633        $table_args = apply_filters( 'doko_dynamic_rule_screen_table_fields', array(
     634            'screen-name'          => array(
     635            'label'       => esc_html__( 'Step Name :', 'doko' ),
     636            'label_class' => 'doko-table-label',
     637            'description' => esc_html__( 'Choose the step where you would like this rule to apply', 'doko' ),
     638            'content'     => formulus_input_fields( "doko[{$select_id}][screen-name]", array(
     639            'type'              => 'select',
     640            'options'           => $bundle_screens,
     641            'return'            => true,
     642            'custom_attributes' => array(
     643            'data-bundle-id' => $bundle_id,
     644        ),
     645            'class'             => array( 'doko-rule-step' ),
     646        ), ( isset( $saved_data['screen-name'] ) ? $saved_data['screen-name'] : 'first-step' ) ) . '<span class="doko-bundle-screen-name-tip"></span>',
     647        ),
     648            'rules'                => array(
     649            'label'       => esc_html__( 'Rules :', 'doko' ),
     650            'label_class' => 'doko-table-label',
     651            'description' => esc_html__( 'Choose the rule to associate to this step', 'doko' ),
     652            'content'     => formulus_input_fields( "doko[{$select_id}][rule][]", array(
     653            'type'              => 'select',
     654            'options'           => $products['products'],
     655            'return'            => true,
     656            'custom_attributes' => array(
     657            'multiple'       => true,
     658            'data-bundle-id' => $bundle_id,
     659        ),
     660        ), ( isset( $saved_data['rule'] ) ? $saved_data['rule'] : 'all' ) ) . '<span class="doko-bundle-screen-name-tip"></span>',
     661        ),
     662            'actions'              => array(
     663            'label'       => esc_html__( 'Action :', 'doko' ),
     664            'label_class' => 'doko-table-label',
     665            'description' => esc_html__( 'Choose the action to execute if this rule is triggered', 'doko' ),
     666            'content'     => formulus_input_fields( "doko[{$select_id}][action]", array(
     667            'type'              => 'select',
     668            'options'           => array(
     669            'limit-product-in-next-step'    => 'Limit product in next step',
     670            'limit-product-in-current-step' => 'Limit product in current step',
     671            'limit-amount-in-current-step'  => 'Limit amount in current step',
     672            'limit-amount-in-next-step'     => 'Limit amount in next step',
     673            'go-to-step'                    => 'Go to step',
     674        ),
     675            'return'            => true,
     676            'custom_attributes' => array(
     677            'data-bundle-id' => $bundle_id,
     678        ),
     679        ), ( isset( $saved_data['action'] ) ? $saved_data['action'] : 'limit-product-in-next-step' ) ) . '<span class="doko-bundle-screen-name-tip"></span>',
     680        ),
     681            'limit-product-number' => array(
     682            'label'       => esc_html__( 'Limit product number for the action above :', 'doko' ),
     683            'label_class' => 'doko-table-label',
     684            'tr_class'    => "doko-limit-product-number doko-{$select_id}",
     685            'description' => esc_html__( 'Define the product number limit in this step', 'doko' ),
     686            'content'     => formulus_input_fields( "doko[{$select_id}][limit-product-number]", array(
     687            'type'   => 'text',
     688            'return' => true,
     689        ), ( isset( $saved_data['limit-product-number'] ) ? $saved_data['limit-product-number'] : 1 ) ) . '<span class="doko-bundle-screen-name-tip"></span>',
     690        ),
     691            'limit-product-amount' => array(
     692            'label'       => esc_html__( 'Limit product amount for the action above :', 'doko' ),
     693            'label_class' => 'doko-table-label',
     694            'tr_class'    => "doko-limit-product-amount doko-{$select_id}",
     695            'description' => esc_html__( "Define the product amount limit in this step ( don't include currency in the field )", 'doko' ),
     696            'content'     => formulus_input_fields( "doko[{$select_id}][limit-product-amount]", array(
     697            'type'   => 'text',
     698            'return' => true,
     699        ), ( isset( $saved_data['limit-product-amount'] ) ? $saved_data['limit-product-amount'] : 10 ) ) . '<span class="doko-bundle-screen-name-tip"></span>',
     700        ),
     701            'step-to-go-to'        => array(
     702            'label'       => esc_html__( 'Step to go :', 'doko' ),
     703            'label_class' => 'doko-table-label',
     704            'tr_class'    => "doko-go-to-screen doko-{$select_id}",
     705            'description' => esc_html__( 'Choose the step you would like to redirect for this action', 'doko' ),
     706            'content'     => formulus_input_fields( "doko[{$select_id}][step-to-go-to]", array(
     707            'type'    => 'select',
     708            'options' => $bundle_screens,
     709            'return'  => true,
     710        ), ( isset( $saved_data['step-to-go-to'] ) ? $saved_data['step-to-go-to'] : 'first-step' ) ) . '<span class="doko-bundle-screen-name-tip"></span>',
     711        ),
     712        ) );
     713        return formulus_input_table( $section_name, $table_args, true );
    570714    }
    571715   
     
    604748            'bundle-products' => esc_html__( 'Bundle Products', 'doko' ),
    605749            'upgrade-cc'      => esc_html__( 'Bundle Cart Content (PRO Version)', 'doko' ),
     750            'upgrade-card'    => esc_html__( 'Bundle Card Page (PRO Version)', 'doko' ),
    606751        );
    607752        /**
     
    630775            'options' => apply_filters( 'doko_bundle_screen_disposition', $option_list ),
    631776            'return'  => true,
    632         ), ( isset( $saved_data['categories'] ) ? $saved_data['categories'] : 'bundle-products' ) ),
     777        ), ( isset( $saved_data['screen-disposition'] ) ? $saved_data['screen-disposition'] : 'bundle-products' ) ),
    633778        ),
    634779            'display-bundle-title'             => array(
     
    759904        $meta_key = 'doko';
    760905       
    761         if ( isset( $_POST[$meta_key], $_POST['doko_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['doko_nonce'] ), 'doko_nonce' ) ) {
    762             $posted_data = filter_input(
    763                 INPUT_POST,
    764                 $meta_key,
    765                 FILTER_DEFAULT,
    766                 FILTER_REQUIRE_ARRAY
    767             );
     906        if ( isset( $_POST[$meta_key] ) ) {
     907            $posted_data = filter_input_array( INPUT_POST );
     908            $posted_data = $posted_data['doko'];
    768909            update_post_meta( $post_id, $meta_key, $posted_data );
    769910        }
     
    828969        echo  wp_json_encode( $data ) ;
    829970        wp_die();
     971    }
     972   
     973    private function generate_rules_content( $data_id, $args, $saved_data = false )
     974    {
     975        $screen_name = "Rule #" . $args['current_index'];
     976        $args['screen-name'] = $data_id;
     977        $content = $this->generate_bundle_rule_fields( $args, $saved_data );
     978        $variation_id = $data_id;
     979        ob_start();
     980        ?>
     981        <div class="woocommerce_variation wc-metabox variation-needs-update doko-dynamic-bundle closed" style="border-radius: 3px; background: #fff; border: 1px solid black; margin: 0 !important;">
     982            <h3 class="doko-collapse">
     983                <a href="#" class="remove_variation delete" style="float: right;" rel="<?php
     984        echo  esc_attr( $variation_id ) ;
     985        ?>"><?php
     986        esc_html_e( 'Remove', 'doko' );
     987        ?></a>
     988                <div class="handlediv" style="width: 27px; float: right;" aria-label="<?php
     989        esc_attr_e( 'Click to toggle', 'doko' );
     990        ?>"></div>
     991                <strong><span class="doko-section-<?php
     992        echo  esc_attr( $data_id ) ;
     993        ?>"> <?php
     994        echo  wp_kses_post( $screen_name ) ;
     995        ?>  </span></strong>
     996
     997                <input type="hidden" class="variable_post_id"  />
     998                <input type="hidden" class="variation_menu_order"  />
     999            </h3>
     1000            <div class="woocommerce_variable_attributes wc-metabox-content" style="display: none;">
     1001                <div class="data">
     1002                    <?php
     1003        formulus_format_fields( $content );
     1004        ?>
     1005                </div>
     1006            </div>
     1007        </div>
     1008        <?php
     1009        return ob_get_clean();
    8301010    }
    8311011   
     
    8701050    public function get_columns_values( $column_name, $id )
    8711051    {
    872        
    8731052        if ( 'bundle_shortcodes' === $column_name ) {
    8741053            formulus_format_fields( $this->generate_bundle_shortcode( $id ) );
    875         } elseif ( 'bundle_rules' === $column_name ) {
    876             $url = admin_url( "edit.php?post_type=doko-bundles&page=manage-dynamic-rules&bundle-id={$id}" );
    877             formulus_format_fields( "<a class='button button-primary button-large ' href='{$url}'>" . esc_html__( 'Manage dynamic rules', 'doko' ) . '</a>' );
    878         }
    879        
     1054        }
    8801055        /**
    8811056         * Fires after the column value is generated.
     
    11301305        wp_die();
    11311306    }
     1307   
     1308    public function get_screen_products()
     1309    {
     1310        $posted_data = filter_input_array( INPUT_POST );
     1311        extract( $posted_data );
     1312        $data = $this->get_data( $bundle_id );
     1313       
     1314        if ( $screen == "first-step" ) {
     1315            $box_selection_mode = $data['box-selection-mode'];
     1316        } else {
     1317            $box_selection_mode = $data[$screen]['options'];
     1318        }
     1319       
     1320        $products = $this->get_screen_product_ids( $data, $box_selection_mode, $screen );
     1321        echo  wp_json_encode( $products ) ;
     1322        wp_die();
     1323    }
     1324   
     1325    private function get_screen_product_ids( $data, $mode, $screen_name = false )
     1326    {
     1327        $product_names = [
     1328            'no'  => '-- Do Nothing --',
     1329            'all' => 'If any product in step is added to box',
     1330        ];
     1331        $html = "<option value='no'>-- Do Nothing --</option>\n                     <option value='all'>If any product in step is added to box</option>\n                   ";
     1332       
     1333        if ( $screen_name == "first-step" ) {
     1334           
     1335            if ( $mode == "products" ) {
     1336                $all_products = $data['box-products'];
     1337                $products = doko_get_children_products( $all_products );
     1338            } else {
     1339                $args = array(
     1340                    'post_type'           => array( 'product', 'product_variation' ),
     1341                    'product_category_id' => $data['box-categories'],
     1342                    'return'              => 'ids',
     1343                    'limit'               => -1,
     1344                );
     1345                $all_products = wc_get_products( $args );
     1346                $products = doko_get_children_products( $all_products );
     1347            }
     1348       
     1349        } else {
     1350           
     1351            if ( $mode == "products" ) {
     1352                $all_products = $data[$screen_name]['products'];
     1353                $products = doko_get_children_products( $all_products );
     1354            } else {
     1355                $args = array(
     1356                    'post_type'           => array( 'product', 'product_variation' ),
     1357                    'product_category_id' => $data[$screen_name]['categories'],
     1358                    'return'              => 'ids',
     1359                    'limit'               => -1,
     1360                );
     1361                $all_products = wc_get_products( $args );
     1362                $products = doko_get_children_products( $all_products );
     1363            }
     1364       
     1365        }
     1366       
     1367        foreach ( $products as $product_id ) {
     1368            $product_names[$product_id] = "If product " . get_the_title( $product_id ) . " is added to box";
     1369            $html .= "<option value='{$product_id}'>If product " . get_the_title( $product_id ) . " is added to box</option>";
     1370        }
     1371        return array(
     1372            'products' => $product_names,
     1373            'html'     => $html,
     1374        );
     1375    }
    11321376
    11331377}
  • doko-box-builder/trunk/admin/css/hs-quilljs.css

    r2925566 r3047333  
    378378    text-align: inherit;
    379379  }
    380   .ql-editor .ql-align-center {
     380  .ql-editor .ql-align-center, .ql-align-center {
    381381    text-align: center;
    382382  }
  • doko-box-builder/trunk/admin/js/hs-doko-admin.js

    r2925566 r3047333  
    9898            }
    9999        });
    100         $('#accordion div.group').map(function(i) { console.log($(this).children('.group1').data()); return this.id; }).get()
     100        $('#accordion div.group').map(function(i) { return this.id; }).get()
    101101    }
    102102
    103103
    104104    $(document).ready(function(){
     105        var hs_dk_bundle_screen = [
     106            '#doko-bundle-screens',
     107            '#doko-rules'
     108        ];
     109
     110        for( var screen in hs_dk_bundle_screen ) {
     111            $( '.type_box' ).insertAfter( hs_dk_bundle_screen[screen] + ' .hndle' );
     112        }
     113
     114
     115
     116
     117        var total_rule = 0;
     118
     119        $('button.hs-add-rule').on('click dbclick', function(e){
     120            e.preventDefault();
     121            var bundleId= $('select#doko-associated_rule-bundle').val();
     122
     123            if ( bundleId == "no" ) {
     124                alert("Choose a bundle, before choosing a rule.");
     125                return false;
     126            }
     127
     128            $.blockUI({'message' : 'Preparing your bundle rule, please wait ....'});
     129            $.post(ajaxurl, {'action': 'doko_get_bundle_rule', 'bundle_id' : bundleId , 'current_index' : total_rule },
     130                function(r){
     131                    r = JSON.parse(r);
     132                    var idField = r.args.elem_id;
     133                    $('div.woocommerce_variations').append( r.html );
     134                    dk_init_sortable_event();
     135                    dk_build_sortable_bundle( idField, r.args );
     136
     137                    hs_dk_get_screen_product_list( bundleId, idField );
     138
     139                    hs_dk_toggle_rule_action( bundleId, idField );
     140                    total_rule ++;
     141                    $.unblockUI();
     142
     143
     144
     145
     146
     147                } );
     148        });
     149
     150
     151
    105152        if ( $('#doko-box-description').length > 0 ) {
    106153
     
    133180            dk_change_option_disposition( 'input[name="doko[box-selection-mode]"]', 'tr.doko-box-products-mode', 'tr.doko-box-categories-mode');
    134181
    135             $( '.type_box' ).insertAfter( '#doko-bundle-screens .hndle' );
    136 
    137 
    138             $('button#add-btn-off').on('click dbclick', function(e){
     182
     183
     184            $('button.hs-add-screen').on('click dbclick', function(e){
    139185                e.preventDefault();     
    140186                $.blockUI({'message' : 'Adding your bundle screen content, please wait ....'})
     
    235281            }
    236282        }
    237        
     283        var fields = window.doko_fields_list;
     284        var bundleId = window.doko_bundle_id;
     285        var js = JSON.parse(fields);
     286
     287
     288        for( var id in js ) {
     289            hs_dk_get_screen_product_list( bundleId, js[id] );
     290            hs_dk_toggle_rule_action( bundleId, js[id] );
     291        }
     292
     293
    238294    });
    239295
     
    396452    };
    397453
     454    var hs_dk_toggle_rule_action = function( bundleId, idField ) {
     455        var elem = $('select[name="doko['+idField+'][action]"][data-bundle-id="'+bundleId+'"]');
     456
     457        elem.on('change', function() {
     458            var value = $(this).val();
     459            if ( value == "limit-product-in-current-step"  || value == "limit-product-in-next-step"  ) {
     460                $('tr.doko-limit-product-number.doko-'+idField ).show();
     461                $('tr.doko-limit-product-amount.doko-'+idField ).hide();
     462                $('tr.doko-go-to-screen.doko-'+idField ).hide();
     463            }
     464
     465
     466            if ( value == "limit-amount-in-current-step"  || value == "limit-amount-in-next-step"  ) {
     467                $('tr.doko-limit-product-number.doko-'+idField ).hide();
     468                $('tr.doko-limit-product-amount.doko-'+idField ).show();
     469                $('tr.doko-go-to-screen.doko-'+idField ).hide();
     470            }
     471
     472            if ( value == "go-to-step" ) {
     473                $('tr.doko-limit-product-number.doko-'+idField ).hide();
     474                $('tr.doko-limit-product-amount.doko-'+idField ).hide();
     475
     476                $('tr.doko-go-to-screen.doko-'+idField ).show();
     477            }
     478
     479
     480
     481        });
     482        elem.trigger('change');
     483    }
     484
     485
     486    var hs_dk_get_screen_product_list = function( bundleId, idField ) {
     487        var elem = $('select[name="doko['+idField+'][screen-name]"][data-bundle-id="'+bundleId+'"]');
     488
     489
     490
     491        elem.on('change', function() {
     492            var value = $(this).val();
     493            $.post(
     494                ajaxurl,
     495                {
     496                    bundle_id : bundleId,
     497                    screen  : value,
     498                    action : "doko_get_screen_products"
     499                }, function(r) {
     500                    var json = JSON.parse(r);
     501
     502                    if ( json.html ) {
     503                        $('select[name="doko['+idField+'][rule][]"][data-bundle-id="'+bundleId+'"]').html(json.html);
     504                        var jss = JSON.parse(window.doko_rule_list);
     505                        if ( undefined != jss[idField] ) {
     506                            var jrule = jss[idField]['rule'];
     507                            $('select[name="doko[' + idField + '][rule][]"][data-bundle-id="' + bundleId + '"]').val(jrule);
     508                            $('select[name="doko[' + idField + '][rule][]"][data-bundle-id="' + bundleId + '"]').select2({'width' : '100%' })
     509                        }
     510
     511                    }
     512
     513                }
     514            );
     515        });
     516        elem.trigger('change');
     517    }
     518
    398519     
    399520})( jQuery );
  • doko-box-builder/trunk/core/class-hs-doko-utils.php

    r3001399 r3047333  
    177177}
    178178
     179function hs_dk_get_products_query( $query ) {
     180    $query['post_type'] = array( 'product', 'product_variation' );
     181}
     182
     183
     184function hs_dk_display_variations_as_single_product( $query ) {
     185    $query->set( 'post_type', [ 'product', 'product_variation' ] );
     186}
     187
     188add_action('pre_get_posts', function (){
     189    add_action( 'woocommerce_product_query', 'hs_dk_display_variations_as_single_product');
     190    add_filter( 'woocommerce_shortcode_products_query', 'hs_dk_get_products_query' , 999 );
     191});
    179192
    180193if ( ! function_exists('hs_dk_display_products_from_categories' ) ) {
    181     function hs_dk_display_products_from_categories( $product_categories ){
    182         add_filter('woocommerce_product_related_products_heading', '__return_false' );
    183 
    184         $wc_query = wc_get_products( array(
    185             'post_type' => 'product',
    186             'post_status'=>'public',
    187             'tax_query' => array(
    188                     array(
    189                 'taxonomy' => 'product_cat',
    190                 'field'    => 'ids',
    191                 'terms'    => $product_categories,
    192                 'operator' => 'IN',
     194    function hs_dk_display_products_from_categories( $product_categories, $is_card_screen = false ){
     195
     196        $products = new WP_Query( array(
     197            'post_type'   => 'product',
     198            'post_status' => 'publish',
     199            'fields'      => 'ids',
     200            'tax_query'   => array(
     201                'relation' => 'AND',
     202                array(
     203                    'taxonomy' => 'product_cat',
     204                    'field'    => 'term_id',
     205                    'terms'    => $product_categories,
    193206                )
    194207            ),
    195             'stock_status'  => 'instock'
     208
    196209        ) );
    197210
    198 
    199         wc_get_template(
    200             'single-product/related.php',
    201             array(
    202                 'related_products' => $wc_query
     211        $products = $products->posts;
     212
     213        echo do_shortcode( '[doko_products ids="' . implode( ',', $products ) . '"   columns="3" order="ASC" is_card_screen="'.$is_card_screen.'"]' );
     214
     215    }
     216}
     217
     218if ( ! function_exists('hs_dk_get_allowed_slug') ) {
     219    function hs_dk_get_allowed_slug() {
     220        return apply_filters( 'doko_get_allowed_slugs', array(
     221            'post_type' => array(
     222                'doko-bundles',
     223                'doko-bundles-rules',
     224            ),
     225            'page' => array(
     226                'edit.php?post_type=doko-bundles&page=doko-settings'
    203227            )
    204         );
     228        ));
    205229    }
    206230}
    207231
     232
     233
     234function doko_display_products( $atts ){
     235    ob_start();
     236
     237    $atts = shortcode_atts(array(
     238        'ids' => '',
     239        'columns' => 3,
     240        'order' => 'ASC',
     241        'is_card_screen' => false
     242    ), $atts );
     243
     244    wc_get_template(
     245        'single-product/doko-products.php',
     246        array(
     247            'ids' => $atts['ids'],
     248            'columns' => $atts['columns'],
     249            'order_mode' => $atts['order'],
     250            'is_card_screen' => $atts['is_card_screen']
     251        )
     252    );
     253
     254    return ob_get_clean();
     255}
     256
     257
     258function doko_get_children_products( $all_products ) {
     259    $products = [];
     260    foreach( $all_products as $pdtId ) {
     261        $pdt = wc_get_product($pdtId);
     262        $childrens = $pdt->get_children();
     263        if ( count($childrens) > 0 ) {
     264            $dpt = [];
     265            foreach( $childrens as $pt ) {
     266                if ( is_object( $pt ) ) {
     267                    $dpt[] = $pt->get_id();
     268                } else {
     269                    $dpt[] = $pt;
     270                }
     271
     272            }
     273            $products = array_merge( $products, $dpt );
     274        } else {
     275            $products[] = $pdt->get_id();
     276        }
     277    }
     278
     279    return $products;
     280}
  • doko-box-builder/trunk/core/class-hs-doko.php

    r3001399 r3047333  
    159159    private function define_admin_hooks() {
    160160
    161             $plugin_admin = new Hs_Doko_Admin( $this->get_plugin_name(), $this->get_version() );
     161            $plugin_admin = new HS\Doko\Hs_Doko_Admin( $this->get_plugin_name(), $this->get_version() );
    162162            $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    163163            $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
     
    168168            $this->loader->add_action( 'wp_ajax_hs_dk_query_wc', $plugin_admin, 'query_wc' );
    169169            $this->loader->add_action( 'save_post_doko-bundles', $plugin_admin, 'save_package' );
     170            $this->loader->add_action( 'save_post_doko-bundles-rules', $plugin_admin, 'save_package' );
    170171            $this->loader->add_filter( 'enter_title_here', $plugin_admin, 'change_cpt_title' );
    171             $this->loader->add_filter( 'wp_ajax_doko_get_admin_screen', $plugin_admin, 'get_dynamic_contents' );
    172             $this->loader->add_filter( 'wp_ajax_doko_get_dynamic_rules', $plugin_admin, 'generate_dynamic_rules' );
     172            $this->loader->add_action( 'wp_ajax_doko_get_admin_screen', $plugin_admin, 'get_dynamic_contents' );
     173            $this->loader->add_action( 'wp_ajax_doko_get_dynamic_rules', $plugin_admin, 'generate_dynamic_rules' );
    173174            $this->loader->add_filter( 'manage_edit-doko-bundles_columns', $plugin_admin, 'get_columns' );
    174175            $this->loader->add_action( 'manage_doko-bundles_posts_custom_column', $plugin_admin, 'get_columns_values', 5, 2 );
    175             $this->loader->add_filter( 'wp_ajax_doko_save_dynamic_rules', $plugin_admin, 'save_dynamic_rules' );
    176 
    177     }
     176            $this->loader->add_action( 'wp_ajax_doko_save_dynamic_rules', $plugin_admin, 'save_dynamic_rules' );
     177            $this->loader->add_action( 'wp_ajax_doko_get_bundle_rule', $plugin_admin, 'get_dynamic_rules' );
     178            $this->loader->add_action( 'wp_ajax_doko_get_screen_products', $plugin_admin, 'get_screen_products' );
     179
     180
     181
     182    }
     183
    178184
    179185    /**
     
    184190     */
    185191    private function define_public_hooks() {
    186         $plugin_public = new Hs_Doko_Public( $this->get_plugin_name(), $this->get_version() );
     192        $plugin_public = new  HS\Doko\Hs_Doko_Public( $this->get_plugin_name(), $this->get_version() );
    187193
    188194        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
     
    199205        $this->loader->add_action( 'woocommerce_before_calculate_totals', $plugin_public, 'set_box_total_price' );
    200206        $this->loader->add_filter( 'woocommerce_loop_add_to_cart_link', $plugin_public, 'replace_default_btn_text', 9999 );
    201         $this->loader->add_filter( 'woocommerce_shortcode_products_query_results', $plugin_public, 'display_variations_separately' );
    202207        $this->loader->add_filter( 'woocommerce_loop_product_link', $plugin_public, 'disable_product_link', 9999 );
    203         $this->loader->add_filter( 'woocommerce_shortcode_products_query', $plugin_public, 'hide_out_of_stock_products', 30, 3 );
    204 
    205208    }
    206209
  • doko-box-builder/trunk/core/homescriptone-formulus.php

    r2925566 r3047333  
    158158
    159159                    foreach ($args['options'] as $option_key => $option_text) {
     160
     161
    160162                        $selected = '';
    161163                        if ('' === $option_key) {
     
    356358            'data-product-name'      => array(),
    357359            'data-image-url'        => array(),
     360            'data-bundle-id'         => array(),
     361            'data-bundle-rule-id'         => array(),
     362            'data-card-mode' => array()
    358363
    359364
  • doko-box-builder/trunk/hs-doko.php

    r3001399 r3047333  
    22
    33/**
    4  * The plugin bootstrap file
    5  *
    6  * This file is read by WordPress to generate the plugin information in the plugin
    7  * admin area. This file also core all of the dependencies used by the plugin,
    8  * registers the activation and deactivation functions, and defines a function
    9  * that starts the plugin.
    104 *
    115 * @link              https://ultiwp.com
     
    1711 * Plugin URI:        https://ultiwp.com
    1812 * Description:       Increase sales by letting your customers create custom bundles.
    19  * Version:           1.1.2
     13 * Version:           1.2
    2014 * Author:            UltiWP
    2115 * Author URI:        https://ultiwp.com
     
    2418 * Text Domain:       doko
    2519 * Domain Path:       /languages
     20 * Requires at least: 6.0
     21 * Requires PHP: 7.4
     22 * WC requires at least: 8.0.0
    2623 */
    2724
     
    3633 * Rename this for your plugin and update it as you release new versions.
    3734 */
    38 define( 'DOKO_VERSION', '1.1.2' );
     35define( 'DOKO_VERSION', '1.2' );
     36
     37add_action( 'before_woocommerce_init', function() {
     38        if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     39                    \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     40        }
     41});
    3942
    4043require plugin_dir_path( __FILE__ ) . 'core/premium-loading.php';
     
    6871
    6972
     73add_filter( 'wc_get_template_part',             'doko_override_woocommerce_template_part', 10, 3 );
     74// Override Template's.
     75add_filter( 'woocommerce_locate_template',      'doko_override_woocommerce_template', 10, 3 );
     76/**
     77 * Template Part's
     78 *
     79 * @param  string $template Default template file path.
     80 * @param  string $slug     Template file slug.
     81 * @param  string $name     Template file name.
     82 * @return string           Return the template part from plugin.
     83 */
     84function doko_override_woocommerce_template_part( $template, $slug, $name ) {
     85    $template_directory = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/';
     86    if ( $name ) {
     87        $path = $template_directory . "{$slug}-{$name}.php";
     88    } else {
     89        $path = $template_directory . "{$slug}.php";
     90    }
     91    return file_exists( $path ) ? $path : $template;
     92}
     93/**
     94 * Template File
     95 *
     96 * @param  string $template      Default template file  path.
     97 * @param  string $template_name Template file name.
     98 * @param  string $template_path Template file directory file path.
     99 * @return string                Return the template file from plugin.
     100 */
     101function doko_override_woocommerce_template( $template, $template_name, $template_path ) {
     102    $template_directory = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/';
     103    $path = $template_directory . $template_name;
     104    return file_exists( $path ) ? $path : $template;
     105}
     106
    70107
    71108/**
  • doko-box-builder/trunk/public/class-hs-doko-public.php

    r3001399 r3047333  
    1010 * @subpackage Hs_Doko/public
    1111 */
     12namespace HS\Doko;
     13
    1214/**
    1315 * The public-facing functionality of the plugin.
     
    101103            'all'
    102104        );
     105        wp_enqueue_style( 'jquery-ui' );
     106        wp_enqueue_style(
     107            'hs-quilljs-css',
     108            plugin_dir_url( __FILE__ ) . '../admin/css/hs-quilljs.css',
     109            array(),
     110            $this->version,
     111            'all'
     112        );
     113        wp_enqueue_style(
     114            'hs-quilljs-bubble-css',
     115            plugin_dir_url( __FILE__ ) . '../admin/css/hs-quilljs-bubble.css',
     116            array(),
     117            $this->version,
     118            'all'
     119        );
     120        wp_enqueue_style(
     121            'hs-doko-snackbar-css',
     122            plugin_dir_url( __FILE__ ) . 'css/hs-doko-snackbar.css',
     123            array(),
     124            $this->version,
     125            'all'
     126        );
     127        wp_enqueue_style(
     128            'hs-doko-card-css',
     129            plugin_dir_url( __FILE__ ) . 'css/hs-doko-card.css',
     130            array(),
     131            $this->version,
     132            'all'
     133        );
    103134    }
    104135   
     
    131162            $this->plugin_name,
    132163            plugin_dir_url( __FILE__ ) . 'js/hs-doko-public.js',
    133             array( 'jquery', 'wp-hooks', $this->plugin_name . '-modal' ),
     164            array( 'jquery', 'wp-hooks' ),
    134165            $this->version,
    135166            false
     
    138169            $this->plugin_name . '-utils',
    139170            plugin_dir_url( __FILE__ ) . 'js/hs-doko-utils.js',
    140             array(
    141             'jquery',
    142             $this->plugin_name,
    143             $this->plugin_name . '-modal',
    144             'wp-hooks'
    145         ),
     171            array( 'jquery', $this->plugin_name, 'wp-hooks' ),
    146172            $this->version,
    147173            false
    148174        );
    149175        wp_enqueue_script(
    150             $this->plugin_name,
     176            $this->plugin_name . "-fa",
    151177            plugin_dir_url( __FILE__ ) . 'js/fontawesome.min.js',
    152             array( 'jquery', $this->plugin_name . '-modal' ),
     178            array( 'jquery' ),
     179            $this->version,
     180            false
     181        );
     182        wp_enqueue_script(
     183            'hs-doko-snackbar',
     184            plugin_dir_url( __FILE__ ) . 'js/hs-doko-snackbar.js',
     185            array( 'jquery' ),
    153186            $this->version,
    154187            false
     
    161194         */
    162195        $data = apply_filters( 'doko_js_data_boxpage', array(
    163             'ajaxurl'           => admin_url( 'admin-ajax.php' ),
    164             'wc_price_args'     => array(
     196            'ajaxurl'              => admin_url( 'admin-ajax.php' ),
     197            'wc_price_args'        => array(
    165198            'html'                         => true,
    166199            'currency_symbol'              => get_woocommerce_currency_symbol( get_woocommerce_currency() ),
     
    171204            'price_format'                 => get_woocommerce_price_format(),
    172205        ),
    173             'next_message'      => esc_html__( 'Next', 'doko' ),
    174             'loading_message'   => $loading_message,
    175             'completed_message' => esc_html__( 'Your bundle is added to the cart, you will redirect to cart in few moments', 'doko' ),
    176             'cart_page_url'     => wc_get_cart_url(),
     206            'next_message'         => esc_html__( 'Next', 'doko' ),
     207            'loading_message'      => $loading_message,
     208            'completed_message'    => esc_html__( 'Your bundle is added to the cart, you will redirect to cart in few moments', 'doko' ),
     209            'cart_page_url'        => wc_get_cart_url(),
     210            'limit_product_number' => esc_html__( "You can't add more than %s products into the box." ),
     211            'limit_product_amount' => esc_html__( "You reached the limit of %s for this box." ),
    177212        ) );
    178213        wp_add_inline_script( $this->plugin_name, ' var doko_object=' . wp_json_encode( $data ) . ';' );
     214        wp_enqueue_script(
     215            $this->plugin_name . '-rules',
     216            plugin_dir_url( __FILE__ ) . 'js/hs-doko-rules.js',
     217            array(
     218            'jquery',
     219            'wp-hooks',
     220            $this->plugin_name,
     221            $this->plugin_name . '-utils'
     222        ),
     223            $this->version,
     224            false
     225        );
    179226    }
    180227   
     
    184231    public function init_shortcodes()
    185232    {
     233        global  $doko_is_card_page ;
     234        $doko_is_card_page = false;
     235        add_shortcode( 'doko_products', 'doko_display_products' );
    186236        add_shortcode( 'doko-bundles', array( $this, 'display_shortcode' ) );
    187237    }
    188238   
    189239    /**
     240     * Retrieve all rules related to a bundle.
     241     * @param $package_id string|integer Bundle Package Id
     242     * @return array
     243     */
     244    private function get_rules_by_bundle( $package_id )
     245    {
     246        $query_args_meta = array(
     247            'posts_per_page' => -1,
     248            'post_type'      => 'doko-bundles-rules',
     249            'post_status'    => 'publish',
     250            'meta_query'     => array(
     251            'relation' => 'AND',
     252            array(
     253            'key'     => 'doko',
     254            'value'   => $package_id,
     255            'compare' => 'LIKE',
     256        ),
     257        ),
     258            'fields'         => 'ids',
     259        );
     260        $rules_ids = get_posts( $query_args_meta );
     261        $rule_configs = array();
     262        foreach ( $rules_ids as $rule_id ) {
     263            $rule_configs[$rule_id] = get_post_meta( $rule_id, 'doko', true );
     264        }
     265        return $rule_configs;
     266    }
     267   
     268    /**
    190269     * Display the shortcode.
    191270     *
     
    196275    public function display_shortcode( $atts )
    197276    {
     277        global  $doko_is_card_page ;
    198278        $package_id = ( isset( $atts['id'] ) ? $atts['id'] : false );
    199279        $this->package_id = $package_id;
     
    226306        <?php
    227307        $counter = 1;
     308        $step_title = "";
     309        if ( isset( $package_data['box-description'] ) ) {
     310            $step_title = $package_data['box-description'];
     311        }
    228312        $fields_to_unset = Hs_Doko_Admin::get_data_to_unset();
    229313        foreach ( $fields_to_unset as $field ) {
     
    232316            }
    233317        }
     318        $step_identifier = array(
     319            1 => 'first-step',
     320        );
    234321        ?>
    235322        <div id="giftbox-progress-bar">
     
    263350        $step_nb = 2;
    264351        foreach ( $package_data as $key => $value ) {
     352            $step_identifier[$step_nb] = $key;
    265353            ?>
    266354                            <div class="step" data-step-id="<?php
     
    322410                <div class="hs-dk-box-selector hs-dk-bundle-page" id="doko-bundle-builder" data-page-id="<?php
    323411        echo  esc_attr( $counter ) ;
     412        ?>" data-bundle-content-id="<?php
     413        echo  esc_attr( 'first-step' ) ;
    324414        ?>">
    325415                    <?php
    326         if ( isset( $package_data['box-description'] ) ) {
    327             echo  wp_kses_post( $package_data['box-description'] ) ;
     416        if ( !empty($step_title) ) {
     417            echo  wp_kses_post( $step_title ) ;
    328418        }
    329419        ?>
     
    332422       
    333423        if ( 'products' === $box_selection_mode ) {
    334             echo  do_shortcode( '[products ids="' . implode( ',', $box_data ) . '"  orderby="date" columns="3" order="ASC"]' ) ;
     424            echo  do_shortcode( '[doko_products ids="' . implode( ',', $box_data ) . '"  columns="3" order="ASC"]' ) ;
    335425        } elseif ( 'categories' === $box_selection_mode ) {
    336426            hs_dk_display_products_from_categories( $box_data );
    337427        }
    338428       
     429        $doko_is_card_page = false;
    339430        ?>
    340431                </div>
     432                <script>
     433                    var doko_step_identifier = '<?php
     434        echo  json_encode( $step_identifier ) ;
     435        ?>'
     436                </script>
    341437        <?php
    342438        foreach ( $package_data as $bundle_id => $bundle_data ) {
     
    348444                $sdisposition = $bundle_data['screen-disposition'];
    349445                $is_pro = false;
     446                $doko_is_card_page = false;
    350447                if ( !$is_pro ) {
    351448                    $sdisposition = 'bundle-products';
     
    370467                    <?php
    371468                } elseif ( 'bundle-cart-content' == $sdisposition ) {
     469                } elseif ( 'bundle-card-page' == $sdisposition ) {
    372470                }
    373471           
     
    430528            'doko-box-container',
    431529            'doko-box-contents',
     530            'doko-card-page',
    432531        ) );
    433532        ?>
     
    471570            <script>
    472571                doko_object.screens = <?php
    473         echo  wp_json_encode( array_keys( $package_data ) ) ;
     572        $screens = array_keys( $package_data );
     573        echo  wp_json_encode( array_merge( array( 'first-step' ), $screens ) ) ;
    474574        ?>;
    475575            </script>
     
    500600            $data = $data['contents'];
    501601            $container = $data['container'];
    502             $contents = $data['contents'];
     602            $card_details = array();
     603            if ( isset( $data['card_details'] ) ) {
     604                $card_details = $data['card_details'];
     605            }
    503606            $product_id = $container['product_id'];
    504607            $quantity = $container['product_qty'];
    505             $variation_id = $container['variation_id'];
    506608            $product = wc_get_product( $product_id );
    507             $variation_attr = $product->get_attributes();
    508             if ( $variation_id === 0 ) {
     609           
     610            if ( isset( $container['variation_id'] ) && $container['variation_id'] != 0 ) {
     611                $variation_id = $container['variation_id'];
     612                $variation_attr = $product->get_default_attributes( 'edit' );
     613            } else {
     614                $variation_id = 0;
    509615                $variation_attr = array();
    510616            }
     617           
    511618            $total_price = $product->get_price() * $quantity;
    512619            $pdts = array();
    513             if ( !empty($data['contents']) ) {
    514                 foreach ( $contents as $content ) {
    515                     $total_price += $content['product_qty'] * $content['product_price'];
    516                     if ( empty($content) ) {
    517                         continue;
     620           
     621            if ( isset( $data['contents'] ) ) {
     622                $contents = $data['contents'];
     623                if ( isset( $data['contents']['card_details'] ) ) {
     624                    unset( $data['contents']['card_details'] );
     625                }
     626                if ( !empty($data['contents']) ) {
     627                    foreach ( $contents as $content ) {
     628                        $total_price += $content['product_qty'] * $content['product_price'];
     629                        if ( empty($content) ) {
     630                            continue;
     631                        }
     632                        $pdts[] = $content;
    518633                    }
    519                     $pdts[] = $content;
    520634                }
    521635            }
    522             $dcontents = array(
     636           
     637            $dcontents = array();
     638            $dcontents += array(
    523639                'box_contents' => $pdts,
    524640                'total_price'  => $total_price,
     
    566682                foreach ( $cart_item_key['box_contents'] as $screen_id => $screen_content ) {
    567683                    $product_id = $screen_content['product_id'];
    568                     $variation_id = $screen_content['variation_id'];
     684                    $variation_id = 0;
     685                    if ( isset( $screen_content['variation_id'] ) ) {
     686                        $variation_id = $screen_content['variation_id'];
     687                    }
    569688                    $price = $screen_content['product_price'];
    570689                    $qty = $screen_content['product_qty'];
     
    588707               
    589708                }
     709               
     710                if ( isset( $cart_item_key['card_details'] ) ) {
     711                    $card_details = $cart_item_key['card_details'];
     712                    $tproduct_name = "";
     713                    if ( isset( $card_details['to'] ) && $card_details['to'] != "" ) {
     714                        $tproduct_name .= "To : " . $card_details['to'];
     715                    }
     716                    if ( isset( $card_details['from'] ) && $card_details['from'] != "" ) {
     717                        $tproduct_name .= "<br/> From : " . $card_details['from'];
     718                    }
     719                    if ( isset( $card_details['message'] ) && $card_details['message'] != "" ) {
     720                        $tproduct_name .= "<br/> Message : " . $card_details['message'];
     721                    }
     722                    $children_product[] = array(
     723                        'key'   => "<a href='" . get_permalink( $card_details['product_id'] ) . "'>" . get_the_title( $card_details['product_id'] ) . '</a>',
     724                        'value' => $tproduct_name,
     725                    );
     726                }
     727               
    590728                if ( $display_children_price ) {
    591729                    $cart_item = array_merge( $cart_item, $children_product );
     
    641779                $product_url = wp_get_attachment_url( $product->get_image_id() );
    642780            }
     781            global  $doko_is_card_page ;
    643782            $btn_text = sprintf(
    644                 '<a style="cursor:pointer;" data-quantity="%s" data-product-id="%s" data-product-price="%s" data-site-currency="%s" data-product-name="%s" data-image-url="%s" class="%s" data-product-variation-parent-id="%s" >%s</a>',
     783                '<a style="cursor:pointer;" data-quantity="%s" data-product-id="%s" data-product-price="%s" data-site-currency="%s" data-product-name="%s" data-image-url="%s" class="%s" data-product-variation-parent-id="%s" data-card-mode="%s" >%s</a>',
    645784                esc_attr( ( isset( $args['quantity'] ) ? $args['quantity'] : 1 ) ),
    646785                $product->get_id(),
     
    651790                'button doko-add-to-box',
    652791                $product->get_parent_id(),
    653                 esc_html__( 'Add to box', 'doko' )
     792                ( $doko_is_card_page ? "yes" : "no" ),
     793                ( $doko_is_card_page ? esc_html__( 'Add card to box', 'doko' ) : esc_html__( 'Add to box', 'doko' ) )
    654794            );
    655795        }
     
    667807     * @return void
    668808     */
    669     public function add_box_contents_order_line( WC_Order_Item $item, $cart_item_key, $values )
     809    public function add_box_contents_order_line( $item, $cart_item_key, $values )
    670810    {
    671811       
    672812        if ( isset( $values['box_contents'] ) ) {
     813            $doko_children_products = array();
    673814            $item->update_meta_data( 'Original Price', wc_price( $values['container']['product_price'] ) );
    674815            foreach ( $values['box_contents'] as $screen_id => $screen_content ) {
    675816                $product_id = $screen_content['product_id'];
    676                 $variation_id = $screen_content['variation_id'];
     817                $variation_id = 0;
     818               
     819                if ( isset( $screen_content['variation_id'] ) && $screen_content['variation_id'] != 0 ) {
     820                    $product_id = $screen_content['variation_id'];
     821                    $variation_id = $screen_content['variation_id'];
     822                }
     823               
    677824                $price = $screen_content['product_price'];
    678825                $qty = $screen_content['product_qty'];
    679826                $product = wc_get_product( $product_id );
    680                 $ptype = $product->get_type();
    681827                $product_name = $product->get_name();
    682                
    683                 if ( 'variable' == $ptype && $variation_id != 0 ) {
    684                     $product = wc_get_product( $variation_id );
    685                     $product_name = $product->get_name();
     828                $item->update_meta_data( "<a href='" . get_permalink( $product_id ) . "'>" . $product_name . '</a>', wc_price( $price ) . '  x' . $qty );
     829                $data = array(
     830                    'qty'          => $qty,
     831                    'product_id'   => $product_id,
     832                    'variation_id' => $variation_id,
     833                );
     834                $doko_children_products[] = $data;
     835            }
     836           
     837            if ( isset( $values['card_details'] ) ) {
     838                $card_details = $values['card_details'];
     839                $tproduct_name = "";
     840                if ( isset( $card_details['to'] ) && $card_details['to'] != "" ) {
     841                    $tproduct_name .= "To : " . $card_details['to'];
    686842                }
    687                
    688                 $item->update_meta_data( "<a href='" . get_permalink( $product_id ) . "'>" . $product_name . '</a>', wc_price( $price ) . '  x' . $qty );
    689             }
    690             $item->add_meta_data( 'doko_bunble_id', $values['bundle_id'], true );
    691         }
    692    
    693     }
    694    
    695     /**
    696      * Display variations separately.
    697      *
    698      * @param mixed $a Query.
    699      *
    700      * @return mixed
    701      */
    702     public function display_variations_separately( $a )
    703     {
    704         $page_url_id = $this->get_page_id();
    705         $post_obj = get_post( $page_url_id );
    706        
    707         if ( has_shortcode( $post_obj->post_content, 'doko-bundles' ) || defined( 'DOING_AJAX' ) && DOING_AJAX ) {
    708             $product_ids = $a->ids;
    709             $list_product_ids = array();
    710             foreach ( $product_ids as $p_key => $product_id ) {
    711                 switch ( wc_get_product( $product_id )->get_type() ) {
    712                     case 'simple':
    713                         $list_product_ids[] = $product_id;
    714                         break;
    715                     case 'variable':
    716                         $variations = wc_get_product( $product_id )->get_children();
    717                         $list_product_ids = array_map( function ( $data ) {
    718                             return $data;
    719                         }, $variations );
    720                         break;
    721                     default:
    722                         /**
    723                          * Filter the product ids.
    724                          *
    725                          * @since 1.0.0
    726                          */
    727                         apply_filters( 'doko_edit_loop_products', $product_id );
    728                         break;
     843                if ( isset( $card_details['from'] ) && $card_details['from'] != "" ) {
     844                    $tproduct_name .= "<br/> From : " . $card_details['from'];
    729845                }
    730             }
    731             $a->ids = $list_product_ids;
    732         }
    733        
    734         return $a;
     846                if ( isset( $card_details['message'] ) && $card_details['message'] != "" ) {
     847                    $tproduct_name .= "<br/> Message : " . $card_details['message'];
     848                }
     849                $item->update_meta_data( "<a href='" . get_permalink( $card_details['product_id'] ) . "'>" . get_the_title( $card_details['product_id'] ) . '</a>', $tproduct_name );
     850                $doko_children_products[] = array(
     851                    'qty'        => $qty,
     852                    'product_id' => $product_id,
     853                );
     854            }
     855           
     856            $item->add_meta_data( 'doko_bundle_id', $values['bundle_id'], true );
     857            $item->add_meta_data( 'doko_children_bundle_ids', json_encode( $doko_children_products ) );
     858        }
     859   
    735860    }
    736861   
     
    768893    }
    769894   
    770     private function display_bundle_products_screen( $package_data )
     895    private function display_bundle_products_screen( $package_data, $is_card_screen = false )
    771896    {
    772897        $this->display_box_title( $package_data );
     
    778903       
    779904        if ( 'products' === $package_data['options'] ) {
    780             echo  do_shortcode( '[products ids="' . implode( ',', $package_data['products'] ) . '"  orderby="date" columns="3" order="ASC"]' ) ;
     905            echo  do_shortcode( '[doko_products ids="' . implode( ',', $package_data['products'] ) . '"  orderby="date" columns="3" order="ASC" is_card="$is_card_screen"]' ) ;
    781906        } elseif ( 'categories' === $package_data['options'] ) {
    782             hs_dk_display_products_from_categories( $package_data['categories'] );
     907            hs_dk_display_products_from_categories( $package_data['categories'], $is_card_screen );
    783908        }
    784909       
     
    797922    }
    798923   
    799     /**
    800      * @param $query_args
    801      * @param $atts
    802      * @param $loop_name
    803      * @return mixed
    804      */
    805     public function hide_out_of_stock_products( $query_args, $atts, $loop_name )
    806     {
    807         if ( $loop_name == 'products' && count( $this->get_data( $this->package_id ) ) > 0 ) {
    808             $query_args['meta_query'] = array( array(
    809                 'key'     => '_stock_status',
    810                 'value'   => 'instock',
    811                 'compare' => 'LIKE',
    812             ) );
    813         }
    814         return $query_args;
     924    private function display_card_content_page( $package_data )
     925    {
     926        ?>
     927        <div class="hs-dk-product-panel">
     928            <?php
     929        echo  $this->display_bundle_products_screen( $package_data, true ) ;
     930        ?>
     931        </div>
     932        <div class="hs-dk-product-card-panel">
     933            <div class="hs-dk-card_row_1">
     934            <h2><?php
     935        echo  esc_html__( 'Choose YOUR CARD', 'doko' ) ;
     936        ?></h2>
     937            <p class="hs-dk-card_text"><?php
     938        echo  esc_html__( 'Our team handwrites each and every note to keep.', 'doko' ) ;
     939        ?></p>
     940
     941        </div>
     942            <div class="hs-dk-doko_card_row_2">
     943
     944              <div class="hs-dk-card-image">
     945                <img src class="hs-dk-card-image" alt="Card Image">
     946                   <a class="hs-dk-change-card"><span>Change card</span></a>
     947              </div>
     948
     949              <div class="hs-dk-card-details">
     950
     951                    <div class="hs-dk-input-bloc">
     952
     953                        <div class="hs-dk-input-container">
     954                            <label for="to">To</label>
     955                            <input class="hs-dk-input-container-to" type="text" id="to" placeholder="To">
     956                        </div>
     957
     958                        <div class="hs-dk-input-container">
     959                            <label for="from">From</label>
     960                            <input class="hs-dk-input-container-from" type="text" id="from" placeholder="From">
     961                        </div>
     962
     963                    </div>
     964
     965                    <div class="hs-dk-message-container">
     966                        <!--label for="message">Add your personalized message here (optional)</label-->
     967                        <textarea id="message-box" placeholder="" max-length="160"></textarea>
     968                    </div>
     969
     970                    <p class="hs-dk-remaining-characters"><?php
     971        esc_html_e( '160 characters remaining', 'doko' );
     972        ?></p>
     973
     974
     975                    <div class="hs-dk-note-options">
     976                        <label class="hs-dk-customer-checkbox">
     977                            <input type="radio" name="doko-note-option" value="blank-card">
     978
     979                        <?php
     980        esc_html_e( " Leave card intentionally blank and we'll tuck the card in the bow for you to do what you need", 'doko' );
     981        ?>
     982                        </label>
     983                        <label class="hs-dk-customer-checkbox">
     984                            <input type="radio" name="doko-note-option" value="no-card">
     985                           <?php
     986        esc_html_e( ' No note or card needed! Just a to/from is fine!', 'doko' );
     987        ?>
     988                        </label>
     989                    </div>
     990
     991
     992                    <button href="#next" class="doko-page-btn button button-primary"  data-btn-type="next"><?php
     993        esc_html_e( 'ADD TO CART', 'doko' );
     994        ?></button>
     995
     996               </div>
     997
     998
     999
     1000        </div>
     1001        </div>
     1002        <?php
    8151003    }
    8161004
     
    8191007    $new_names = $names;
    8201008    foreach ( $new_names as $name_id => $name ) {
    821         if ( $name->key == 'doko_bunble_id' && !is_admin() ) {
     1009        if ( $name->key == 'doko_bundle_id' && !is_admin() ) {
     1010            unset( $new_names[$name_id] );
     1011        }
     1012        if ( $name->key == 'doko_children_bundle_ids' ) {
    8221013            unset( $new_names[$name_id] );
    8231014        }
     
    8251016    return $new_names;
    8261017}, 999 );
     1018add_action(
     1019    'woocommerce_reduce_order_item_stock',
     1020    function ( $item, $change, $order ) {
     1021   
     1022    if ( $item->get_meta( 'doko_bundle_id' ) ) {
     1023        $children_products = $item->get_meta( 'doko_children_bundle_ids' );
     1024        $children_products = json_decode( $children_products, true );
     1025        $changes = array();
     1026        foreach ( $children_products as $key => $value ) {
     1027            $product_id = $value['product_id'];
     1028            if ( isset( $value['variation_id'] ) && $value['variation_id'] != 0 ) {
     1029                $product_id = $value['variation_id'];
     1030            }
     1031            $stock_avail = get_post_meta( $product_id, '_manage_stock', true );
     1032           
     1033            if ( $stock_avail == "yes" ) {
     1034                $qty = $value['qty'];
     1035                $product = wc_get_product( $product_id );
     1036                $new_stock = wc_update_product_stock( $product, $qty, 'decrease' );
     1037                $changes[] = array(
     1038                    'product' => $product,
     1039                    'from'    => $new_stock + $qty,
     1040                    'to'      => $new_stock,
     1041                );
     1042            }
     1043       
     1044        }
     1045        wc_trigger_stock_change_notifications( $order, $changes );
     1046    }
     1047
     1048},
     1049    10,
     1050    3
     1051);
     1052add_action( 'woocommerce_restore_order_stock', function ( $order ) {
     1053    foreach ( $order->get_items() as $item ) {
     1054        if ( !$item->is_type( 'line_item' ) ) {
     1055            continue;
     1056        }
     1057        $children_products = $item->get_meta( 'doko_children_bundle_ids' );
     1058        $children_products = json_decode( $children_products, true );
     1059        foreach ( $children_products as $key => $value ) {
     1060            $product_id = $value['product_id'];
     1061            if ( isset( $value['variation_id'] ) && $value['variation_id'] != 0 ) {
     1062                $product_id = $value['variation_id'];
     1063            }
     1064            $stock_avail = get_post_meta( $product_id, '_manage_stock', true );
     1065            $qty = $value['qty'];
     1066            $product = wc_get_product( $product_id );
     1067           
     1068            if ( $stock_avail == "yes" ) {
     1069                wc_update_product_stock( $product, $qty, 'increase' );
     1070                $order->add_order_note( __( 'Stock levels of product ', 'woocommerce' ) . $product->get_formatted_name() . ' has increased of ' . $qty );
     1071            }
     1072       
     1073        }
     1074    }
     1075} );
  • doko-box-builder/trunk/public/js/hs-doko-public.js

    r3001399 r3047333  
    66    window.doko.box_container = "";
    77    window.doko.box_contents = {};
     8    window.doko.rules = {};
     9    window.doko.screens = {};
     10    window.doko.box_card = {};
     11
     12    let qty;
    813
    914    $(document).ready(function() {
     
    6772        $('div.hs-dk-bundle-page').hide()
    6873        $('div.hs-dk-bundle-page[data-page-id="1"]').show()
     74        $('div.hs-dk-menu-fix').hide()
     75        $('div.hs-dk-product-card-panel').hide()
    6976
    7077        var current_page = 1;
    7178        window.doko.current_page = current_page;
     79        $('div#giftbox-progress-bar div.step a').removeClass('completed');
     80        $('div#giftbox-progress-bar div.step[data-step-id="'+current_page+'"] a').addClass('completed');
    7281        $('button.doko-page-btn[data-btn-type="next"]').on('click', function() {
     82
    7383            if ( current_page + 1 > $('div.hs-dk-bundle-page').length ) {
    7484                return false;
     
    7787
    7888            if ( undefined != doko_bundle_data ) {
    79                 if ( "" == window.doko.box_container ) {
    80                     alert( doko_bundle_data['no-products-message'] );
    81                     return false;
     89                if ( wp.hooks.applyFilters('doko_restrict_first_page', true, current_page ) ) {
     90                    if ( "" == window.doko.box_container ) {
     91                        alert( doko_bundle_data['no-products-message'] );
     92                        return false;
     93                    }
    8294                }
    8395            }
     
    8799            }
    88100
     101            current_page++;
    89102            $('div.hs-dk-bundle-page').hide();
    90             current_page++;
    91103            $('div.hs-dk-bundle-page[data-page-id="'+current_page+'"]').show()
    92104            $('div#giftbox-progress-bar div.step a').removeClass('completed');
    93105            $('div#giftbox-progress-bar div.step[data-step-id="'+current_page+'"] a').addClass('completed');
    94106            window.doko.current_page = current_page;
    95 
    96107            wp.hooks.doAction( 'doko_after_click_navigate_to_page', current_page );
    97108        });
     
    104115            $('div.hs-dk-bundle-page').hide();
    105116            current_page--;
     117            console.log(current_page)
    106118            $('div.hs-dk-bundle-page[data-page-id="'+current_page+'"]').show()
    107119            $('div#giftbox-progress-bar div.step a').removeClass('completed');
     
    119131            window.location.href = doko_object.cart_page_url;
    120132        });
    121     });
    122 
    123 
    124     function hs_dk_init_delete_box_action( hash_code ) {
    125 
     133
     134
     135
     136
     137
     138
     139    function hs_dk_init_delete_box_action( hash_code , trigger= false ) {
     140
     141        var jsonId = JSON.parse(doko_step_identifier);
     142        var current_screen = window.doko.current_page;
     143
     144        var screenId = jsonId[current_screen];
    126145        if ( $('table.doko-box-contents').length > 0 ) {
    127146            $('table.doko-box-contents tr[data-product-id]').each( function() {
     
    131150                    var productQty= parseInt( $('table.doko-box-contents tr[data-product-id="' + product_id + '"]').data('productQty') );
    132151                    var price= parseFloat( $('table.doko-box-contents tr[data-product-id="' + product_id + '"]').data('productPrice') );
    133                     wp.hooks.doAction( 'doko_before_delete_product_from_box', product_id, productQty, price, total_price, stored_total_price )
    134 
     152                    wp.hooks.doAction( 'doko_before_delete_product_from_box', product_id, productQty, price );
     153                    delete window.doko.box_contents[product_id];
     154                    delete window.doko.screens[screenId][product_id];
     155
     156                    recalculate_total();
     157
     158                    $(this).parent().closest('tr').remove()
    135159                    $('ul.box-images li[data-product-id="'+product_id+'"]').remove();
    136                     $('table.doko-box-contents tr[data-product-id="' + product_id + '"]').remove();
    137                     $('ul.doko-footer-navigation li[data-product-id="'+product_id+'"]').remove();
    138                     var total_price = 0;
    139                     var stored_total_price = window.doko.total_price;
    140                     if ( hs_dk_has_decimals() ) {
    141                         total_price = parseFloat( hs_dk_get_wc_price( stored_total_price, false ) - (price * productQty) );
    142                     } else {
    143                         total_price = parseInt( hs_dk_get_wc_price( stored_total_price, false ) - (price * productQty) )
    144                     }
    145                     window.doko.total_price = total_price;
    146                     $('button.doko-total-btn').html('Total : '+ hs_dk_get_wc_price( window.doko.total_price  ) );
    147 
    148                     wp.hooks.doAction( 'doko_after_delete_product_from_box', product_id, productQty, price, total_price, stored_total_price )
    149                 })
     160                    $('ul.doko-box-contents li[data-product-id="' + product_id + '"]').remove();
     161
     162                    wp.hooks.doAction( 'doko_after_delete_product_from_box', product_id, productQty, price )
     163                });
    150164            });
    151165        }
     
    156170            var product_id =  $(this).closest('li').data('productId');
    157171            $(this).closest('li').remove();
    158             wp.hooks.doAction( 'doko_before_product_from_box', product_id, productQty, price, total_price, stored_total_price )
     172            wp.hooks.doAction( 'doko_before_delete_product_from_box', product_id, productQty, price )
     173            delete window.doko.box_contents[product_id];
     174            delete window.doko.screens[screenId][product_id];
     175            recalculate_total();
    159176            $('ul.box-images li[data-product-id="'+product_id+'"]').remove();
    160             $('table.doko-box-contents tr[data-product-id="' + product_id + '"]').remove();
    161             $('ul.doko-footer-navigation li[data-product-id="'+product_id+'"]').remove();
    162             var total_price = 0;
    163             var stored_total_price = window.doko.total_price;
    164 
    165             if ( hs_dk_has_decimals() ) {
    166                 total_price = parseFloat( hs_dk_get_wc_price( stored_total_price, false ) - ( hs_dk_get_wc_price( price, false ) * productQty) );
    167             } else {
    168                 total_price = parseInt( hs_dk_get_wc_price( stored_total_price, false ) - ( hs_dk_get_wc_price( price, false ) * productQty) )
    169             }
    170 
    171             window.doko.total_price = total_price;
    172             $('button.doko-total-btn').html('Total : '+ hs_dk_get_wc_price( window.doko.total_price  ) );
    173 
    174             wp.hooks.doAction( 'doko_delete_product_from_box', product_id, productQty, price, total_price, stored_total_price )
    175         });
    176 
    177     }
     177            $('ul.doko-box-contents li[data-product-id="' + product_id + '"]').remove();
     178            wp.hooks.doAction( 'doko_after_delete_product_from_box', product_id, productQty, price )
     179        });
     180
     181        if ( trigger ) {
     182            $('li[data-hash-code="'+hash_code+'"] div.doko-right-sup-exposant').trigger('click');
     183        }
     184
     185    }
     186
     187    window.hs_dk_init_delete_box_action = hs_dk_init_delete_box_action;
     188    window.hs_dk_recalculate_total      = recalculate_total;
    178189
    179190    /**
     
    219230    }
    220231
     232    window.hs_dk_get_wc_price = hs_dk_get_wc_price;
     233
    221234    function hs_dk_build_box_contents( product_qty, product_name, product_price, product_id ) {
    222235        var html = '<tr data-product-id="'+product_id+'" data-product-qty="'+product_qty+'" data-product-price="'+product_price+'"><td>'+product_name+'</td><td>'+product_qty+'</td><td>'+ product_price +'</td>'
     
    270283            var bundle_id = $('input[name="doko-bundle-page-id"]').val();
    271284            var productData = {}
     285            var cardMode = $(this).data('cardMode');
     286            window.doko.cardMode = cardMode;
     287
    272288
    273289            // generate code to get data of a parent of multilevel wih data-page-id and data-product-id
     
    281297            productData.current_page = dk_current_page;
    282298            productData.bundle_id = bundle_id;
    283             var total_price = window.doko.total_price;
    284299            var product_name = $(this).data('productName')
    285300
     
    288303            wp.hooks.doAction( 'doko_before_calculate_add_to_box', product_id, productData, window.doko.current_page, page_data );
    289304
    290             if ( hs_dk_has_decimals() ) {
    291                 product_price = parseFloat( hs_dk_get_wc_price( product_price, false ) );
    292                 total_price += product_price;
     305
     306            productData.variation_id = parent_variation_id;
     307
     308            wp.hooks.doAction('doko_after_calculate_add_to_box', product_id, productData, window.doko.current_page, page_data);
     309
     310            if ( "no" == cardMode ) {
     311                if ($('table.doko-box-contents').length > 0 && dk_current_page != 1) {
     312                    var box_contents_html;
     313                    box_contents_html = hs_dk_build_box_contents(product_quantity, product_name, product_price, product_id);
     314
     315                    if ($('table.doko-box-contents tbody tr[data-product-id="' + product_id + '"]').length == 0) {
     316                        $('table.doko-box-contents tbody').append(box_contents_html);
     317                        $('ul.box-images').append(hs_dk_build_img_block(product_img_url, false, productData ));
     318                    } else {
     319                        qty = $('ul.doko-box-contents li[data-product-id="' + product_id + '"] div.doko-qty-exposant').html();
     320                        box_contents_html = hs_dk_build_box_contents(qty, product_name, product_price, product_id);
     321                        $('table.doko-box-contents tr[data-product-id="' + product_id + '"]').replaceWith(box_contents_html)
     322                    }
     323
     324                }
     325
     326                $('div.hs-dk-menu-fix').show();
     327                hs_dk_init_delete_box_action(unique_id);
    293328            } else {
    294                 product_price = parseInt( product_price );
    295                 total_price += product_price;
    296             }
    297 
    298             productData.variation_id = parent_variation_id;
    299 
    300             window.doko.total_price = hs_dk_get_wc_price( total_price, false );
    301 
    302             wp.hooks.doAction( 'doko_after_calculate_add_to_box', product_id, productData,  window.doko.current_page, page_data );
    303 
    304             if ( $('table.doko-box-contents').length > 0 ) {
    305                 var box_contents_html ;
    306                 box_contents_html = hs_dk_build_box_contents( product_quantity, product_name, product_price,  product_id );
    307 
    308                 if ( $('table.doko-box-contents tbody tr[data-product-id="'+product_id+'"]').length == 0 ) {
    309                     $('table.doko-box-contents tbody').append(box_contents_html);
     329                $('div.hs-dk-menu-fix').hide();
     330                $('img.hs-dk-card-image').attr('src', product_img_url )
     331                $('div.hs-dk-product-card-panel').show()
     332                $('div.hs-dk-product-panel').hide()
     333                window.doko.box_card.product_id = product_id;
     334
     335            }
     336
     337            recalculate_total();
     338        });
     339
     340        $('a.hs-dk-change-card').on('click', function(){
     341            $('div.hs-dk-product-card-panel').hide()
     342            $('div.hs-dk-product-panel').show()
     343        });
     344
     345
     346        $('input.hs-dk-input-container-to').on('change', function(){
     347            window.doko.box_card.to = $(this).val()
     348        });
     349        $('input.hs-dk-input-container-to').trigger('change')
     350
     351        $('input.hs-dk-input-container-from').on('change', function(){
     352            window.doko.box_card.from = $(this).val()
     353        });
     354        $('input.hs-dk-input-container-from').trigger('change')
     355
     356        $('#message-box').on('change', function(){
     357            window.doko.box_card.message = $(this).val()
     358        });
     359        $('#message-box').trigger('change');
     360
     361
     362    }
     363
     364        function recalculate_total() {
     365            var screens = window.doko.screens;
     366            var total = 0;
     367
     368            for (var sc in screens) {
     369                var product = screens[sc];
     370
     371                if (product.qty !== undefined && product.amount !== undefined) {
     372                    total += product.qty * product.amount;
    310373                } else {
    311                     qty = product_quantity;
    312                     box_contents_html = hs_dk_build_box_contents( qty, product_name, product_price,  product_id );
    313                     $('table.doko-box-contents tr[data-product-id="'+product_id+'"]').replaceWith(box_contents_html)
     374                    for (var ccd in product) {
     375                        var data = product[ccd];
     376
     377                        if (data.qty !== undefined && data.amount !== undefined) {
     378                            total += data.qty * data.amount;
     379                        }
     380                    }
    314381                }
    315 
    316             }
    317 
    318             $('button.doko-total-btn').html('Total : '+ hs_dk_get_wc_price( window.doko.total_price ) );
    319             $('div.hs-dk-menu-fix').show();
    320 
    321             hs_dk_init_delete_box_action( unique_id );
    322         });
    323     }
     382            }
     383            window.doko.total_price = total;
     384
     385            $('button.doko-total-btn').html('Total : ' + hs_dk_get_wc_price( total, true ) );
     386        }
     387
     388
     389
     390
     391        function hs_dk_build_img_block( product_img_url, is_bottom = true, productData ){
     392
     393            var li_class_name ="";
     394            var div_class_name = "doko-icone-remove";
     395            var i_class_name  = "";
     396            if ( ! is_bottom ) {
     397                li_class_name = 'doko-reset-icone-remove';
     398                div_class_name = "doko-reset-icone";
     399            }
     400
     401            return "<li class='"+li_class_name+"' data-product-id='"+productData.productId+"'><i ' style='cursor: pointer;' aria-hidden='true'></i></div><a class='selected-box' ><img class='box-color' src='"+product_img_url+"'></a></li>";
     402        }
     403
     404    });
    324405
    325406
  • doko-box-builder/trunk/public/js/hs-doko-utils.js

    r3001399 r3047333  
    2626            var puid = productData['unique_id'];
    2727            var pvid = productData['variation_id'];
     28            var step_identifier = JSON.parse(doko_step_identifier);
    2829
    2930            if ( current_page == 1 ) {
    30                 if ( undefined != doko_bundle_data ) {
    31                     var enable_redirect = doko_bundle_data['enable-screen-redirect'];
    32                     // todo : enable single choice or multiple choices.
    33                     if ( "" != window.doko.box_container ) {
    34                         var pprice = window.doko.box_container['product_price'] * window.doko.box_container['product_qty'];
    35                         window.doko.total_price = parseFloat(window.doko.total_price) - parseFloat(pprice);
    36                     }
    37                     window.doko.box_container = {
    38                         product_id : pid,
    39                         product_qty: pqty,
    40                         product_price : pprice,
    41                         unique_id : puid,
    42                         variation_id : pvid
    43                     };
    44                     var elemUL =  $('ul.doko-box-container');
    45                     hs_dk_add_li_to_box( productData, elemUL, true,  true );
    46                     if ( "yes" == enable_redirect ){
    47                         $('button.doko-page-btn[data-btn-type="next"]').trigger('click');
     31                if ( wp.hooks.applyFilters('doko_execute_rule_on_page' , true , current_page ) ) {
     32                    if ( undefined != doko_bundle_data ) {
     33                        var enable_redirect = wp.hooks.applyFilters('doko_enable_first_page_redirect', doko_bundle_data['enable-screen-redirect'] , current_page );
     34                        if ( "" != window.doko.box_container ) {
     35                            var pprice = window.doko.box_container['product_price'] * window.doko.box_container['product_qty'];
     36                            window.doko.total_price = parseFloat(window.doko.total_price) - parseFloat(pprice);
     37                        }
     38                        window.doko.box_container = {
     39                            product_id : pid,
     40                            product_qty: pqty,
     41                            product_price : pprice,
     42                            unique_id : puid,
     43                            variation_id : pvid
     44                        };
     45                        window.doko.screens['first-step'] = {
     46                            qty : productData['quantity'],
     47                            amount : productData['productPrice']
     48                        }
     49
     50                        var elemUL =  $('ul.doko-box-container');
     51                        hs_dk_add_li_to_box( productData, elemUL, true,  true );
     52
     53                        if ( "yes" == enable_redirect ){
     54                            $('ul.doko-btn-navigation button.doko-page-btn[data-btn-type="next"]').trigger('click');
     55                        }
    4856                    }
    4957                }
    5058            } else {
    51                 var elemUL =  $('ul.doko-box-contents');
    52                 hs_dk_add_li_to_box( productData, elemUL, false,  true );
     59                if ( wp.hooks.applyFilters('doko_execute_rule_on_page' , true , current_page ) ) {
     60                    var elemUL =  $('ul.doko-box-contents');
     61                    if ( wp.hooks.applyFilters('doko_add_product_to_navigation', true , current_page ) ) {
     62                        hs_dk_add_li_to_box( productData, elemUL, false,  true );
     63                    }
    5364
    54                 if ( window.doko.box_contents.hasOwnProperty( pid ) ) {
    55                     window.doko.box_contents[pid]['product_qty'] += 1;
    56                 } else {
    57                     window.doko.box_contents[pid] =  {
    58                         product_id : pid,
    59                         product_qty: pqty,
    60                         product_price : pprice,
    61                         unique_id : puid,
    62                         variation_id : pvid
    63                     };
     65                    if ( window.doko.box_contents.hasOwnProperty( pid ) ) {
     66                        window.doko.box_contents[pid]['product_qty'] += pqty;
     67                        window.doko.screens[step_identifier[current_page]][pid]['qty'] += productData['quantity'];
     68
     69                    } else {
     70                        if ( window.doko.cardMode == "no" ) {
     71                            window.doko.box_contents[pid] =  {
     72                                product_id : pid,
     73                                product_qty: pqty,
     74                                product_price : pprice,
     75                                unique_id : puid,
     76                                variation_id : pvid
     77                            };
     78
     79                            var sidentifier = step_identifier[current_page];
     80                            if ( undefined == window.doko.screens[sidentifier] ) {
     81                                window.doko.screens[sidentifier] = {}
     82                            }
     83
     84                            if ( undefined == window.doko.screens[sidentifier][pid] ) {
     85                                window.doko.screens[sidentifier][pid] = {}
     86                            }
     87
     88
     89                            window.doko.screens[sidentifier][pid] = {
     90                                qty : productData['quantity'],
     91                                amount : productData['productPrice']
     92                            }
     93                        }
     94                    }
    6495                }
    65                
    66 
    6796            }
    68         }, 10, 3);
     97            wp.hooks.doAction('doko_execute_rule', current_page, pid, pqty, pprice, puid, pvid );
     98        }, 30, 3);
    6999
    70100        wp.hooks.addAction('doko_delete_product_from_box', 'doko', function( product_id ) {
     
    82112                    'contents' : window.doko.box_contents,
    83113                    'total_price' : window.doko.total_price,
     114                    'card_details' : window.doko.box_card
    84115                }
    85116                $.post(
     
    88119                        contents : doko_products,
    89120                        bundle_id : $('div[data-bundle-id]').data('bundleId'),
     121
    90122                    }, function( response ) {
    91123                        var json_resp = JSON.parse( response );
     
    97129                            $('div.doko-spinner-loading').show();
    98130                            $('div.doko-spinner-complete').hide();
     131                            // todo : add the ability to display error messages.
    99132                        }
    100133                    }
     
    116149
    117150            if ( remove ) {
     151                // responsible for the box container.
    118152                $(parent_sibling).empty();
    119153                var html = "<li class='"+li_class_name+"' data-product-qty='"+qty+"' data-product-price='"+product_price+"' data-product-id='"+product_id+"' data-hash-code='"+hash_code+"'><i style='cursor: pointer;' aria-hidden='true'></i><a class='selected-box' ><img class='box-color' src='"+product_img_url+"'></a> "
     
    126160                $(parent_sibling).append(html).css('display','flex').css('list-style-type', 'none')
    127161                $(parent_sibling).find('li img').css('height','56px');
     162                window.doko.rules = {}
    128163            } else {
    129 
     164                // responsible for the box contents.
    130165                if ( $(parent_sibling).find('li[data-product-id="'+product_id+'"]').length > 0 ) {
    131166                    var product_qty = $(parent_sibling).find('li[data-product-id="'+product_id+'"]').attr('data-product-qty');
     
    151186
    152187})( jQuery );
     188
     189function check_in_list( value, array ) {
     190    return array.indexOf(value) > -1;
     191}
     192
     193window.hs_dk_check_in_list = check_in_list;
Note: See TracChangeset for help on using the changeset viewer.