Skip to content

Commit

Permalink
v1.6.2 matise
Browse files Browse the repository at this point in the history
  • Loading branch information
SHoogland committed Jul 4, 2019
1 parent fde1b35 commit 1ea2808
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 13 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.1
Stable tag: 1.6.2
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.1"
"version": "1.6.2"
}
87 changes: 86 additions & 1 deletion includes/class-xcore-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,91 @@ public function get_item($request)
$response = parent::get_item($request);
$types = ['line_items', 'shipping_lines', 'fee_lines'];

foreach ($response->data['line_items'] as $line_key => $line_item) {
$has_embroidery_1 = false;
$has_embroidery_2 = false;
foreach ($line_item['meta_data'] as $meta_key => $meta_data) {
if($meta_data->get_data()['key'] === 'text1'){
error_log('Embroidery line 1: '.$meta_data->get_data()['value']);
$has_embroidery_1 = true;
}
if(strpos($meta_data->get_data()['key'], 'text2') > -1){
error_log('Embroidery line 2: '.$meta_data->get_data()['value']);
$has_embroidery_2 = true;
}
if($meta_data->get_data()['key'] === 'font'){
error_log('Font: '.$meta_data->get_data()['value']);
}
if($meta_data->get_data()['key'] === 'color' && $has_embroidery_1){
error_log('Color: '.$meta_data->get_data()['value']);
}
if($meta_data->get_data()['key'] === 'position'){
error_log('Position: '.$meta_data->get_data()['value']);
}

}

if($has_embroidery_1){
$response->data['line_items'][$line_key]['price'] = $response->data['line_items'][$line_key]['price'] - 12.95;
$response->data['line_items'][] = [
"id" => 0,
"name" => "Embroidery line 1",
"product_id" => 0,
"variation_id" => 0,
"quantity" => 1,
"tax_class" => "",
"subtotal" => "12.95",
"subtotal_tax" => "2.72",
"total" => "12.95",
"total_tax" => "2.72",
"taxes" => [
[
"id" => 21,
"rate" => "21.0000",
"total" => "2.72",
"subtotal" => "2.72"
]
],
"meta_data" => [],
"sku" => "9810670001101",
"price" => 12.95,
"bundled_by" => "",
"bundled_item_title" => "",
"bundled_items" => []
];
}
if($has_embroidery_2){
$response->data['line_items'][$line_key]['price'] = $response->data['line_items'][$line_key]['price'] - 3.5;
$response->data['line_items'][] = [
"id" => 0,
"name" => "Embroidery line 2",
"product_id" => 0,
"variation_id" => 0,
"quantity" => 1,
"tax_class" => "",
"subtotal" => "3.50",
"subtotal_tax" => "0.74",
"total" => "3.50",
"total_tax" => "0.74",
"taxes" => [
[
"id" => 21,
"rate" => "21.0000",
"total" => "0.74",
"subtotal" => "0.74"
]
],
"meta_data" => [],
"sku" => "9810670001102",
"price" => 3.50,
"bundled_by" => "",
"bundled_item_title" => "",
"bundled_items" => []
];
}
}


foreach($types as $type) {
Xcore_Helper::add_tax_rate($response->data, $type);
}
Expand Down Expand Up @@ -282,4 +367,4 @@ public function get_orders_statuses()
{
return wc_get_order_statuses();
}
}
}
40 changes: 32 additions & 8 deletions includes/class-xcore-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public function get_items($request)
return $result;
}

public function create_item($request)
{
return $response = rest_ensure_response('');
}

/**
* @param WP_REST_Request $request
* @return WP_Error|WP_REST_Response
Expand All @@ -161,23 +166,42 @@ public function update_item($request)
return new WP_Error( '404', 'No item found with ID: '. $request['id'], array( 'status' => '404' ));
}

$product = false;
if ($object->is_type('variation')) {
$product = new WC_Product_Variation($request['id']);

if(isset($request['stock_quantity'])) {
} else if($object->is_type('simple')){
$product = new WC_Product_Simple($request['id']);
}
if($product){
if(isset($request['stock_quantity'])){
$product->set_stock_quantity($request['stock_quantity']);
}

if(isset($request['manage_stock'])) {
if(isset($request['manage_stock'])){
$product->set_manage_stock($request['manage_stock']);
}

if(isset($request['backorders'])) {
if(isset($request['regular_price'])){
$product->set_regular_price($request['regular_price']);
}
if(isset($request['tax_class'])){
$product->set_tax_class($request['tax_class']);
}
if(isset($request['weight'])){
$product->set_weight($request['weight']);
}
if(isset($request['catalog_visibility'])){
$product->set_catalog_visibility($request['catalog_visibility']);
}
if(isset($request['backorders'])){
$product->set_backorders($request['backorders']);
}

$product->set_stock_status();
$product->save();

// trigger an update (for example to let polylang sync products between languages)
if(has_action('woocommerce_update_product')){
do_action( 'woocommerce_update_product', $product->get_id() );
}

return parent::prepare_object_for_response($product, $request);
}

Expand Down Expand Up @@ -302,4 +326,4 @@ public function get_product_category($request, $id = null)
return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
}
}
}
}
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.1';
private $_version = '1.6.2';
protected static $_instance = null;
protected static $_productInstance = null;

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.1
@Version: 1.6.2
@Author: Dealer4Dealer
Author URI: http://www.dealer4dealer.nl
Requires at least: 4.7.5
Expand Down

0 comments on commit 1ea2808

Please sign in to comment.