From fde1b35a0df1fafd6673e877574f1c2aca1edfb0 Mon Sep 17 00:00:00 2001 From: Willie Huizing Date: Wed, 26 Jun 2019 14:09:29 +0200 Subject: [PATCH] added xcore_is_variation and bugfix --- README.md | 2 +- composer.json | 2 +- includes/class-xcore-products.php | 34 ++++++++++++++++++++++++- includes/class-xcore.php | 2 +- includes/helpers/class-xcore-helper.php | 2 +- xcore.php | 2 +- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ee7a9c1..856f047 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Tags: woocommerce, connect, exact, exact online, xcore, d4d, dealer4dealer Requires at least: 4.7.5 Tested up to: 5.2.1 -Stable tag: 1.6.0 +Stable tag: 1.6.1 License: The MIT License (MIT) This module extends the api of Woocommerce and is needed for the usage of the xCore. For more information or support see http://www.dealer4dealer.nl. diff --git a/composer.json b/composer.json index 88a7d95..83030a0 100644 --- a/composer.json +++ b/composer.json @@ -14,5 +14,5 @@ "php" : ">=5.6.0", "woocommerce/woocommerce" : ">=3.3.0" }, - "version": "1.6.0" + "version": "1.6.1" } diff --git a/includes/class-xcore-products.php b/includes/class-xcore-products.php index 44db603..4b11a44 100644 --- a/includes/class-xcore-products.php +++ b/includes/class-xcore-products.php @@ -85,6 +85,29 @@ public function init() )); } + /** + * Sadly there's no way of obtaining a list with all available product types, including variations. This allows + * us to bypass the problem if a customer wants to process variations as well without impacting performance. + * + * @param WP_REST_Request $request + * @return WP_Error|WP_REST_Response + */ + + public function get_item($request) + { + $result = parent::get_item($request); + $class = WC_Product_Factory::get_classname_from_product_type($result->data['type']); + $object = new $class; + + if(is_subclass_of($object, 'WC_Product_Variation')) { + $result->data['xcore_is_variation'] = true; + } else { + $result->data['xcore_is_variation'] = false; + } + + return $result; + } + /** * Returns an array with item information * @@ -172,7 +195,14 @@ public function find_item_by_sku($request) $object = parent::get_object($product_id); if($object) { - return parent::prepare_object_for_response($object, $request); + $result = parent::prepare_object_for_response($object, $request); + + if(is_subclass_of($object, 'WC_Product_Variation')) { + $result->data['xcore_is_variation'] = true; + } else { + $result->data['xcore_is_variation'] = false; + } + return $result; } return new WP_Error( '404', 'No item found with SKU: '. $product_reference, array( 'status' => '404' )); } @@ -183,6 +213,8 @@ public function find_item_by_sku($request) */ public function get_product_types($request) { + $x = WC_Product_Factory::get_classname_from_product_typ('variable_subscription'); + return $x; return wc_get_product_types(); } diff --git a/includes/class-xcore.php b/includes/class-xcore.php index 5187c32..062efe1 100644 --- a/includes/class-xcore.php +++ b/includes/class-xcore.php @@ -4,7 +4,7 @@ class Xcore { - private $_version = '1.6.0'; + private $_version = '1.6.1'; protected static $_instance = null; protected static $_productInstance = null; diff --git a/includes/helpers/class-xcore-helper.php b/includes/helpers/class-xcore-helper.php index f7c7666..6747ead 100644 --- a/includes/helpers/class-xcore-helper.php +++ b/includes/helpers/class-xcore-helper.php @@ -13,7 +13,7 @@ static public function add_tax_rate(&$data, $key) if(array_key_exists($key, $data)) { foreach($data[$key] as &$item) { foreach($item['taxes'] as &$tax) { - $rates = ($key == 'shipping_lines') ? WC_Tax::get_shipping_tax_rates() : WC_Tax::get_rates( $item['tax_class']); + $rates = ($key == 'shipping_lines' && WC()->cart) ? WC_Tax::get_shipping_tax_rates() : WC_Tax::get_rates( $item['tax_class']); $rate_id = $tax['id'] ?? null; $rate = 0.0000; diff --git a/xcore.php b/xcore.php index 9ef9a40..22f71eb 100644 --- a/xcore.php +++ b/xcore.php @@ -4,7 +4,7 @@ Plugin Name: xCore Rest API extension Plugin URI: http://xcore.dealer4dealer.nl description: Extend WC Rest API to support xCore requests - @Version: 1.6.0 + @Version: 1.6.1 @Author: Dealer4Dealer Author URI: http://www.dealer4dealer.nl Requires at least: 4.7.5