Plugin Directory

Changeset 1893975


Ignore:
Timestamp:
06/16/2018 07:08:39 PM (8 years ago)
Author:
shopybot
Message:

fixed offer name entity issue

Location:
shopybot-woocommerce/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • shopybot-woocommerce/trunk/includes/class-wc-shopybot-export.php

    r1794656 r1893975  
    22
    33class WC_Shopybot_Export {
    4    
     4
    55    private $id;              // plugin ID
    6    
     6
    77    private $currentpage;     // current export page
    88    private $vendors;         // brand
     
    1111    private $debug;           // debug on/off
    1212    private $isgroupidattr;   // adding group_id to var. products
    13    
     13
    1414    function __construct($export_id, $settings) {
    1515        $this->id          = $export_id;
    1616        $this->shellPrefix = $export_id;
    17        
     17
    1818        $this->currentpage   = (get_option($this->id . '_page')) ? get_option($this->id . '_page') : 1;
    1919        $this->pages         = (get_option($this->id . '_pages')) ? get_option($this->id . '_pages') : 1;
     
    2222        $this->posts         = get_option($this->id . '_get_ids');
    2323        $this->md5offer      = array();
    24        
     24
    2525        $def_settings = array(
    2626            'isdeliver'       => true,
     
    3636            'salesNote'       => ''
    3737        );
    38        
     38
    3939        foreach($def_settings as $set => $val) {
    40            
     40
    4141            if(isset($settings[ $set ])) {
    4242                $this->{$set} = $settings[ $set ];
     
    4444                $this->{$set} = $val;
    4545            }
    46            
    47         }
    48        
     46
     47        }
     48
    4949        add_action('init', array($this, 'init'));
    50        
     50
    5151        if(isset($_GET['tab']) && $_GET['tab'] == $this->id and isset($_REQUEST['save'])) {
    5252            $this->action_unlock();
    5353        }
    5454    }
    55    
     55
    5656    /**
    5757     * Init
     
    5959    public function init() {
    6060        add_filter('mod_rewrite_rules', array($this, 'add_htaccess_rule'));
    61        
     61
    6262        add_action("added_post_meta", array($this, 'generateOffer'), 10, 2);
    6363        add_action('updated_postmeta', array($this, 'generateOffer'), 10, 2);
    6464        add_action('wp_insert_post', array($this, 'wp_insert_post'), 1, 2);
    6565        add_action('set_object_terms', array($this, 'set_object_terms'), 1);
    66        
     66
    6767        add_action('wp_ajax_shopybot_woocommerce_ajaxUpdateOffers', array($this, 'ajaxUpdateOffers'));
    68        
     68
    6969        $this->shell();
    7070        $this->getYmlAction();
    7171    }
    72    
     72
    7373    public function add_htaccess_rule($rules) {
    7474        $rules .= "RewriteRule ^" . $this->id . ".xml index.php\n";
    7575        $rules .= "RewriteRule ^" . $this->id . ".xml.gz index.php\n";
    76        
     76
    7777        return $rules;
    7878    }
    79    
     79
    8080    public function getYmlAction() {
    8181        if(get_option('permalink_structure') != '') {
    8282            $url = parse_url($this->siteURL() . $_SERVER['REQUEST_URI']);
    83            
     83
    8484            if($url['path'] == '/' . $this->id . '.xml') {
    8585                $this->getYml();
    8686                die;
    8787            }
    88            
     88
    8989            if($url['path'] == '/' . $this->id . '.xml.gz') {
    9090                $this->getYml(true);
     
    9393        } else {
    9494            if(isset($_GET[ $this->id . '_export' ])) {
    95                
     95
    9696                $gzip = (isset($_GET['gzip'])) ? true : false;
    9797                $this->getYml($gzip);
     
    100100        }
    101101    }
    102    
     102
    103103    private function siteURL() {
    104104        $protocol   = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    105105        $domainName = $_SERVER['HTTP_HOST'];
    106        
     106
    107107        return $protocol . $domainName;
    108108    }
    109    
    110    
     109
     110
    111111    public function bread($text) {
    112112        if(is_string($text)) {
     
    115115            $result = print_r($text, true) . "\n";
    116116        }
    117        
     117
    118118        $this->bread[] = $result;
    119        
     119
    120120        if($this->debug) {
    121121            echo $result;
    122122        }
    123123    }
    124    
     124
    125125    final public function inProcess() {
    126126        $inProcess = get_option($this->id . '_in_process');
    127        
     127
    128128        if(empty($inProcess)) {
    129129            update_option($this->id . '_in_process', 'no');
    130            
     130
    131131            return false;
    132132        }
    133        
     133
    134134        if($inProcess == 'no') {
    135135            return false;
     
    138138        }
    139139    }
    140    
     140
    141141    /**
    142142     * Sets the export status: yes/no
     
    147147        }
    148148    }
    149    
    150    
     149
     150
    151151    /**
    152152     * set current page of the export
     
    156156        update_option($this->id . '_page', $page);
    157157    }
    158    
    159    
     158
     159
    160160    public function debugOn() {
    161161        $this->debug = true;
    162162    }
    163    
     163
    164164    /**
    165165     * Debug off
     
    168168        $this->debug = false;
    169169    }
    170    
     170
    171171    /**
    172172     * Blocks the export (multiple button click error)
     
    175175        update_option($this->id . '_lock', true);
    176176    }
    177    
     177
    178178    /**
    179179     * Unblocks the export
     
    182182        update_option($this->id . '_lock', false);
    183183    }
    184    
     184
    185185    /**
    186186     * Checks whether export is blocked
     
    189189        return get_option($this->id . '_lock');
    190190    }
    191    
     191
    192192    final public function numberOffers() {
    193193        global $wpdb;
    194194        $ids = $this->getIdsQueryForExport();
    195195        $ids = implode(',', $ids->posts);
    196        
     196
    197197        $offers = $wpdb->get_results("SELECT COUNT(*) as num_offers FROM {$wpdb->prefix}postmeta WHERE meta_key='" . $this->id . "_yml_offer' AND post_id IN ($ids)");
    198        
     198
    199199        return $offers[0]->num_offers;
    200200    }
    201    
     201
    202202    /**
    203203     * Export categories
     
    205205    final public function renderCats() {
    206206        $get_terms = $this->getRelationsTax();
    207        
     207
    208208        if(!empty($get_terms['product_cat'])) {
    209209            if(in_array('all', $get_terms['product_cat'])) {
     
    215215            $terms = get_terms('product_cat');
    216216        }
    217        
     217
    218218        if(!empty($terms)) {
    219219            $yml = '<categories>' . "\n";
    220            
     220
    221221            foreach($terms as $key => $cat) {
    222222                $parent = ($cat->parent) ? 'parentId="' . $cat->parent . '"' : '';
    223                
    224                 $yml .= "\t\t" . '<category id="' . $cat->term_id . '" ' . $parent . '>' . $cat->name . '</category>' . "\n";
    225             }
    226            
     223                $yml .= "\t\t" . '<category id="' . $cat->term_id . '" ' . $parent . '>' . htmlspecialchars($cat->name) . '</category>' . "\n";
     224            }
     225
    227226            $yml .= '</categories>' . "\n";
    228            
     227
    229228            $yml = apply_filters($this->id . '_render_cats', $yml);
    230            
     229
    231230            return $yml;
    232231        }
    233232    }
    234    
     233
    235234    /**
    236235     * Export currencies
     
    238237    final public function renderCurrency() {
    239238        $yml = '<currency id="' . $this->getWooCurrency() . '" rate="1"/>';
    240        
     239
    241240        $yml = apply_filters($this->id . '_render_currency', $yml);
    242        
     241
    243242        return $yml;
    244243    }
    245    
    246    
     244
     245
    247246    /**
    248247     * Gets product attrs
     
    251250        $attributes = $product->get_attributes();
    252251        $out_attr   = '';
    253        
     252
    254253        foreach($attributes as $key => $attribute) {
    255            
     254
    256255            if($attribute['is_taxonomy'] && !taxonomy_exists($attribute['name'])) {
    257256                continue;
    258257            }
    259            
     258
    260259            $name = wc_attribute_label($attribute['name']);
    261            
     260
    262261            if($attribute['is_taxonomy']) {
    263262                if($product->product_type == 'variation' && array_key_exists('attribute_' . $attribute['name'], $product->variation_data)) {
    264                    
    265263                    $value = apply_filters('woocommerce_attribute', $product->variation_data[ 'attribute_' . $attribute['name'] ]);
    266                    
    267                 }
    268                
     264                }
     265
    269266                if($product->product_type != 'variation' || empty($value)) {
    270267                    $values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
     
    273270            } else {
    274271                if($product->product_type == 'variation' && array_key_exists('attribute_' . $attribute['name'], $product->variation_data)) {
    275                    
    276272                    $value = apply_filters('woocommerce_attribute', $product->variation_data[ 'attribute_' . $attribute['name'] ]);
    277                    
    278273                } else {
    279274                    // Convert pipes to commas and display values
     
    282277                }
    283278            }
    284            
     279
    285280            if(!empty($value) and !empty($name)) {
    286                 $out_attr .= '<param name="' . $name . '">' . $value . '</param>' . "\n";
    287             }
    288         }
    289        
     281                $out_attr .= '<param name="' . $name . '">' . htmlspecialchars($value) . '</param>' . "\n";
     282            }
     283        }
     284
    290285        $out_attr = apply_filters($this->id . '_export_attributes', $out_attr, $product, $attributes);
    291        
     286
    292287        return $out_attr;
    293288    }
    294    
     289
    295290    /**
    296291     * Product images
     
    298293    final public function getImagesProduct($product) {
    299294        $images = array();
    300        
     295
    301296        if($product->product_type == 'variation' && method_exists($product, 'get_image_id')) {
    302297            $image_id = $product->get_image_id();
     
    304299            $image_id = get_post_thumbnail_id($product->id);
    305300        }
    306        
     301
    307302        $general_image = WC_Shopybot_Functions::sanitize(wp_get_attachment_url($image_id));
    308        
     303
    309304        if(!empty($general_image)) {
    310305            $images[] = $general_image;
    311306        }
    312        
     307
    313308        $ids = $product->get_gallery_attachment_ids();
    314        
     309
    315310        if(!empty($ids)) {
    316            
     311
    317312            foreach($ids as $id) {
    318313                $image = wp_get_attachment_image_src($id, 'full');
     
    320315                    $images[] = WC_Shopybot_Functions::sanitize($image[0]);
    321316                }
    322                
    323             }
    324         }
    325        
     317
     318            }
     319        }
     320
    326321        return $images;
    327322    }
    328    
     323
    329324    /**
    330325     * Sets export params
    331326     */
    332327    final public function setOfferParams($product) {
    333        
     328
    334329        $terms = wp_get_post_terms($product->id, 'product_cat');
    335        
     330
    336331        if(!empty($terms)) {
    337332            $cat = $terms[0]->term_id;
    338333        } else {
    339334            $this->bread('cat not set id=' . $product->id);
    340            
     335
    341336            return false;
    342337        }
    343        
     338
    344339        $excerpt     = trim($product->post->post_excerpt);
    345340        $description = (!empty($excerpt)) ? $excerpt : $product->post->post_content;
    346341        $description = WC_Shopybot_Functions::substr($description, 500, false);
    347        
     342
    348343        if($this->vendors == false) {
    349344            $vendor = get_post_meta($product->id, '_vendor', true);
    350345        } else {
    351            
    352346            $terms = wp_get_post_terms($product->id, $this->vendors);
    353            
     347
    354348            if(!is_wp_error($terms)) {
    355349                if(!empty($terms[0])) {
     
    357351                }
    358352            }
    359            
    360         }
    361        
     353        }
     354
    362355        if(empty($vendor)) {
    363356            $vendor = get_option($this->id . '_def_vendor');
    364357        }
    365        
     358
    366359        if(empty($vendor)) {
    367360            $vendor = 'none';
    368361        }
    369        
    370        
     362
     363
    371364        $pictures = $this->getImagesProduct($product);
    372        
     365
    373366        if(empty($pictures)) {
    374367            return false;
    375368        }
    376        
    377        
     369
    378370        $params = array(
    379371            'url'         => WC_Shopybot_Functions::sanitize(urldecode(esc_attr($product->get_permalink()))),
     
    391383            'cpa'         => ($this->cpa) ? $this->cpa : '',
    392384        );
    393        
    394        
     385
     386
    395387        $params = apply_filters($this->id . '_set_offer_params', $params, $product);
    396        
     388
    397389        if(empty($params['vendor'])) {
    398390            $this->bread('vendor not set id=' . $product->id);
    399            
     391
    400392            return false;
    401393        }
    402        
     394
    403395        if(empty($params['name'])) {
    404396            $this->bread('name not set id=' . $product->id);
    405            
     397
    406398            return false;
    407399        }
    408        
    409        
     400
     401
    410402        if($params['price'] == 0) {
    411403            return false;
    412404        }
    413        
    414        
     405
     406
    415407        $params['sales_notes'] = WC_Shopybot_Functions::substr($params['sales_notes'], 50, false);
    416        
     408
    417409        return $params;
    418410    }
    419    
    420    
     411
     412
    421413    /**
    422414     * Exports page of the products
     
    424416    final public function renderPartOffers() {
    425417        $products = $this->makeQuery();
    426        
     418
    427419        if($products->post_count == $products->found_posts) {
    428420            $this->yaml_finished = true;
    429421        }
    430        
     422
    431423        if($products->have_posts()) {
    432            
     424
    433425            $this->bread('found posts');
    434            
     426
    435427            while($products->have_posts()) {
    436                
     428
    437429                $products->the_post();
    438430                $product = get_product($products->post->ID);
    439                
     431
    440432                if($product->product_type == 'simple' || $product->product_type == 'variation') {
    441                    
    442                     //не нужно включать вариации, у которых нет отличий от основного товара и других вариаций
     433
    443434                    if($product->product_type == 'variation') {
    444                        
    445435                        if(!$this->checkVariationUniqueness($product)) {
    446                            
    447436                            delete_post_meta($product->variation_id, $this->id . '_yml_offer');
    448437                            $this->bread('WARNING: skipping product variation ID ' . $product->variation_id . ' (product ID ' . $product->id . ') — variation has no unique attributes');
    449438                            continue;
    450                            
    451439                        }
    452                        
    453440                    }
    454                    
     441
    455442                    $this->renderPartOffer($product);
    456                    
    457                 }
    458                
    459             }
    460            
     443                }
     444            }
     445
    461446            wp_reset_postdata();
    462            
     447
    463448            $this->setPage($this->currentpage + 1);
    464            
     449
    465450        } else {
    466451            $this->bread('no have posts');
    467452            $this->yaml_finished = true;
    468453        }
    469        
    470     }
    471    
     454
     455    }
     456
    472457    final public function renderPartOffer($product) {
    473458        $param = $this->setOfferParams($product);
    474        
     459
    475460        if($product->product_type == 'variation') {
    476461            $product_id = $product->variation_id;
     
    478463            $product_id = $product->id;
    479464        }
    480        
    481        
     465
    482466        if(!empty($param)) {
    483467            $offer = '';
    484            
     468
    485469            $available = ($product->is_in_stock() == 'instock') ? "true" : "false";
    486470            $available = apply_filters($this->id . '_set_offer_param_available', $available, $product);
    487            
     471
    488472            if($this->isbid == true) {
    489473                $bid = ($this->bid) ? 'bid="' . $this->bid . '"' : '';
     
    491475                $bid = "";
    492476            }
    493            
     477
    494478            $offer .= '<offer id="' . $product_id . '" type="vendor.model" available="' . $available . '" ' . $bid;
    495            
     479
    496480            if($product->product_type == 'variation' && $this->isgroupidattr && isset($product->parent->id)) {
    497481                $offer .= ' group_id="' . $product->parent->id . '"';
    498482            }
    499            
    500            
     483
    501484            $offer .= '>' . "\n";
    502            
     485
    503486            foreach($param as $key => $value) {
    504487                if(!empty($value)) {
    505488                    if(is_array($value)) {
    506489                        foreach($value as $values) {
    507                             $offer .= "<$key>" . $values . "</$key>\n";
     490                            $offer .= "<$key>" . htmlspecialchars($values) . "</$key>\n";
    508491                        }
    509492                    } else {
    510                         $offer .= "<$key>" . $value . "</$key>\n";
     493                        $offer .= "<$key>" . htmlspecialchars($value) . "</$key>\n";
    511494                    }
    512495                }
    513496            }
    514            
     497
    515498            $offer .= $this->getProductAttributes($product);
    516499            $offer .= '</offer>' . "\n";
    517500            if(!empty($offer)) {
    518501                $md5offer = md5($offer);
    519                
     502
    520503                if(!in_array($md5offer, $this->md5offer)) {
    521504                    $this->md5offer[] = $md5offer;
    522505                    update_post_meta($product_id, $this->id . '_yml_offer', $offer);
    523                    
    524506                    return true;
    525507                }
    526508            } else {
    527509                update_post_meta($product_id, $this->id . '_yml_offer', '');
    528                
    529510                return false;
    530511            }
    531            
     512
    532513        } else {
    533514            update_post_meta($product_id, $this->id . '_yml_offer', '');
    534            
    535515            return false;
    536516        }
    537517    }
    538    
     518
    539519    /**
    540520     * Check variation
    541521     */
    542522    final public function checkVariationUniqueness($variation) {
    543        
     523
    544524        $product = get_product($variation->id);
    545        
     525
    546526        if(!is_object($product) || !($product instanceof WC_Product_Variable)) {
    547527            return false;
    548528        }
    549        
     529
    550530        if(method_exists($product, 'get_children')) {
    551531            $children = $product->get_children();
     
    553533            return false;
    554534        }
    555        
     535
    556536        $differs      = false;
    557537        $pairs_differ = array();
    558        
     538
    559539        foreach($children as $_id) {
    560            
     540
    561541            $_variation = get_product($_id);
    562            
     542
    563543            if($_variation->variation_id == $variation->variation_id) {
    564544                continue;
    565545            }
    566            
    567            
     546
    568547            $pair_differs = false;
    569            
     548
    570549            foreach($variation->variation_data as $attr => $value) {
    571                
    572550                foreach($_variation->variation_data as $attr_compare => $value_compare) {
    573                    
    574551                    if($attr === $attr_compare && $value !== $value_compare) {
    575552                        $pair_differs = true;
    576553                        break;
    577554                    }
    578                    
    579                 }
    580                
     555                }
     556
    581557                if($pair_differs) {
    582558                    break;
    583559                }
    584                
    585             }
    586            
     560            }
     561
    587562            $pairs_differ[] = $pair_differs;
    588            
    589         }
    590        
     563        }
     564
    591565        $differs = in_array(false, $pairs_differ) ? false : true;
    592        
     566
    593567        return $differs;
    594        
    595     }
    596    
     568
     569    }
     570
    597571    final public function getShellArg() {
    598572        $shell_arg = @getopt("", array("wooexportyml_" . $this->shellPrefix . "::", "debug::", "unlock::", 'fullexport::', "unittests::"));
    599        
     573
    600574        if(empty($shell_arg)) {
    601575            $shell_arg = array();
     
    603577            $shell_arg = array_keys($shell_arg);
    604578        }
    605        
     579
    606580        return $shell_arg;
    607581    }
    608    
     582
    609583    /**
    610584     * shell params
     
    617591    public function shell() {
    618592        global $wpdb;
    619        
     593
    620594        $shell_arg = $this->getShellArg();
    621        
     595
    622596        if(in_array('wooexportyml_' . $this->shellPrefix, $shell_arg)) {
    623597            if(in_array('unlock', $shell_arg)) {
     
    625599                die;
    626600            }
    627            
     601
    628602            if(in_array('debug', $shell_arg)) {
    629603                $this->debugOn();
    630604            }
    631            
     605
    632606            $this->action_fullexport();
    633607            die;
    634608        }
    635609    }
    636    
     610
    637611    /**
    638612     * Unlocks the export
     
    643617        $this->exportUnlock();
    644618    }
    645    
     619
    646620    /**
    647621     * Full re-export, not paginated
     
    651625        $this->setPage(1);
    652626        $this->exportUnlock();
    653        
     627
    654628        while(!$this->yaml_finished) {
    655629            $this->export();
    656630        }
    657631    }
    658    
     632
    659633    /**
    660634     * Main export function
     
    662636    public function export() {
    663637        if(!$this->isLock()) {
    664            
     638
    665639            $this->exportLock();
    666            
     640
    667641            if($this->inProcess()) {
    668                
     642
    669643                $this->bread('in process');
    670                
     644
    671645                $this->renderPartOffers();
    672                
     646
    673647            } else {
    674                
     648
    675649                $this->bread('not in process');
    676                
    677                
     650
     651
    678652                $this->bread('check time true');
    679                
     653
    680654                $this->inProcessSet('yes');
    681655                $this->renderPartOffers();
    682                
    683             }
    684            
     656
     657            }
     658
    685659            if($this->yaml_finished) {
    686                
     660
    687661                $this->bread('is yaml_finished true');
    688                
     662
    689663                $this->inProcessSet('no');
    690664                $this->setPage(1);
    691665            }
    692            
     666
    693667            $this->exportUnlock();
    694668        } else {
     
    696670        }
    697671    }
    698    
    699    
     672
     673
    700674    /**
    701675     * Renders YAML head
     
    717691    <offers>
    718692    ';
    719        
    720     }
    721    
    722    
     693
     694    }
     695
     696
    723697    /**
    724698     * Renders YAML footer
     
    730704    </yml_catalog>
    731705    ';
    732        
    733     }
    734    
     706
     707    }
     708
    735709    final public function renderOffers() {
    736710        global $wpdb;
    737        
     711
    738712        $ids = $this->getIdsQueryForExport();
    739713        $ids = implode(',', $ids->posts);
    740        
     714
    741715        $offers = $wpdb->get_results("SELECT DISTINCT meta_value, post_id FROM {$wpdb->prefix}postmeta WHERE meta_key='" . $this->id . "_yml_offer' AND post_id IN ($ids)");
    742        
     716
    743717        foreach($offers as $offer) {
    744718            echo apply_filters($this->id . '_renderOffers', $offer->meta_value, $offer->post_id);
    745719        }
    746720    }
    747    
    748    
     721
     722
    749723    /**
    750724     * Fetches offers from postmeta and generates YML file
     
    757731            header("Content-Type:text/xml; charset=utf-8");
    758732        }
    759        
    760        
     733
     734
    761735        $arg = array(
    762736            'name'    => get_option('blogname'),
     
    765739            //            'this' => $this,
    766740        );
    767        
     741
    768742        $arg = apply_filters($this->id . '_make_yml_arg', $arg);
    769        
     743
    770744        $this->renderHead($arg);
    771745        $this->renderOffers();
    772746        $this->renderFooter();
    773        
     747
    774748        if($gzip) {
    775749            WC_Shopybot_Functions::print_gzencode_output($this->id . '.xml.gz');
    776750        }
    777751    }
    778    
    779    
     752
     753
    780754    final public function getIdsQueryForExport() {
    781        
     755
    782756        $this->bread('Generate ids');
    783        
     757
    784758        $args = array(
    785759            'posts_per_page' => - 1,
     
    788762            'fields'         => 'ids'
    789763        );
    790        
     764
    791765        $relations = $this->getRelationsTax();
    792        
     766
    793767        foreach($relations as $tax => $terms) {
    794768            if(!empty($terms)) {
    795                
     769
    796770                if(!in_array('all', $terms)) {
    797771                    $args['tax_query'][] = array(
     
    801775                    );
    802776                } else if($tax == 'product_cat' and in_array('all', $terms)) {
    803                    
     777
    804778                    $get_terms = get_terms($tax);
    805779                    $terms     = array();
    806                    
     780
    807781                    foreach($get_terms as $term) {
    808782                        $terms[] = $term->term_id;
    809783                    }
    810                    
     784
    811785                    $args['tax_query'][] = array(
    812786                        'taxonomy' => $tax,
     
    817791            }
    818792        }
    819        
    820        
     793
     794
    821795        $args         = apply_filters($this->id . '_make_query_get_ids', $args);
    822796        $products_ids = new WP_Query($args);
    823        
     797
    824798        $variations_ids = $this->getVariationsIds();
    825        
     799
    826800        $ids_query             = new WP_Query();
    827801        $ids_query->posts      = array_merge($products_ids->posts, $variations_ids->posts);
    828802        $ids_query->post_count = $products_ids->post_count + $variations_ids->post_count;
    829        
     803
    830804        return $ids_query;
    831805    }
    832    
     806
    833807    final public function getVariationsIds() {
    834        
     808
    835809        $args = array(
    836810            'posts_per_page' => - 1,
     
    846820            )
    847821        );
    848        
     822
    849823        return new WP_Query($args);
    850824    }
    851    
     825
    852826    /**
    853827     * Export DB query
    854828     */
    855829    final public function makeQuery() {
    856        
     830
    857831        if($this->currentpage == 1) {
    858832            $ids_query   = $this->getIdsQueryForExport();
     
    860834            update_option($this->id . '_get_ids', $this->posts);
    861835        }
    862        
    863        
     836
     837
    864838        $this->bread('Current page - ' . $this->currentpage);
    865        
     839
    866840        $shell_arg = $this->getShellArg();
    867        
     841
    868842        $perpage = (in_array('wooexportyml', $shell_arg)) ? 500 : 150;
    869        
     843
    870844        $args = array(
    871845            'post__in'       => (array) $this->posts,
     
    874848            'post_type'      => array('product', 'product_variation'),
    875849        );
    876        
     850
    877851        // Когда всего 200 товаров, нет смысла выгружать партиями.
    878852        if((int) $get_ids->found_posts >= 200) {
    879853            $args['posts_per_page'] == 200;
    880854        }
    881        
     855
    882856        $args = apply_filters($this->id . '_make_query_get_products', $args);
    883        
     857
    884858        $query = new WP_Query($args);
    885859        update_option($this->id . '_pages', $query->max_num_pages);
    886        
     860
    887861        return $query;
    888862    }
    889    
    890    
     863
     864
    891865    /**
    892866     * Get list of taxonomies
     
    894868    final public function getRelationsTax() {
    895869        $tax = get_taxonomies(array('object_type' => array('product')), 'objects');
    896        
     870
    897871        $relations = array();
    898        
     872
    899873        foreach($tax as $key => $tax_val) {
    900            
     874
    901875            if($key == 'product_type') {
    902876                continue;
    903877            }
    904            
     878
    905879            if(strripos($key, 'pa_') !== false) {
    906880                continue;
    907881            }
    908            
     882
    909883            $relations[ $key ] = get_option($this->id . '_tax_' . $key);
    910884        }
    911        
     885
    912886        if(!isset($relations['product_cat'])) {
    913887            $relations['product_cat'] = array();
    914888        }
    915        
    916        
     889
     890
    917891        $options = get_option($this->id . '_filters');
    918        
     892
    919893        if(!empty($options)) {
    920894            foreach($options as $key => $value) {
     
    922896                    continue;
    923897                }
    924                
     898
    925899                $relations[ $key ] = $value;
    926900            }
    927901        }
    928        
     902
    929903        return $relations;
    930904    }
    931    
    932    
     905
     906
    933907    public function ajaxUpdateOffers() {
    934908        if($_POST['unlock'] == 'yes') {
    935909            $this->action_unlock();
    936910        }
    937        
     911
    938912        $this->export();
    939        
     913
    940914        echo json_encode(array('yaml_finished' => $this->yaml_finished, 'bread' => $this->bread));
    941915        die;
    942916    }
    943    
     917
    944918    final public function generateOffer($meta_id, $post_id) {
    945        
     919
    946920        $product = get_product($post_id);
    947921        $this->renderPartOffer($product);
    948922    }
    949    
     923
    950924    final public function wp_insert_post($post_id, $post) {
    951925        if($post->post_type == 'product') {
     
    954928        }
    955929    }
    956    
     930
    957931    final public function set_object_terms($post_id) {
    958932        $post = get_post($post_id);
    959        
     933
    960934        if($post->post_type == 'product') {
    961935            $product = get_product($post_id);
    962936            $this->renderPartOffer($product);
    963937        }
    964        
    965     }
    966    
     938
     939    }
     940
    967941    /**
    968942     * @return mixed|void
     
    971945        return apply_filters('woocommerce_currency', get_option('woocommerce_currency'));
    972946    }
    973    
     947
    974948}
  • shopybot-woocommerce/trunk/readme.txt

    r1858541 r1893975  
    33Tags: bot, chat-bot, chatbot, facebook, woocommerce, integration, ShopyBot, ai, machine learning, artificial intelligence
    44Requires at least: 3.9
    5 Tested up to: 4.9.1
    6 Stable tag: 1.0.3
     5Tested up to: 4.9.6
     6Stable tag: 1.0.5
    77License: GNU GENERAL PUBLIC LICENSE Version 3
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    105105== Changelog ==
    106106
     107= 1.0.5 =
     108Fixed issue with XML file generation
     109
    107110= 1.0.4 =
    108111Fixed issue with injecting styles and scripts
Note: See TracChangeset for help on using the changeset viewer.