Plugin Directory

Changeset 1894389


Ignore:
Timestamp:
06/18/2018 08:30:59 AM (8 years ago)
Author:
shopybot
Message:

fixed compatibility issues with WooCommerce 3.0+

Location:
shopybot-woocommerce/trunk
Files:
3 edited

Legend:

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

    r1893975 r1894389  
    260260
    261261            if($attribute['is_taxonomy']) {
    262                 if($product->product_type == 'variation' && array_key_exists('attribute_' . $attribute['name'], $product->variation_data)) {
     262                if($product->get_type() == 'variation' && array_key_exists('attribute_' . $attribute['name'], $product->variation_data)) {
    263263                    $value = apply_filters('woocommerce_attribute', $product->variation_data[ 'attribute_' . $attribute['name'] ]);
    264264                }
    265265
    266                 if($product->product_type != 'variation' || empty($value)) {
    267                     $values = wc_get_product_terms($product->id, $attribute['name'], array('fields' => 'names'));
     266                if($product->get_type() != 'variation' || empty($value)) {
     267                    $values = wc_get_product_terms($product->get_id(), $attribute['name'], array('fields' => 'names'));
    268268                    $value  = apply_filters('woocommerce_attribute', wptexturize(implode(', ', $values)), $attribute, $values);
    269269                }
    270270            } else {
    271                 if($product->product_type == 'variation' && array_key_exists('attribute_' . $attribute['name'], $product->variation_data)) {
     271                if($product->get_type() == 'variation' && array_key_exists('attribute_' . $attribute['name'], $product->variation_data)) {
    272272                    $value = apply_filters('woocommerce_attribute', $product->variation_data[ 'attribute_' . $attribute['name'] ]);
    273273                } else {
     
    294294        $images = array();
    295295
    296         if($product->product_type == 'variation' && method_exists($product, 'get_image_id')) {
     296        if($product->get_type() == 'variation' && method_exists($product, 'get_image_id')) {
    297297            $image_id = $product->get_image_id();
    298298        } else {
    299             $image_id = get_post_thumbnail_id($product->id);
     299            $image_id = get_post_thumbnail_id($product->get_id());
    300300        }
    301301
     
    306306        }
    307307
    308         $ids = $product->get_gallery_attachment_ids();
     308        $ids = $product->get_gallery_image_ids();
    309309
    310310        if(!empty($ids)) {
     
    327327    final public function setOfferParams($product) {
    328328
    329         $terms = wp_get_post_terms($product->id, 'product_cat');
     329        $terms = wp_get_post_terms($product->get_id(), 'product_cat');
    330330
    331331        if(!empty($terms)) {
    332332            $cat = $terms[0]->term_id;
    333333        } else {
    334             $this->bread('cat not set id=' . $product->id);
     334            $this->bread('cat not set id=' . $product->get_id());
    335335
    336336            return false;
    337337        }
    338338
    339         $excerpt     = trim($product->post->post_excerpt);
    340         $description = (!empty($excerpt)) ? $excerpt : $product->post->post_content;
     339        $excerpt     = trim(strip_tags($product->get_short_description()));
     340        $description = (!empty($excerpt)) ? $excerpt : trim(strip_tags($product->get_description()));
    341341        $description = WC_Shopybot_Functions::substr($description, 500, false);
    342342
    343343        if($this->vendors == false) {
    344             $vendor = get_post_meta($product->id, '_vendor', true);
    345         } else {
    346             $terms = wp_get_post_terms($product->id, $this->vendors);
     344            $vendor = get_post_meta($product->get_id(), '_vendor', true);
     345        } else {
     346            $terms = wp_get_post_terms($product->get_id(), $this->vendors);
    347347
    348348            if(!is_wp_error($terms)) {
     
    378378            'delivery'    => ($this->isdeliver and !$this->cpa) ? 'true' : '',
    379379            'vendor'      => $vendor,
    380             'name'        => WC_Shopybot_Functions::del_symvol(strip_tags($product->post->post_title)),
     380            'name'        => WC_Shopybot_Functions::del_symvol(strip_tags($product->get_title())),
    381381            'description' => WC_Shopybot_Functions::del_symvol(strip_tags($description)),
    382382            'sales_notes' => (!empty($this->salesNote)) ? WC_Shopybot_Functions::substr($this->salesNote, 50, false) : '',
     
    388388
    389389        if(empty($params['vendor'])) {
    390             $this->bread('vendor not set id=' . $product->id);
     390            $this->bread('vendor not set id=' . $product->get_id());
    391391
    392392            return false;
     
    394394
    395395        if(empty($params['name'])) {
    396             $this->bread('name not set id=' . $product->id);
     396            $this->bread('name not set id=' . $product->get_id());
    397397
    398398            return false;
     
    422422
    423423        if($products->have_posts()) {
    424 
    425424            $this->bread('found posts');
    426425
    427426            while($products->have_posts()) {
    428 
    429427                $products->the_post();
    430                 $product = get_product($products->post->ID);
    431 
    432                 if($product->product_type == 'simple' || $product->product_type == 'variation') {
    433 
    434                     if($product->product_type == 'variation') {
     428                $product = wc_get_product($products->post->ID);
     429
     430                // error_log("PRODUCT_TYPE :: " . var_export($product->get_type(), true));
     431
     432                $allowed_product_types = array('external', 'simple', 'variation');
     433
     434                if(in_array($product->get_type(), $allowed_product_types)) {
     435                    if($product->get_type() == 'variation') {
    435436                        if(!$this->checkVariationUniqueness($product)) {
    436437                            delete_post_meta($product->variation_id, $this->id . '_yml_offer');
    437                             $this->bread('WARNING: skipping product variation ID ' . $product->variation_id . ' (product ID ' . $product->id . ') — variation has no unique attributes');
     438                            $this->bread('WARNING: skipping product variation ID ' . $product->variation_id . ' (product ID ' . $product->get_id() . ') — variation has no unique attributes');
    438439                            continue;
    439440                        }
    440441                    }
    441 
    442442                    $this->renderPartOffer($product);
    443443                }
     
    458458        $param = $this->setOfferParams($product);
    459459
    460         if($product->product_type == 'variation') {
     460        // error_log("PARAM :: " . var_export($param, true));
     461
     462        if($product->get_type() == 'variation') {
    461463            $product_id = $product->variation_id;
    462464        } else {
    463             $product_id = $product->id;
     465            $product_id = $product->get_id();
    464466        }
    465467
     
    478480            $offer .= '<offer id="' . $product_id . '" type="vendor.model" available="' . $available . '" ' . $bid;
    479481
    480             if($product->product_type == 'variation' && $this->isgroupidattr && isset($product->parent->id)) {
     482            if($product->get_type() == 'variation' && $this->isgroupidattr && isset($product->parent->id)) {
    481483                $offer .= ' group_id="' . $product->parent->id . '"';
    482484            }
    483485
    484486            $offer .= '>' . "\n";
     487
     488            // error_log("offer :: " . var_export($offer, true));
    485489
    486490            foreach($param as $key => $value) {
     
    522526    final public function checkVariationUniqueness($variation) {
    523527
    524         $product = get_product($variation->id);
     528        $product = wc_get_product($variation->id);
    525529
    526530        if(!is_object($product) || !($product instanceof WC_Product_Variable)) {
     
    539543        foreach($children as $_id) {
    540544
    541             $_variation = get_product($_id);
     545            $_variation = wc_get_product($_id);
    542546
    543547            if($_variation->variation_id == $variation->variation_id) {
     
    635639     */
    636640    public function export() {
    637         if(!$this->isLock()) {
    638 
    639             $this->exportLock();
     641        // if(!$this->isLock()) {
     642
     643            // $this->exportLock();
    640644
    641645            if($this->inProcess()) {
    642 
     646                // error_log("in process");
    643647                $this->bread('in process');
    644 
    645648                $this->renderPartOffers();
    646 
    647649            } else {
    648 
     650                // error_log("not in process");
    649651                $this->bread('not in process');
    650 
    651 
    652652                $this->bread('check time true');
    653 
    654653                $this->inProcessSet('yes');
    655654                $this->renderPartOffers();
    656 
    657655            }
    658656
    659657            if($this->yaml_finished) {
    660 
     658                // error_log("yaml finished");
    661659                $this->bread('is yaml_finished true');
    662 
    663660                $this->inProcessSet('no');
    664661                $this->setPage(1);
    665662            }
    666663
    667             $this->exportUnlock();
    668         } else {
    669             $this->bread('process is lock');
    670         }
     664            // $this->exportUnlock();
     665        // } else {
     666            // $this->bread('process is lock');
     667        // }
    671668    }
    672669
     
    850847
    851848        // Когда всего 200 товаров, нет смысла выгружать партиями.
    852         if((int) $get_ids->found_posts >= 200) {
     849        if((int) $ids_query->found_posts <= 200) {
    853850            $args['posts_per_page'] == 200;
    854851        }
     
    918915    final public function generateOffer($meta_id, $post_id) {
    919916
    920         $product = get_product($post_id);
     917        $product = wc_get_product($post_id);
    921918        $this->renderPartOffer($product);
    922919    }
     
    924921    final public function wp_insert_post($post_id, $post) {
    925922        if($post->post_type == 'product') {
    926             $product = get_product($post_id);
     923            $product = wc_get_product($post_id);
    927924            $this->renderPartOffer($product);
    928925        }
     
    933930
    934931        if($post->post_type == 'product') {
    935             $product = get_product($post_id);
     932            $product = wc_get_product($post_id);
    936933            $this->renderPartOffer($product);
    937934        }
  • shopybot-woocommerce/trunk/readme.txt

    r1893975 r1894389  
    44Requires at least: 3.9
    55Tested up to: 4.9.6
    6 Stable tag: 1.0.5
     6Stable tag: 1.0.6
    77License: GNU GENERAL PUBLIC LICENSE Version 3
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    105105== Changelog ==
    106106
     107= 1.0.6 =
     108Fixed incompatibility issues with WooCommerce 3.0+
     109
    107110= 1.0.5 =
    108111Fixed issue with XML file generation
  • shopybot-woocommerce/trunk/shopybot-woocommerce.php

    r1858541 r1894389  
    1010 *
    1111 * @link              https://www.shopybot.com
    12  * @since             1.0.4
     12 * @since             1.0.6
    1313 * @package           Shopybot_Chatbot_Woocommerce
    1414 *
     
    1717 * Plugin URI:        https://www.shopybot.com/connect-bot/woocommerce
    1818 * Description:       Create Facebook Chatbot for your WooCommerce E-Store. Showcase with your products in the Facebook Messenger in a few clicks
    19  * Version:           1.0.3
     19 * Version:           1.0.6
    2020 * Author:            Shopybot
    2121 * Author URI:        https://www.shopybot.com
Note: See TracChangeset for help on using the changeset viewer.