Skip to content

Commit

Permalink
added xcore_is_variation and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieHuizing committed Jun 26, 2019
1 parent 2b5a7f6 commit fde1b35
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"php" : ">=5.6.0",
"woocommerce/woocommerce" : ">=3.3.0"
},
"version": "1.6.0"
"version": "1.6.1"
}
34 changes: 33 additions & 1 deletion includes/class-xcore-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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' ));
}
Expand All @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion includes/class-xcore.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Xcore
{
private $_version = '1.6.0';
private $_version = '1.6.1';
protected static $_instance = null;
protected static $_productInstance = null;

Expand Down
2 changes: 1 addition & 1 deletion includes/helpers/class-xcore-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion xcore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fde1b35

Please sign in to comment.