Plugin Directory

Changeset 2999217


Ignore:
Timestamp:
11/20/2023 07:32:13 PM (2 years ago)
Author:
ascendedcrow
Message:

1.0.28.4: Fix Product Variant Call

Location:
shop-2-api/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • shop-2-api/trunk/includes/Base/EnqueueWCAPI.php

    r2975851 r2999217  
    3939
    4040        $args = array(
    41             'post_type' => 'product',
     41            'post_type' => array('product', 'product_variation'),
    4242            'meta_query' => array(
    4343                array(
     
    5151        $query = new WP_Query( $args );
    5252        if ( $query->have_posts() ) {
    53             $products = array();
    54             while ( $query->have_posts() ) {
    55                 $query->the_post();
    56                 $product = new WC_Product(get_the_ID());
    57                 $products[] = array(
    58                     'id' => get_the_ID(),
    59                     'name' => get_the_title(),
    60                     'price' => $product->get_price(),
    61                     'meta_key' => $meta_key,
    62                     'meta_value' => $meta_value,
    63                     'stock_quantity' => $product->get_stock_quantity()
    64                 );
    65             }
     53            $products = $this->getProducts($query, $meta_key, $meta_value);
    6654            return rest_ensure_response( $products );
    6755        } else {
     
    6957        }
    7058    }
     59
     60    /**
     61     * @param WP_Query $query
     62     * @param mixed $meta_key
     63     * @param $meta_value
     64     * @return array
     65     */
     66    public function getProducts(WP_Query $query, mixed $meta_key, $meta_value): array
     67    {
     68        $products = array();
     69        while ($query->have_posts()) {
     70            $query->the_post();
     71            $current_post_id = get_the_ID();
     72            $current_post_type = get_post_type($current_post_id);
     73            if ($current_post_type === 'product_variation') {
     74                $product = new WC_Product_Variation($current_post_id);
     75            } else {
     76                $product = new WC_Product(get_the_ID());
     77            }
     78
     79            $products[] = array(
     80                'id' => get_the_ID(),
     81                'name' => get_the_title(),
     82                'price' => $product->get_price(),
     83                'meta_key' => $meta_key,
     84                'meta_value' => $meta_value,
     85                'stock_quantity' => $product->get_stock_quantity()
     86            );
     87        }
     88        return $products;
     89    }
    7190}
  • shop-2-api/trunk/readme.txt

    r2983482 r2999217  
    1591593) Dashboard Changes
    1601604) Added Alert on Order Failing Option
     1615) Fix bug where product variants is not retrieved
    161162
    162163
  • shop-2-api/trunk/shop-2-api.php

    r2983482 r2999217  
    55Plugin URI: https://wordpress.org/plugins/shop-2-api/
    66Description: The plugin Shop2Api will sync products between e-Commerce platforms. The current supported e-Commerce platforms are WooCommerce to Bol.com, and we are working on Amazon, Shopify and others.  We added a koopblok service so that you can check if you lower your price can you get koopblok.
    7 Version: 1.0.28.3
     7Version: 1.0.28.4
    88Requires at least: 5.0
    99Requires PHP:      7.2
     
    3434define('SHOP2API_PLUGIN_URL', plugin_dir_url( __FILE__ ));
    3535define('SHOP2API_PLUGIN', plugin_basename( __FILE__ ));
    36 define ('VERSION', '1.0.28.3');
     36define ('VERSION', '1.0.28.4');
    3737
    3838// Register items in the project.
Note: See TracChangeset for help on using the changeset viewer.