Plugin Directory

Changeset 1249434


Ignore:
Timestamp:
09/19/2015 11:17:02 PM (11 years ago)
Author:
d363f86b
Message:

Issue with Quick Order fixed

Location:
bulk-photo-to-product-importer-extension-for-woocommerce/trunk
Files:
1 added
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • bulk-photo-to-product-importer-extension-for-woocommerce/trunk/assets/js/admin.js

    r1245657 r1249434  
    1616            var today = [d.getMonth()+1,d.getDate(),d.getFullYear()];
    1717            today = today.join("/");
    18             console.log(today.toString());
    1918            $('.datepicker').datepicker("setDate", today);
    2019           
  • bulk-photo-to-product-importer-extension-for-woocommerce/trunk/bptpi.php

    r1246386 r1249434  
    66Author: The Portland Company, Designed by Spencer Hill, Coded by Redeye Adaya
    77Author URI: http://www.theportlandcompany.com
    8 Version: 2.4.1
     8Version: 2.4.3
    99Copyright: 2015 The Portland Company
    1010License: GPL v3
     
    2424     * @var string
    2525     */
    26     public $version = '2.4.1';
     26    public $version = '2.4.3';
    2727
    2828    /**
  • bulk-photo-to-product-importer-extension-for-woocommerce/trunk/classes/ajax.php

    r1245657 r1249434  
    44 * Description of ajax
    55 */
    6 class PTPImporter_Ajax {
    7 
    8     public function __construct() {
    9 
    10         add_action( 'wp_ajax_ptp_product_upload', array($this, 'product_upload') );
    11         add_action( 'wp_ajax_ptp_product_select', array($this, 'product_select') );
    12         add_action( 'wp_ajax_ptp_product_import', array($this, 'product_import') );
    13         add_action( 'wp_ajax_ptp_product_delete', array($this, 'product_delete') );
    14 
    15         add_action( 'wp_ajax_ptp_products_add_to_cart', array($this, 'products_add_to_cart') );
    16         add_action( 'wp_ajax_nopriv_ptp_products_add_to_cart', array($this, 'products_add_to_cart') );
    17 
    18         add_action( 'wp_ajax_ptp_dropdown_bulk_import_categories', array($this, 'dropdown_bulk_import_categories') );
    19         add_action( 'wp_ajax_ptp_dropdown_variation_groups', array($this, 'dropdown_variation_groups') );
    20 
    21         add_action( 'wp_ajax_ptp_variations_group_edit_form', array($this, 'variations_group_edit_form') );
    22         add_action( 'wp_ajax_ptp_variations_group_add', array($this, 'variations_group_add') );
    23         add_action( 'wp_ajax_ptp_variations_group_update', array($this, 'variations_group_update') );
    24         add_action( 'wp_ajax_ptp_variations_group_delete', array($this, 'variations_group_delete') );
    25         add_action( 'wp_ajax_ptp_variations_group_delete_dialog', array($this, 'variations_group_delete_dialog') );
    26         add_action( 'wp_ajax_ptp_variations_group_migrate', array($this, 'variations_group_migrate') );
    27 
    28         add_action( 'wp_ajax_ptp_settings_save', array($this, 'settings_save') );
    29 
    30         add_action( 'wp_ajax_ptp_category_quick_add', array($this, 'category_quick_add') );
    31         add_action( 'wp_ajax_ptp_category_quick_add_form', array($this, 'category_quick_add_form') );
    32         add_action( 'wp_ajax_ptp_category_list', array($this, 'category_list') );
     6class PTPImporter_Ajax
     7{
     8
     9    public function __construct()
     10    {
     11
     12        add_action('wp_ajax_ptp_product_upload', array($this, 'product_upload'));
     13        add_action('wp_ajax_ptp_product_select', array($this, 'product_select'));
     14        add_action('wp_ajax_ptp_product_import', array($this, 'product_import'));
     15        add_action('wp_ajax_ptp_product_delete', array($this, 'product_delete'));
     16
     17        add_action('wp_ajax_ptp_products_add_to_cart', array($this, 'products_add_to_cart'));
     18        add_action('wp_ajax_nopriv_ptp_products_add_to_cart', array($this, 'products_add_to_cart'));
     19
     20        add_action('wp_ajax_ptp_dropdown_bulk_import_categories', array($this, 'dropdown_bulk_import_categories'));
     21        add_action('wp_ajax_ptp_dropdown_variation_groups', array($this, 'dropdown_variation_groups'));
     22
     23        add_action('wp_ajax_ptp_variations_group_edit_form', array($this, 'variations_group_edit_form'));
     24        add_action('wp_ajax_ptp_variations_group_add', array($this, 'variations_group_add'));
     25        add_action('wp_ajax_ptp_variations_group_update', array($this, 'variations_group_update'));
     26        add_action('wp_ajax_ptp_variations_group_delete', array($this, 'variations_group_delete'));
     27        add_action('wp_ajax_ptp_variations_group_delete_dialog', array($this, 'variations_group_delete_dialog'));
     28        add_action('wp_ajax_ptp_variations_group_migrate', array($this, 'variations_group_migrate'));
     29
     30        add_action('wp_ajax_ptp_settings_save', array($this, 'settings_save'));
     31
     32        add_action('wp_ajax_ptp_category_quick_add', array($this, 'category_quick_add'));
     33        add_action('wp_ajax_ptp_category_quick_add_form', array($this, 'category_quick_add_form'));
     34        add_action('wp_ajax_ptp_category_list', array($this, 'category_list'));
    3335
    3436        // Mini cart
    35         add_action( 'wp_ajax_nopriv_ptp_get_refreshed_fragments', array( $this, 'get_refreshed_fragments' ) );
    36         add_action( 'wp_ajax_ptp_get_refreshed_fragments', array( $this, 'get_refreshed_fragments' ) );
    37 
    38         add_action( 'wp_ajax_ptp_activate', array( $this, 'activate' ) );
    39         add_action( 'wp_ajax_ptp_deactivate', array( $this, 'deactivate' ) );
    40     }
    41 
    42     public function dropdown_bulk_import_categories() {
    43         check_ajax_referer( 'ptp_nonce' );
    44 
    45         echo json_encode( array(
    46             'success' => true,
    47             'html' => ptp_dropdown_categories( array( 'name' => $_POST['name'], 'show_option_none' => 'Select Event', 'walker' => new Walker_Without_Children() ) )
    48         ) );
    49 
    50         exit;
    51     }
    52 
    53     public function dropdown_variation_groups() {
    54         check_ajax_referer( 'ptp_nonce' );
     37        add_action('wp_ajax_nopriv_ptp_get_refreshed_fragments', array($this, 'get_refreshed_fragments'));
     38        add_action('wp_ajax_ptp_get_refreshed_fragments', array($this, 'get_refreshed_fragments'));
     39        add_action('wp_ajax_nopriv_ptp_remove_cart_item', array($this, 'remove_cart_item'));
     40        add_action('wp_ajax_ptp_remove_cart_item', array($this, 'remove_cart_item'));
     41
     42        add_action('wp_ajax_ptp_activate', array($this, 'activate'));
     43        add_action('wp_ajax_ptp_deactivate', array($this, 'deactivate'));
     44    }
     45
     46    public function dropdown_bulk_import_categories()
     47    {
     48        check_ajax_referer('ptp_nonce');
     49
     50        echo json_encode(array(
     51            'success' => true,
     52            'html' => ptp_dropdown_categories(array('name' => $_POST['name'], 'show_option_none' => 'Select Event', 'walker' => new Walker_Without_Children()))
     53        ));
     54
     55        exit;
     56    }
     57
     58    public function dropdown_variation_groups()
     59    {
     60        check_ajax_referer('ptp_nonce');
    5561
    5662        global $wpdb, $ptp_importer;
     
    5965
    6066        // Nothing to exclude & pre-select
    61         if ( !$variation_group_id || $variation_group_id == '-1' ) {
    62             echo json_encode( array(
     67        if (!$variation_group_id || $variation_group_id == '-1') {
     68            echo json_encode(array(
    6369                'success' => true,
    6470                'html' => ptp_dropdown_categories(
    65                     array( 
    66                         'name' => 'variation_group', 
    67                         'class' => 'variation-group', 
    68                         'taxonomy' => $ptp_importer->taxonomy, 
    69                         'show_option_none' => 
    70                         'Select Variation Group',
    71                         'walker' => new Walker_With_Variations() 
    72                     ) 
     71                    array(
     72                        'name' => 'variation_group',
     73                        'class' => 'variation-group',
     74                        'taxonomy' => $ptp_importer->taxonomy,
     75                        'show_option_none' =>
     76                            'Select Variation Group',
     77                        'walker' => new Walker_With_Variations()
     78                    )
    7379                )
    74             ) );
     80            ));
    7581
    7682            exit;
     
    7985        $sql = "SELECT `term_id`";
    8086        $sql .= " FROM {$wpdb->term_taxonomy}";
    81         $sql .= " WHERE {$wpdb->term_taxonomy}.term_id != '%s'"; 
     87        $sql .= " WHERE {$wpdb->term_taxonomy}.term_id != '%s'";
    8288        $sql .= " AND {$wpdb->term_taxonomy}.taxonomy = '%s'";
    8389        $sql .= " GROUP BY {$wpdb->term_taxonomy}.term_id";
    8490
    85         $groups = $wpdb->get_results( $wpdb->prepare( $sql, $variation_group_id, $ptp_importer->taxonomy ) );
     91        $groups = $wpdb->get_results($wpdb->prepare($sql, $variation_group_id, $ptp_importer->taxonomy));
    8692        $exclude = array();
    8793
    88         foreach ( $groups as $group ) {
     94        foreach ($groups as $group) {
    8995            $exclude[] = (int)$group->term_id;
    9096        }
    9197
    92         echo json_encode( array(
     98        echo json_encode(array(
    9399            'success' => true,
    94100            'html' => ptp_dropdown_categories(
    95                 array( 
    96                     'name' => 'variation_group', 
    97                     'class' => 'variation-group', 
    98                     'taxonomy' => $ptp_importer->taxonomy, 
    99                     'show_option_none' => 
    100                     'Select Variation Group',
     101                array(
     102                    'name' => 'variation_group',
     103                    'class' => 'variation-group',
     104                    'taxonomy' => $ptp_importer->taxonomy,
     105                    'show_option_none' =>
     106                        'Select Variation Group',
    101107                    'exclude' => $exclude,
    102                     'selected' =>  $variation_group_id,
    103                     'walker' => new Walker_With_Variations() 
    104                 ) 
     108                    'selected' => $variation_group_id,
     109                    'walker' => new Walker_With_Variations()
     110                )
    105111            )
    106         ) );
    107 
    108         exit;
    109     }
    110 
    111     public function product_upload() {
    112         check_ajax_referer( 'ptp_product_upload', 'ptp_nonce' );
    113 
    114         $object_id = isset( $_REQUEST['object_id'] ) ? intval( $_REQUEST['object_id'] ) : 0;
     112        ));
     113
     114        exit;
     115    }
     116
     117    public function product_upload()
     118    {
     119        check_ajax_referer('ptp_product_upload', 'ptp_nonce');
     120
     121        $object_id = isset($_REQUEST['object_id']) ? intval($_REQUEST['object_id']) : 0;
    115122        $photos_obj = PTPImporter_Product::getInstance();
    116         $response = $photos_obj->upload_file( $object_id );
    117 
    118         if ( !$response['success'] ) {
    119             echo json_encode( array(
     123        $response = $photos_obj->upload_file($object_id);
     124
     125        if (!$response['success']) {
     126            echo json_encode(array(
    120127                'success' => false,
    121128                'error' => $response['error']
    122             ) );
    123 
    124             exit;
    125         }
    126 
    127         $file = $photos_obj->get_file( $response['file_id'] );
    128         $html = ptp_uploaded_item_html( $file );
    129 
    130         echo json_encode( array(
     129            ));
     130
     131            exit;
     132        }
     133
     134        $file = $photos_obj->get_file($response['file_id']);
     135        $html = ptp_uploaded_item_html($file);
     136
     137        echo json_encode(array(
    131138            'success' => true,
    132139            'content' => $html
    133         ) );
    134 
    135         exit;
    136     }
    137     public function product_select() {
    138         check_ajax_referer( 'ptp_product_select', 'ptp_nonce' );
    139         global $ptp_importer;
    140         $watermarker = get_post_meta($_POST['id'],$ptp_importer->attachment_meta_key);
    141         if(empty($watermarker))
    142         {
    143             $file_loc = get_attached_file($_POST['id']);
    144             update_post_meta( $_POST['id'], $ptp_importer->attachment_meta_key, 'yes' );
    145         }
    146         $photos_obj = PTPImporter_Product::getInstance();
    147         $file = $photos_obj->get_file( $_POST['id'] );
    148         $html = ptp_uploaded_item_html( $file );
    149 
    150         echo json_encode( array(
     140        ));
     141
     142        exit;
     143    }
     144
     145    public function product_select()
     146    {
     147        check_ajax_referer('ptp_product_select', 'ptp_nonce');
     148        global $ptp_importer;
     149        $watermarker = get_post_meta($_POST['id'], $ptp_importer->attachment_meta_key);
     150        if (empty($watermarker)) {
     151            $file_loc = get_attached_file($_POST['id']);
     152            update_post_meta($_POST['id'], $ptp_importer->attachment_meta_key, 'yes');
     153        }
     154        $photos_obj = PTPImporter_Product::getInstance();
     155        $file = $photos_obj->get_file($_POST['id']);
     156        $html = ptp_uploaded_item_html($file);
     157
     158        echo json_encode(array(
    151159            'success' => true,
    152160            'content' => $html
    153         ) );
    154 
    155         exit;
    156     }
    157 
    158     public function product_delete() {
    159         check_ajax_referer( 'ptp_nonce' );
    160 
    161         $file_id = (isset( $_POST['file_id'] )) ? intval( $_POST['file_id'] ) : 0;
     161        ));
     162
     163        exit;
     164    }
     165
     166    public function product_delete()
     167    {
     168        check_ajax_referer('ptp_nonce');
     169
     170        $file_id = (isset($_POST['file_id'])) ? intval($_POST['file_id']) : 0;
    162171
    163172        $photos_obj = PTPImporter_Product::getInstance();
     
    174183        }
    175184        */
    176         echo json_encode( array(
     185        echo json_encode(array(
    177186            'success' => true
    178         ) );
    179 
    180         exit;
    181     }
    182 
    183     public function product_import() {
    184         check_ajax_referer( 'ptp_product_import', 'ptp_nonce' );
     187        ));
     188
     189        exit;
     190    }
     191
     192    public function product_import()
     193    {
     194        check_ajax_referer('ptp_product_import', 'ptp_nonce');
    185195
    186196        $photos_obj = PTPImporter_Product::getInstance();
    187197
    188         $post_ids = $photos_obj->create( $_POST );
    189 
    190         if ( !$post_ids ) {
    191             echo json_encode( array(
     198        $post_ids = $photos_obj->create($_POST);
     199
     200        if (!$post_ids) {
     201            echo json_encode(array(
    192202                'success' => false,
    193203                'error' => $post_ids
    194             ) );
     204            ));
    195205
    196206            exit;
     
    198208
    199209        global $ptp_importer;
    200         $groups = (array) ptp_get_term_meta( $_POST['term_id'], $ptp_importer->term_variation_groups_meta_key, true );
    201         if( !in_array( $_POST['variation_group'], $groups ) ) {
     210        $groups = (array)ptp_get_term_meta($_POST['term_id'], $ptp_importer->term_variation_groups_meta_key, true);
     211        if (!in_array($_POST['variation_group'], $groups)) {
    202212            $groups[] = $_POST['variation_group'];
    203213        }
    204         ptp_update_term_meta( $_POST['term_id'], $ptp_importer->term_variation_groups_meta_key, $groups );
     214        ptp_update_term_meta($_POST['term_id'], $ptp_importer->term_variation_groups_meta_key, $groups);
    205215
    206216        // Associate variation group with term
    207         ptp_update_term_meta( $_POST['term_id'], $ptp_importer->term_variation_group_meta_key, $_POST['variation_group'] );
    208 
    209         do_action( 'ptp_product_import_complete', $_POST );
    210 
    211         echo json_encode( array(
     217        ptp_update_term_meta($_POST['term_id'], $ptp_importer->term_variation_group_meta_key, $_POST['variation_group']);
     218
     219        do_action('ptp_product_import_complete', $_POST);
     220
     221        echo json_encode(array(
    212222            'success' => true
    213         ) );
    214 
    215         exit;
    216     }
    217 
    218     public function products_add_to_cart() {
    219         check_ajax_referer( 'ptp_products_add_to_cart', 'ptp_nonce' );
    220        
    221  $product_id = array();
     223        ));
     224
     225        exit;
     226    }
     227
     228    public function products_add_to_cart()
     229    {
     230        check_ajax_referer('ptp_products_add_to_cart', 'ptp_nonce');
     231
     232        $product_id = array();
    222233
    223234        global $woocommerce;
    224         $found = false;
    225235        $posted = $_POST;
    226236
    227 //print_r($posted); die("die here");
    228         if ( !isset( $posted['ptp_grouped_products'] ) ) {
    229 
    230             echo json_encode( array(
     237        if (!isset($posted['ptp_grouped_products'])) {
     238
     239            echo json_encode(array(
    231240                'success' => false,
    232241                'error' => 'Queue is empty.'
    233             ) );
    234 
    235             exit;
    236         }
    237 //print_r($posted['ptp_grouped_products']);
    238 $variation_name = $posted['variation'];
    239         foreach ( $posted['ptp_grouped_products'] as $grouped_product_id ) {
    240 
    241      $version_value = get_option('_transient_product-transient-version');
    242 
    243    $variations = get_option( '_transient_wc_product_children_ids_' . $grouped_product_id.$version_value  );
    244             if ( sizeof( $variations ) == 0 ) { continue; }
    245 
    246 foreach($variations as $variationval) {
    247 $varvalue = get_post_meta($variationval, '_downloadable', true);
    248 
    249 if($varvalue == 'yes' && ($variation_name == 'Downloadable' OR $variation_name == 'downloadable') ){
    250 $product_id = $variationval;
    251 
    252 } else if($varvalue == 'no' && ($variation_name != 'Downloadable') ) {
    253 $product_id = $variationval;
    254 }
    255 
    256 }
    257 
    258        //     foreach ( $variations as $variation ) {
    259           //       $product_id[] = $variation;
    260                  //   break;
    261 //}
    262 
    263 
    264             // If no items in cart, add product directly
    265             if ( sizeof( $woocommerce->cart->get_cart() ) == 0 ) {
    266     foreach($product_id as $product_id) {
    267              $woocommerce->cart->add_to_cart( $product_id );
    268 }           
    269             //  continue;
     242            ));
     243
     244            exit;
     245        }
     246        $variation_name = $posted['variation'];
     247
     248
     249        foreach ($posted['ptp_grouped_products'] as $grouped_product_id) {
     250
     251            $version_value = get_option('_transient_product-transient-version');
     252
     253            $variations = get_option('_transient_wc_product_children_ids_' . $grouped_product_id . $version_value);
     254            if (sizeof($variations) == 0) {
     255                continue;
    270256            }
    271257
    272             // If there are items in cart, check if the product is added already
    273             foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    274          
    275                 if ( $_product->id == $product_id ) {
    276 
    277                     $found = true;
    278                 }
     258            foreach ($variations as $variationval) {
     259                $varvalue = get_post_meta($variationval, '_downloadable', true);
     260                $variation_db_name = get_the_title($variationval);
     261
     262
     263                if ($varvalue == 'yes' && $variation_name == $variation_db_name /*&& ($variation_name == 'Downloadable' OR $variation_name == 'downloadable')*/) {
     264                    $product_id[] = $variationval;
     265
     266                } /*else if ($varvalue == 'no' && ($variation_name != 'Downloadable')) {
     267                    $product_id[] = $variationval;
     268                }*/
     269
    279270            }
    280271
    281                
    282             // if product not found, add it
    283             if ( !$found ) {
    284                 $woocommerce->cart->add_to_cart( $product_id );
     272
     273            foreach ($product_id as $prod_id) {
     274                $woocommerce->cart->add_to_cart($prod_id);
    285275            }
    286276        }
    287277
    288         echo json_encode( array(
     278        echo json_encode(array(
    289279            'success' => true
    290         ) );
    291 
    292         exit;
    293     }
    294 
    295     public function settings_save() {
    296         check_ajax_referer( 'ptp_settings_save', 'ptp_nonce' );
    297        
    298         $posted = $_POST;
     280        ));
     281
     282        exit;
     283    }
     284
     285    public function settings_save()
     286    {
     287        check_ajax_referer('ptp_settings_save', 'ptp_nonce');
     288
     289        $posted = $_POST;
    299290        $settings_obj = PTPImporter_Settings::getInstance();
    300         $result = $settings_obj->update( $posted );
    301 
    302         if ( !$result ) {
    303             echo json_encode( array(
     291        $result = $settings_obj->update($posted);
     292
     293        if (!$result) {
     294            echo json_encode(array(
    304295                'success' => false,
    305296                'error' => $result
    306             ) );
    307 
    308             exit;
    309         }
    310 
    311         echo json_encode( array(
     297            ));
     298
     299            exit;
     300        }
     301
     302        echo json_encode(array(
    312303            'success' => true
    313         ) );
    314 
    315         exit;
    316     }
    317 
    318     public function variations_group_edit_form() {
    319         check_ajax_referer( 'ptp_nonce' );
     304        ));
     305
     306        exit;
     307    }
     308
     309    public function variations_group_edit_form()
     310    {
     311        check_ajax_referer('ptp_nonce');
    320312
    321313        $posted = $_POST;
    322314
    323315        $variations_obj = PTPImporter_Variation_Group::getInstance();
    324         $group = $variations_obj->group( $posted['term_id'] );
    325 
    326         if ( !$group ) {
    327             echo json_encode( array(
     316        $group = $variations_obj->group($posted['term_id']);
     317
     318        if (!$group) {
     319            echo json_encode(array(
    328320                'success' => false,
    329321                'error' => 'No variations found.'
    330             ) );
    331 
    332             exit;
    333         }
    334 
    335         echo json_encode( array(
    336             'success' => true,
    337             'html' => ptp_variations_edit_form( $group )
    338         ) );
    339 
    340         exit;
    341     }
    342 
    343     public function variations_group_add() {
    344         check_ajax_referer( 'ptp_variations_group_add', 'ptp_nonce' );
     322            ));
     323
     324            exit;
     325        }
     326
     327        echo json_encode(array(
     328            'success' => true,
     329            'html' => ptp_variations_edit_form($group)
     330        ));
     331
     332        exit;
     333    }
     334
     335    public function variations_group_add()
     336    {
     337        check_ajax_referer('ptp_variations_group_add', 'ptp_nonce');
    345338
    346339        $posted = $_POST;
    347340
    348         if ( !$posted['variations'] ) {
    349             echo json_encode( array(
     341        if (!$posted['variations']) {
     342            echo json_encode(array(
    350343                'success' => false,
    351344                'error' => 'You must add at least one variation.'
    352             ) );
     345            ));
    353346
    354347            exit;
     
    357350        $variations_obj = PTPImporter_Variation_Group::getInstance();
    358351
    359         $term_id = $variations_obj->add( $posted['group_name'], $posted['description'], $posted['variations'], $posted['parent-group'] );
    360 
    361         if ( $term_id ) {
    362             echo json_encode( array(
     352        $term_id = $variations_obj->add($posted['group_name'], $posted['description'], $posted['variations'], $posted['parent-group']);
     353
     354        if ($term_id) {
     355            echo json_encode(array(
    363356                'success' => true,
    364                 'parent'  => intval($posted['parent-group']),
    365                 'html'    => ptp_variations_list_item( $variations_obj->group( $term_id ) )
    366             ) );
    367         }
    368 
    369         exit;
    370     }
    371 
    372     public function variations_group_update() {
    373         check_ajax_referer( 'ptp_variations_group_update', 'ptp_nonce' );
     357                'parent' => intval($posted['parent-group']),
     358                'html' => ptp_variations_list_item($variations_obj->group($term_id))
     359            ));
     360        }
     361
     362        exit;
     363    }
     364
     365    public function variations_group_update()
     366    {
     367        check_ajax_referer('ptp_variations_group_update', 'ptp_nonce');
    374368
    375369        $posted = $_POST;
    376370
    377         if ( !$posted['variations'] ) {
    378             echo json_encode( array(
     371        if (!$posted['variations']) {
     372            echo json_encode(array(
    379373                'success' => false,
    380374                'error' => 'You must add at least one variation.'
    381             ) );
     375            ));
    382376
    383377            exit;
     
    385379
    386380        $variations_obj = PTPImporter_Variation_Group::getInstance();
    387         $old_parent     = get_term_parent( $posted['term_id'] );
    388        
    389         $result         = $variations_obj->update( $posted['term_id'], $posted['group_name'], $posted['description'], $posted['variations'], $posted['parent-group'] );
    390 
    391         if ( !$result ) {
    392             echo json_encode( array(
    393                 'success' => false,
    394                 'term_id'  => intval($posted['term_id']),
    395                 'parent'  => intval($posted['parent-group']),
    396                 'error'   => $result
    397             ) );
    398 
    399             exit;
    400         }
    401        
    402         $parents = tpc_get_term_parents( $posted['term_id'] );
    403         $dashes  = '';
    404 
    405         for( $i = 0; $i < count( $parents ); $i ++ ) $dashes .= '&mdash;';
    406 
    407         echo json_encode( array(
    408             'success'  => true,
    409             'term_id'  => intval($posted['term_id']),
    410             'name'     => $dashes . ' ' . $posted['group_name'],
     381        $old_parent = get_term_parent($posted['term_id']);
     382
     383        $result = $variations_obj->update($posted['term_id'], $posted['group_name'], $posted['description'], $posted['variations'], $posted['parent-group']);
     384
     385        if (!$result) {
     386            echo json_encode(array(
     387                'success' => false,
     388                'term_id' => intval($posted['term_id']),
     389                'parent' => intval($posted['parent-group']),
     390                'error' => $result
     391            ));
     392
     393            exit;
     394        }
     395
     396        $parents = tpc_get_term_parents($posted['term_id']);
     397        $dashes = '';
     398
     399        for ($i = 0; $i < count($parents); $i++) $dashes .= '&mdash;';
     400
     401        echo json_encode(array(
     402            'success' => true,
     403            'term_id' => intval($posted['term_id']),
     404            'name' => $dashes . ' ' . $posted['group_name'],
    411405            'is_moved' => $old_parent != $posted['parent-group'],
    412             'parent'   => intval($posted['parent-group']),
    413         ) );
    414 
    415         exit;
    416     }
    417 
    418     public function variations_group_delete() {
    419         check_ajax_referer( 'ptp_nonce' ); // generic nonce
     406            'parent' => intval($posted['parent-group']),
     407        ));
     408
     409        exit;
     410    }
     411
     412    public function variations_group_delete()
     413    {
     414        check_ajax_referer('ptp_nonce'); // generic nonce
    420415
    421416        $post = $_POST;
    422417
    423418        $variations_obj = PTPImporter_Variation_Group::getInstance();
    424         $result = $variations_obj->delete( $post['term_ids'] );
    425 
    426         if ( !$result ) {
    427             echo json_encode( array(
     419        $result = $variations_obj->delete($post['term_ids']);
     420
     421        if (!$result) {
     422            echo json_encode(array(
    428423                'success' => false,
    429424                'error' => $result
    430             ) );
    431 
    432             exit;
    433         }
    434 
    435         echo json_encode( array(
     425            ));
     426
     427            exit;
     428        }
     429
     430        echo json_encode(array(
    436431            'success' => true
    437         ) );
    438 
    439         exit;
    440     }
    441 
    442     public function variations_group_delete_dialog() {
    443         check_ajax_referer( 'ptp_nonce' ); // generic nonce
    444 
    445         echo json_encode( array(
    446             'success' => true,
    447             'html' => ptp_delete_dialog( 'Delete Variation Group(s)?', 'You are about to delete a Variation Group(s). After doing so, all products associated with this group(s) will be deleted too.' )
    448         ) );
    449 
    450         exit;
    451     }
    452 
    453     public function variations_group_migrate() {
    454         check_ajax_referer( 'ptp_nonce' ); // generic nonce
     432        ));
     433
     434        exit;
     435    }
     436
     437    public function variations_group_delete_dialog()
     438    {
     439        check_ajax_referer('ptp_nonce'); // generic nonce
     440
     441        echo json_encode(array(
     442            'success' => true,
     443            'html' => ptp_delete_dialog('Delete Variation Group(s)?', 'You are about to delete a Variation Group(s). After doing so, all products associated with this group(s) will be deleted too.')
     444        ));
     445
     446        exit;
     447    }
     448
     449    public function variations_group_migrate()
     450    {
     451        check_ajax_referer('ptp_nonce'); // generic nonce
    455452
    456453        $variations_migrate_obj = PTPImporter_Variation_Migrate::getInstance();
    457454        $result = $variations_migrate_obj->migrate();
    458455//print_r($result); die("Die for variation group migrate");
    459         if ( !$result ) {
    460             echo json_encode( array(
     456        if (!$result) {
     457            echo json_encode(array(
    461458                'success' => false
    462             ) );
    463 
    464             exit;
    465         }
    466 
    467         echo json_encode( array(
     459            ));
     460
     461            exit;
     462        }
     463
     464        echo json_encode(array(
    468465            'success' => true
    469         ) );
    470 
    471         exit;
    472     }
    473 
    474     public function category_quick_add_form() {
    475         check_ajax_referer( 'ptp_nonce' );
    476 
    477         echo json_encode( array(
     466        ));
     467
     468        exit;
     469    }
     470
     471    public function category_quick_add_form()
     472    {
     473        check_ajax_referer('ptp_nonce');
     474
     475        echo json_encode(array(
    478476            'success' => true,
    479477            'html' => ptp_quick_add_category_form()
    480         ) );
    481 
    482         exit;
    483     }
    484    
    485     public function category_list() {
    486         check_ajax_referer( 'ptp_nonce' );
    487        
    488         global $ptp_importer;
    489         $settings_obj = PTPImporter_Settings::getInstance();
    490         $settings = $settings_obj->get();
    491         $bptpi_category_naming_scheme_value = $settings['bptpi_category_naming_scheme'];
     478        ));
     479
     480        exit;
     481    }
     482
     483    public function category_list()
     484    {
     485        check_ajax_referer('ptp_nonce');
     486
     487        global $ptp_importer;
     488        $settings_obj = PTPImporter_Settings::getInstance();
     489        $settings = $settings_obj->get();
     490        $bptpi_category_naming_scheme_value = $settings['bptpi_category_naming_scheme'];
    492491//die("Die Here for naming scheme");
    493         if ( isset($bptpi_category_naming_scheme_value) ) {
    494             $bptpi_category_naming_scheme = $settings['bptpi_category_naming_scheme'];
    495         } else {
    496             $bptpi_category_naming_scheme = 'Category';
    497         }
    498 
    499         echo json_encode( array(
    500             'success' => true,
    501             'html' => ptp_dropdown_categories( array( 'name' => 'term_id', 'show_option_none' => 'Select a category' . $bptpi_category_naming_scheme, 'walker' => new Walker_Without_Children() ) )
    502         ) );
    503 
    504         exit;
    505     }
    506 
    507     public function category_quick_add() {
    508         check_ajax_referer( 'ptp_nonce' ); // generic nonce
     492        if (isset($bptpi_category_naming_scheme_value)) {
     493            $bptpi_category_naming_scheme = $settings['bptpi_category_naming_scheme'];
     494        } else {
     495            $bptpi_category_naming_scheme = 'Category';
     496        }
     497
     498        echo json_encode(array(
     499            'success' => true,
     500            'html' => ptp_dropdown_categories(array('name' => 'term_id', 'show_option_none' => 'Select a category' . $bptpi_category_naming_scheme, 'walker' => new Walker_Without_Children()))
     501        ));
     502
     503        exit;
     504    }
     505
     506    public function category_quick_add()
     507    {
     508        check_ajax_referer('ptp_nonce'); // generic nonce
    509509
    510510        global $ptp_importer;
    511511//print_r($_POST['parent']); die("Die in category");
    512         if(isset($_POST['parent']))
    513             $termx = get_term_by( 'id', $_POST['parent'], "product_cat" );
    514    
    515         if($termx->parent != 0 && isset($_POST['parent']) && $_POST['parent'] > 0)
    516         {
    517             echo json_encode( array(
     512        if (isset($_POST['parent']))
     513            $termx = get_term_by('id', $_POST['parent'], "product_cat");
     514
     515        if ($termx->parent != 0 && isset($_POST['parent']) && $_POST['parent'] > 0) {
     516            echo json_encode(array(
    518517                'success' => false,
    519518                'error' => 'Unable to create from children nodes from children category.'
    520             ) );
    521             exit;
    522         }
    523         else
    524         {
    525             $term = wp_insert_term(
    526                 $_POST['name'],
    527                 $ptp_importer->woocommerce_cat_tax,
    528                 array(
    529                     'parent' => (int)$_POST['parent']
    530                 )
    531             );
    532         }
    533 
    534         if ( is_wp_error( $term ) ) {
    535             echo json_encode( array(
     519            ));
     520            exit;
     521        } else {
     522            $term = wp_insert_term(
     523                $_POST['name'],
     524                $ptp_importer->woocommerce_cat_tax,
     525                array(
     526                    'parent' => (int)$_POST['parent']
     527                )
     528            );
     529        }
     530
     531        if (is_wp_error($term)) {
     532            echo json_encode(array(
    536533                'success' => false,
    537534                'error' => 'Unable to create category.'
    538             ) );
    539 
    540             exit;
    541         }
    542 
    543         echo json_encode( array(
     535            ));
     536
     537            exit;
     538        }
     539
     540        echo json_encode(array(
    544541            'success' => true,
    545542            'error' => $_POST
    546         ) );
    547 
    548         exit;
    549     }
    550 
    551     public function get_refreshed_fragments() {
     543        ));
     544
     545        exit;
     546    }
     547
     548    public function get_refreshed_fragments()
     549    {
    552550        global $woocommerce;
    553551
    554552        // Get mini cart
    555553        ob_start();
    556       // print_r( woocommerce_mini_cart() ); die("Atleast die any where");
     554        // print_r( woocommerce_mini_cart() ); die("Atleast die any where");
    557555        $mini_cart = ob_get_clean();
    558        // print_r($mini_cart); die("Die before Cart");
    559 
    560         if ( !$mini_cart ) {
     556        // print_r($mini_cart); die("Die before Cart");
     557
     558        if (!$mini_cart) {
    561559            $mini_cart = '<p class="empty-cart">You have not added any products to your cart yet.</p>';
    562560        }
    563561
    564562        // Fragments and mini cart are returned
    565       //  $data = array(
    566        //     'fragments' => apply_filters( 'add_to_cart_fragments', array(
    567        //             'div.ptp-widget-cart-content' => '<div class="ptp-widget-cart-content">' . $mini_cart . '</div>'
    568        //         )
    569       //      ),
    570       //      'cart_hash' => md5( json_encode( $woocommerce->cart->get_cart() ) )
    571       //  );
    572         $data = array(
    573             'fragments' => apply_filters( 'add_to_cart_fragments', array(
     563        //  $data = array(
     564        //     'fragments' => apply_filters( 'add_to_cart_fragments', array(
     565        //             'div.ptp-widget-cart-content' => '<div class="ptp-widget-cart-content">' . $mini_cart . '</div>'
     566        //         )
     567        //      ),
     568        //      'cart_hash' => md5( json_encode( $woocommerce->cart->get_cart() ) )
     569        //  );
     570        $data = array(
     571            'fragments' => apply_filters('add_to_cart_fragments', array(
    574572                    'div.ptp-widget-cart-content' => '<div class="ptp-widget-cart-content"></div>'
    575573                )
    576574            ),
    577             'cart_hash' => md5( json_encode( $woocommerce->cart->get_cart() ) )
     575            'cart_hash' => md5(json_encode($woocommerce->cart->get_cart()))
    578576        );
    579577//print_r($data); die("Die Before Cart-2");
    580         echo json_encode( $data );
    581 
    582        exit;
    583     }
    584 
    585         /**
     578        echo json_encode($data);
     579
     580        exit;
     581    }
     582
     583    // AJAX path to remove a whole item (counter turned to zero)
     584    public function remove_cart_item() {
     585        $cart = WC()->instance()->cart;
     586
     587        $_id = $_POST['id'];
     588
     589        $cart_id = $cart->generate_cart_id($_id); // $_id as Post id
     590        $cart_item_id = $cart->find_product_in_cart($cart_id);
     591
     592        if ($cart_item_id) {
     593            $cart->set_quantity($cart_item_id, 0);
     594            echo json_encode(array('success' => true));
     595        } else {
     596            echo json_encode(array('success' => false));
     597        }
     598
     599        exit;
     600    }
     601
     602    /**
    586603     * Activate this plugin
    587604     *
    588605     * @return json object
    589606     */
    590     public function activate() {
    591         check_ajax_referer( 'ptp_nonce' );
     607    public function activate()
     608    {
     609        check_ajax_referer('ptp_nonce');
    592610
    593611        global $ptp_importer;
    594612
    595613        // Check if serial key is valid
    596         $res = ptp_is_valid_serial_key( $_POST['serial_key'] );
    597         if ( !$res['success'] ) {
     614        $res = ptp_is_valid_serial_key($_POST['serial_key']);
     615        if (!$res['success']) {
    598616            echo json_encode(array(
    599617                'success' => false,
     
    605623
    606624        // Check if item names match
    607         if ( $res['item_name'] != $ptp_importer->plugin_name ) {
    608             echo json_encode(array(
    609                 'success' => false,
    610                 'message' => 'The serial key your using is not for '.$ptp_importer->plugin_name
     625        if ($res['item_name'] != $ptp_importer->plugin_name) {
     626            echo json_encode(array(
     627                'success' => false,
     628                'message' => 'The serial key your using is not for ' . $ptp_importer->plugin_name
    611629            ));
    612630
     
    615633
    616634        // Register this IP
    617         $res = ptp_register_server_info( $_POST['serial_key'] );
    618         if ( !$res['success'] ) {
     635        $res = ptp_register_server_info($_POST['serial_key']);
     636        if (!$res['success']) {
    619637            echo json_encode(array(
    620638                'success' => false,
     
    625643        }
    626644
    627         update_option( '_ptp_status', 'active' );
    628         update_option( '_ptp_sk', $_POST['serial_key'] );
     645        update_option('_ptp_status', 'active');
     646        update_option('_ptp_sk', $_POST['serial_key']);
    629647
    630648        echo json_encode(array(
     
    640658     * @return json object
    641659     */
    642     public function deactivate() {
    643         check_ajax_referer( 'ptp_nonce' );
    644 
    645         $res = ptp_deactivate( $_POST['serial_key'] );
    646         if ( !$res['success'] ) {
     660    public function deactivate()
     661    {
     662        check_ajax_referer('ptp_nonce');
     663
     664        $res = ptp_deactivate($_POST['serial_key']);
     665        if (!$res['success']) {
    647666            echo json_encode(array(
    648667                'success' => false,
     
    653672        }
    654673
    655         delete_option( '_ptp_status' );
     674        delete_option('_ptp_status');
    656675
    657676        echo json_encode(array(
  • bulk-photo-to-product-importer-extension-for-woocommerce/trunk/classes/product.php

    r1178647 r1249434  
    106106        $variation_obj = PTPImporter_Variation_Group::getInstance();
    107107        $group = $variation_obj->group( $term_id );
     108
     109        $version_value = get_option('_transient_product-transient-version');
    108110
    109111        foreach ( $group->variations as $variation ) {
     
    134136            $metadata['_sku'] = uniqid();
    135137
    136             if ( $variation['name'] == 'Downloadable' || $variation['name'] == 'downloadable' ) {
     138            //if ( $variation['name'] == 'Downloadable' || $variation['name'] == 'downloadable' ) {
    137139                $uploads_dir = wp_upload_dir();
    138140                $file_path = $uploads_dir['baseurl'] . '/woocommerce_uploads'  . $uploads_dir['subdir'] . '/downloadable_' . basename( $file_data['url'] );
     
    149151                // Set download expiry
    150152                $metadata['_download_expiry'] = '';
    151             }
     153
     154                // Add this to cache. This fixes the issue of this downloadable product not being included in the front-end
     155                $transient_name = 'wc_product_children_ids_' . $parent_id . $version_value;
     156                $children = (array)get_transient( $transient_name );
     157                $children[] = $post_id;
     158                set_transient( $transient_name, $children );
     159            //}
    152160                       
    153161            // Update metadata
     
    169177    public function add_variations( $variation_group_id, $variations ) {
    170178        global $ptp_importer;
     179
     180        $version_value = get_option('_transient_product-transient-version');
    171181
    172182        $sql = "SELECT {$this->_db->posts}.ID";
     
    215225                $metadata['_sku'] = uniqid();
    216226
    217                 if ( $variation['name'] == 'Downloadable' || $variation['name'] == 'downloadable' ) {
     227                //if ( $variation['name'] == 'Downloadable' || $variation['name'] == 'downloadable' ) {
    218228                    $uploads_dir = wp_upload_dir();
    219229                    $file_path = $uploads_dir['baseurl'] . '/woocommerce_uploads'  . $uploads_dir['subdir'] . '/downloadable_' . basename( wp_get_attachment_url( get_post_meta( $parents[$i]->ID, '_ptp_attchement_id', true ) ) );
     
    229239
    230240                    // Add this to cache. This fixes the issue of this downloadable product not being included in the front-end
    231                     $transient_name = 'wc_product_children_ids_' . $parents[$i]->ID;
     241                    $transient_name = 'wc_product_children_ids_' . $parents[$i]->ID . $version_value;
    232242                    $children = (array)get_transient( $transient_name );
    233243                    $children[] = $post_id;
    234244                    set_transient( $transient_name, $children );
    235                 }
     245                //}
    236246
    237247                // Update metadata
  • bulk-photo-to-product-importer-extension-for-woocommerce/trunk/front-end/assets/js/frontend.js

    r1178647 r1249434  
    104104                });
    105105            },
     106            remove: function(e) {
     107                // Suppress default action
     108                e.preventDefault()
     109
     110                var that = $(this);
     111                var _id = that.attr('data-product_id');
     112
     113
     114                $.post(PTPImporter_Vars_Frontend.ajaxurl, { action: 'ptp_remove_cart_item', id: _id }, function(res) {
     115                    res = $.parseJSON(res);
     116
     117                    if (res.success) {
     118                        that.closest('tr').fadeOut(function() {
     119                            $(this).remove();
     120                        });
     121                    }
     122
     123                });
     124            }
    106125        }
    107126    };
     
    119138        });
    120139        $('.datepicker').datepicker();
     140
     141
     142        $(document).on('click', '.woocommerce .shop_table .product-remove .remove', PTPImporter_Frontend.Cart.remove);
    121143    });
    122144
Note: See TracChangeset for help on using the changeset viewer.