Changeset 2858515
- Timestamp:
- 02/01/2023 05:46:19 PM (3 years ago)
- Location:
- shop-2-api/trunk
- Files:
-
- 9 edited
-
assets/shop2api_order.js (modified) (5 diffs)
-
includes/Api/Shop2ApiConnect.php (modified) (3 diffs)
-
includes/Base/AjaxButtonActions.php (modified) (1 diff)
-
includes/Base/Enqueue.php (modified) (2 diffs)
-
includes/Base/EnqueueWC.php (modified) (2 diffs)
-
includes/Init.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
-
shop-2-api.php (modified) (2 diffs)
-
templates/bol-order-sync.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
shop-2-api/trunk/assets/shop2api_order.js
r2825412 r2858515 7 7 }); 8 8 9 populate_data();10 9 retrieve_from_shop2api(); 11 10 12 // Save Koopblokdata11 // Save Order data 13 12 $(document).on('click', '#save-order-data', function (event) { 14 13 event.preventDefault(); … … 40 39 }); 41 40 }); 41 42 // Select change 43 $(document).on( 'change', '#orders-ean', handle_cat_change); 42 44 }) 45 46 function handle_cat_change(e, ) { 47 $('#orders-ean-value').children().remove() 48 if ($(this).val() === 'Product') { 49 populate_product_dropdown(); 50 } 51 if ($(this).val() === 'MetaData') { 52 populate_metadata_dropdown(); 53 } 54 } 43 55 44 56 function serialize(data) { … … 57 69 } 58 70 59 function populate_ data() {71 function populate_product_dropdown() { 60 72 let woocommerce_option_properties = settings.wc_field_options.success.schema.properties; 61 73 let _select = $('#wc-price-field'); 62 let _select_ean = $('# wc-ean-field');74 let _select_ean = $('#orders-ean-value'); 63 75 64 76 for (const item in woocommerce_option_properties) { … … 75 87 } else { 76 88 let dropdown_values = {"value": item, "text": item} 77 if (item==='sku') {78 dropdown_values['selected'] = 'selected';79 }80 89 $('<option />', dropdown_values).appendTo(_select); 81 90 $('<option />', dropdown_values).appendTo(_select_ean); 82 91 } 83 92 } 93 84 94 } 85 95 … … 87 97 let json_data = settings.orders_data; 88 98 if (json_data.length !== 0) { 89 $('#orders-active').prop('checked', json_data[0].active); 90 $('#orders-status').val(json_data[0].status); 91 $('#orders-paid').prop('checked', json_data[0].paid); 99 let order_data = json_data[0]; 100 101 $('#orders-active').prop('checked', order_data.active); 102 $('#orders-status').val(order_data.status); 103 $('#orders-paid').prop('checked', order_data.paid); 104 105 document.getElementById("orders-ean").value = order_data.woocommerce_ean_category; 106 if (order_data.woocommerce_ean_category === 'Product') { 107 populate_product_dropdown(); 108 document.getElementById("orders-ean-value").value = order_data.woocommerce_ean_field; 109 } 110 111 if (order_data.woocommerce_ean_category === 'MetaData') { 112 populate_metadata_dropdown(); 113 document.getElementById("orders-ean-value").value = order_data.woocommerce_ean_field; 114 } 115 116 return 117 } 118 document.getElementById("orders-ean-value").value = 'sku'; 119 populate_product_dropdown(); 120 } 121 122 // function populate_attribute_dropdown() { 123 // for (let i in settings.wc_metadata_dropdown_values.success) { 124 // let wc_metadata_val = settings.wc_metadata_dropdown_values.success[i]; 125 // let _select_ean_dropdown = $('#orders-ean-value'); 126 // 127 // let dropdown_values = { 128 // 'value': wc_metadata_val['bol_category'], 129 // 'text': wc_metadata_val['woocommerce_field'] 130 // } 131 // 132 // $('<option />', dropdown_values).appendTo(_select_ean_dropdown); 133 // } 134 // } 135 136 function populate_metadata_dropdown() { 137 for (i in settings.wc_metadata_dropdown_values.success) { 138 let wc_metadata_val = settings.wc_metadata_dropdown_values.success[i]; 139 let _select_ean_dropdown = $('#orders-ean-value'); 140 141 let dropdown_values = { 142 'value': wc_metadata_val['bol_category'], 143 'text': wc_metadata_val['woocommerce_field'] 144 } 145 146 $('<option />', dropdown_values).appendTo(_select_ean_dropdown); 92 147 } 93 148 } -
shop-2-api/trunk/includes/Api/Shop2ApiConnect.php
r2825412 r2858515 22 22 $this->header = ['Authorization' => 'Token ' . $token]; 23 23 if (get_site_url() == 'http://localhost:8000' || get_site_url() == 'http://127.0.0.1:8000') { 24 $this->header = array_merge($this->header, ['authurl' => "https:// pepperwall.nl/bol"]);24 $this->header = array_merge($this->header, ['authurl' => "https://testshop.shop2api.com"]); 25 25 } else { 26 26 $this->header = array_merge($this->header, ['authurl' => get_site_url()]); … … 456 456 457 457 // Set Order data 458 public function set_order_data($active, $status, $paid )458 public function set_order_data($active, $status, $paid, $woocommerce_ean_field, $woocommerce_ean_category) 459 459 { 460 460 $order = $this->get_order(); … … 474 474 'paid' => ($paid != ''), 475 475 'status' => $status, 476 "product" => $order["id"] 476 "product" => $order["id"], 477 "woocommerce_ean_field" => $woocommerce_ean_field, 478 "woocommerce_ean_category" => $woocommerce_ean_category 477 479 ]; 478 480 -
shop-2-api/trunk/includes/Base/AjaxButtonActions.php
r2825412 r2858515 310 310 $this->check_nonce(); 311 311 $shop_2_api_response = $this->shop_2_api_connections->set_order_data( 312 $_POST['orders-active'], $_POST['orders-status'], $_POST['orders-paid'] 312 $_POST['orders-active'], $_POST['orders-status'], $_POST['orders-paid'], $_POST['orders-ean-value'], 313 $_POST['orders-ean'] 313 314 ); 314 315 -
shop-2-api/trunk/includes/Base/Enqueue.php
r2825412 r2858515 237 237 $offer_data = $this->handle_api_response($shop_2_api_connection->get_bol_offer_info()); 238 238 $orders_data = $this->handle_api_response($shop_2_api_connection->get_order_data()); 239 // Get Dropdown Values 240 $wc_metadata_dropdown_values = $this->handle_api_response($shop_2_api_connection->get_wc_product_values('meta_data')); 241 $wc_attributes_dropdown_values = $this->handle_api_response($shop_2_api_connection->get_wc_product_values('attributes')); 239 242 240 243 wp_localize_script('bol2api_scripts_common', 'settings', array( … … 243 246 'wc_field_options' => $wc_field_options, 244 247 'offer_data' => $offer_data, 245 'orders_data' => $orders_data 248 'orders_data' => $orders_data, 249 'wc_metadata_dropdown_values' => $wc_metadata_dropdown_values, 250 'wc_attributes_dropdown_values' => $wc_attributes_dropdown_values 246 251 )); 247 252 } -
shop-2-api/trunk/includes/Base/EnqueueWC.php
r2846945 r2858515 41 41 add_filter('manage_edit-product_columns', array($this, 'add_columns_into_product_list_filter')); 42 42 add_filter('manage_edit-product_sortable_columns', array($this, "sortable_columns")); 43 44 // Custom API Endpoint for getting Metadata 45 add_action( 'rest_api_init', array($this, 'register_meta_field_search_endpoint' )); 43 46 } 44 47 … … 309 312 } 310 313 } 314 315 //Add Custom API End-Point 316 317 318 function register_meta_field_search_endpoint(): void 319 { 320 register_rest_route( 'shop-2-api/v1', '/search-meta', array( 321 'methods' => 'GET', 322 'callback' => array($this, 'meta_field_search_callback'), 323 ) ); 324 } 325 326 function meta_field_search_callback( $request ) { 327 $meta_key = $request->get_param( 'meta_key' ); 328 $meta_value = $request->get_param( 'meta_value' ); 329 $args = array( 330 'post_type' => 'product', 331 'meta_query' => array( 332 array( 333 'key' => $meta_key, 334 'value' => $meta_value, 335 'compare' => '=' 336 ) 337 ) 338 ); 339 $query = new WP_Query( $args ); 340 if ( $query->have_posts() ) { 341 $products = array(); 342 while ( $query->have_posts() ) { 343 $query->the_post(); 344 $product = new WC_Product(get_the_ID()); 345 $products[] = array( 346 'id' => get_the_ID(), 347 'name' => get_the_title(), 348 'price' => $product->get_price(), 349 'meta_key' => $meta_key, 350 'meta_value' => $meta_value, 351 ); 352 } 353 return rest_ensure_response( $products ); 354 } else { 355 return new WP_Error( 'no_products_found', 'No products found.', array( 'status' => 402 ) ); 356 } 357 } 311 358 } -
shop-2-api/trunk/includes/Init.php
r2825412 r2858515 18 18 require_once plugin_dir_path( __FILE__ ). 'Base/Enqueue.php'; 19 19 require_once plugin_dir_path( __FILE__ ). 'Base/EnqueueWC.php'; 20 require_once plugin_dir_path( __FILE__ ). 'Base/EnqueueWCAPI.php'; 20 21 require_once plugin_dir_path( __FILE__ ). 'Base/SettingsLinks.php'; 21 22 require_once plugin_dir_path( __FILE__ ). 'Base/AjaxButtonActions.php'; … … 33 34 $cls->register(); 34 35 36 //Add WooCommerce API Custom Calls 37 $cls = new Shop2Api_EnqueueWCAPI(); 38 $cls->register(); 39 35 40 // Settings Links 36 41 $cls = new Shop2Api_SettingsLinks(); -
shop-2-api/trunk/readme.txt
r2846945 r2858515 121 121 3) EAN Numbers can now be split up with a comma, so multiple EAN's can be sent over to Bol.com 122 122 123 = 1.0.20 = 124 1) Added an EAN Number to the order sync page 125 2) Small WooCommerce API Changes 126 123 127 == Instructions == 124 128 1) After installing Shop2Api, a new menu item will be available in your WordPress installation, you can continue and click on it and enter you token which was mailed to you. -
shop-2-api/trunk/shop-2-api.php
r2846945 r2858515 5 5 Plugin URI: https://wordpress.org/plugins/shop-2-api/ 6 6 Description: 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. 197 Version: 1.0.20 8 8 Requires at least: 5.0 9 9 Requires PHP: 7.2 … … 34 34 define('SHOP2API_PLUGIN_URL', plugin_dir_url( __FILE__ )); 35 35 define('SHOP2API_PLUGIN', plugin_basename( __FILE__ )); 36 define ('VERSION', '1.0. 19');36 define ('VERSION', '1.0.20'); 37 37 38 38 // Register items in the project. -
shop-2-api/trunk/templates/bol-order-sync.php
r2825412 r2858515 3 3 <?php require_once("common-header.php"); ?> 4 4 5 <div id='bol-connection-error' class='error-message'></div> 6 <h2>Sync Bol Orders</h2> 7 <form method="post" action="#" id="orders-form"> 8 <table> 9 <tbody id="offer-data-body"> 10 <tr> 11 <td title="Order Service Active" style="padding: 15px 0px 0px 0px;"> 12 <span class="dashicons dashicons-info-outline"></span> 13 </td> 14 <td> 15 <label for="orders-active">Active</label> 16 </td> 17 <td> 18 <input type="checkbox" name="orders-active" id="orders-active"/> 19 <span id="active" class="error-message"></span> 20 </td> 21 </tr> 22 <tr> 23 <td title="Set Incoming Orders as Paid, this will set the status in processing and update stock items." 24 style="padding: 15px 0px 0px 0px;"> 25 <span class="dashicons dashicons-info-outline"></span> 26 </td> 27 <td> 28 <label for="orders-paid">Incoming Orders Is Paid (Reduce Stock Items)</label> 29 </td> 30 <td> 31 <input type="checkbox" name="orders-paid" id="orders-paid"/> 32 <span id="paid" class="error-message"></span> 33 </td> 34 </tr> 35 <tr> 36 <td title="Set the status of the incoming order to a pre-defined WC status." 37 style="padding: 15px 0px 0px 0px;"> 38 <span class="dashicons dashicons-info-outline"></span> 39 </td> 40 <td> 41 <label for="orders-status">Incoming Orders Status</label> 42 </td> 43 <td> 44 <select name="orders-status" id="orders-status"> 45 <option value="pending">Pending</option> 46 <option value="processing">Processing</option> 47 <option value="on-hold">On-Hold</option> 48 <option value="completed">Completed</option> 49 </select> 50 <span id="status" class="error-message"></span> 51 </td> 52 </tr> 53 </tbody> 54 </table> 55 <br/> 56 <button type='submit' class='btn primary' 57 title="Save the data to Shop-2-API" id="save-order-data"> 58 Save 59 </button> 60 </form> 61 62 5 <div id='bol-connection-error' class='error-message'></div> 6 <h2>Sync Bol Orders</h2> 7 <form method="post" action="#" id="orders-form"> 8 <table> 9 <tbody id="offer-data-body"> 10 <tr> 11 <td title="Order Service Active" style="padding: 15px 0px 0px 0px;"> 12 <span class="dashicons dashicons-info-outline"></span> 13 </td> 14 <td> 15 <label for="orders-active">Active</label> 16 </td> 17 <td> 18 <input type="checkbox" name="orders-active" id="orders-active"/> 19 <span id="active" class="error-message"></span> 20 </td> 21 <td></td> 22 </tr> 23 <tr> 24 <td title="EAN Number Field in WC" style="padding: 15px 0px 0px 0px;"> 25 <span class="dashicons dashicons-info-outline"></span> 26 </td> 27 <td> 28 <label for="orders-ean">EAN Field</label> 29 </td> 30 <td> 31 <select name="orders-ean" id="orders-ean" > 32 <option value="Product" selected>WooCommerce Product Field</option> 33 <option value="MetaData">WooCommerce Metadata Field</option> 34 </select> 35 <span id="sku" class="error-message"></span> 36 </td> 37 <td><select name="orders-ean-value" id="orders-ean-value" ></select></td> 38 </tr> 39 <tr> 40 <td title="Set Incoming Orders as Paid, this will set the status in processing and update stock items." 41 style="padding: 15px 0px 0px 0px;"> 42 <span class="dashicons dashicons-info-outline"></span> 43 </td> 44 <td> 45 <label for="orders-paid">Incoming Orders Is Paid (Reduce Stock Items)</label> 46 </td> 47 <td> 48 <input type="checkbox" name="orders-paid" id="orders-paid"/> 49 <span id="paid" class="error-message"></span> 50 </td> 51 </tr> 52 <tr> 53 <td title="Set the status of the incoming order to a pre-defined WC status." 54 style="padding: 15px 0px 0px 0px;"> 55 <span class="dashicons dashicons-info-outline"></span> 56 </td> 57 <td> 58 <label for="orders-status">Incoming Orders Status</label> 59 </td> 60 <td> 61 <select name="orders-status" id="orders-status"> 62 <option value="pending">Pending</option> 63 <option value="processing">Processing</option> 64 <option value="on-hold">On-Hold</option> 65 <option value="completed">Completed</option> 66 </select> 67 <span id="status" class="error-message"></span> 68 </td> 69 </tr> 70 <tr> 71 <td title="I Have Combi Deals" style="padding: 15px 0px 0px 0px;"> 72 <span class="dashicons dashicons-info-outline"></span> 73 </td> 74 <td> 75 <label for="orders-enable_combi">Enable Combi-Deals</label> 76 </td> 77 <td> 78 <input type="checkbox" name="orders-enable_combi" id="orders-enable_combi"/> 79 <span id="enable_combi" class="error-message"></span> 80 </td> 81 </tr> 82 <tr> 83 <td title="The EAN Number field which combines all the Combi Deals." style="padding: 15px 0px 0px 0px;"> 84 <span class="dashicons dashicons-info-outline"></span> 85 </td> 86 <td> 87 <label for="orders-active">Combi EAN Number</label> 88 </td> 89 <td> 90 <input type="checkbox" name="orders-combideals" id="orders-active"/> 91 <span id="combideals" class="error-message"></span> 92 </td> 93 </tr> 94 </tbody> 95 </table> 96 <br/> 97 <button type='submit' class='btn primary' title="Save the data to Shop-2-API" id="save-order-data"> 98 Save 99 </button> 100 </form> 63 101 </div>
Note: See TracChangeset
for help on using the changeset viewer.