Changeset 2931825
- Timestamp:
- 06/28/2023 12:36:57 PM (3 years ago)
- Location:
- sitepack-connect/trunk
- Files:
-
- 1 added
- 5 edited
-
class.sitepack-connect-rest-api.php (modified) (1 diff)
-
class.sitepack-connect.php (modified) (1 diff)
-
class.sitepack-frontend.php (added)
-
models/class.sitepack-stock.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
-
sitepack-connect.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sitepack-connect/trunk/class.sitepack-connect-rest-api.php
r2891775 r2931825 295 295 } 296 296 297 public function renderArchiveProduct(WP_REST_Request $request) 298 { 299 try { 300 $this->authenticateRequest($request); 301 $this->validateRequiredFields($request, [ 302 'id', 303 ]); 304 305 $product = $this->eCommerceService->findProduct($request['id']); 306 307 $product->delete(false); 308 309 return [ 310 'status' => 'success', 311 ]; 312 } catch (\Exception $exception) { 313 return $this->renderError($exception->getMessage()); 314 } 315 } 316 297 317 private function renderError(string $message) 298 318 { -
sitepack-connect/trunk/class.sitepack-connect.php
r2894846 r2931825 13 13 if (!isset(self::$instance)) { 14 14 self::$instance = new SitePackConnect(); 15 16 15 self::$instance->init(); 17 16 } -
sitepack-connect/trunk/models/class.sitepack-stock.php
r2894846 r2931825 53 53 $locations = []; 54 54 55 if (is_array($apiData['stock_locations'])) { 56 foreach ($apiData['stock_locations'] as $stockLocation) { 57 $locations[] = SitePackStockLocation::fromSitePackConnectData($stockLocation); 58 } 59 } 60 55 61 return new SitePackStock( 56 62 (bool)$apiData['inStock'], … … 106 112 107 113 /** 108 * @return array114 * @return SitePackStockLocation[] 109 115 */ 110 116 public function getStockLocations(): array -
sitepack-connect/trunk/readme.txt
r2894846 r2931825 109 109 == Changelog == 110 110 111 = 1.2.0 = 112 113 Release date: 2023-06-28 114 115 #### Enhancements 116 117 * Stock locations implemented on product page, display current quantity per store location 118 119 #### Bugfixes 120 121 * Archive call fixed in REST API, used when a product is no longer active in CycleSoftware 122 111 123 = 1.1.0 = 112 124 -
sitepack-connect/trunk/sitepack-connect.php
r2894846 r2931825 8 8 Plugin URI: https://sitepack.nl/integraties 9 9 Description: Connect your eCommerce store with external APIs, using SitePack Connect. Import products with stock information and export orders to your favorite third party software. 10 Version: 1. 1.010 Version: 1.2.0 11 11 Author: SitePack B.V. 12 12 Author URI: https://sitepack.nl … … 22 22 23 23 define('SITEPACK_PLUGIN_BASENAME', plugin_basename(__FILE__)); 24 define('SITEPACK_CONNECT_VERSION', '1.0.0'); 24 define('SITEPACK_PLUGIN_FILE', __FILE__); 25 define('SITEPACK_CONNECT_VERSION', '1.2.0'); 25 26 define('SITEPACK_CONNECT_PLUGIN_DIR', plugin_dir_path(__FILE__)); 26 27 27 28 require_once(SITEPACK_CONNECT_PLUGIN_DIR . 'class.sitepack-connect.php'); 28 29 require_once(SITEPACK_CONNECT_PLUGIN_DIR . 'class.sitepack-connect-rest-api.php'); 30 require_once(SITEPACK_CONNECT_PLUGIN_DIR . 'class.sitepack-frontend.php'); 29 31 30 32 add_action('init', ['SitePackConnect', 'init']); … … 32 34 $sitePackRestApi = new SitePackConnectRestApi(); 33 35 add_action('rest_api_init', [$sitePackRestApi, 'init']); 36 add_action('wp_ajax_sitepack_product_stock', 'sitePackStockAjaxHandler'); 37 add_action('wp_ajax_nopriv_sitepack_product_stock', 'sitePackStockAjaxHandler'); 34 38 35 39 if (is_admin() || (defined('WP_CLI') && WP_CLI)) { … … 37 41 $admin = new SitePackConnectAdmin(); 38 42 $admin->init(); 43 } 44 45 if (is_admin() === false) { 46 $sitePackFrontend = new SitePackFrontend(); 47 $sitePackFrontend->init(); 39 48 } 40 49 … … 81 90 } 82 91 83 add_action('init', 'spFetchstock'); 92 if (!function_exists('sitePackStockAjaxHandler')) { 93 function sitePackStockAjaxHandler(): void 94 { 95 try { 96 if (empty($_POST['product_id'])) { 97 throw new Exception('Empty product id!'); 98 } 99 if (empty($_POST['nonce'])) { 100 throw new Exception('Empty token!'); 101 } 84 102 85 function spFetchstock() 86 { 87 if (is_admin()) { 88 return; 103 $productId = (int)$_POST['product_id']; 104 105 if (!wp_verify_nonce($_POST['nonce'], 'sitepack_product_stock')) { 106 throw new Exception('Invalid nonce given! For key: ' . $productId . ' . ' . $_POST['nonce']); 107 } 108 109 $cached = get_transient('sitepack_ajax_stock_' . $productId); 110 $isCached = false; 111 if ($cached !== false) { 112 $stock = $cached; 113 $isCached = true; 114 } else { 115 $stock = spGetProductStockInformation($productId); 116 117 set_transient('sitepack_ajax_stock_' . $productId, $stock, 10 * 60); 118 } 119 120 $response = [ 121 'success' => true, 122 'stock' => $stock, 123 'is_cached' => $isCached, 124 ]; 125 126 wp_send_json_success($response); 127 wp_die(); 128 } catch (\Exception $exception) { 129 $response = [ 130 'success' => false, 131 'message' => $exception->getMessage(), 132 ]; 133 134 wp_send_json_success($response); 135 wp_die(); 136 } 89 137 } 90 91 $ajaxStock = (bool)apply_filters('sitepack_fetch_live_stock', true);92 // TODO: build in stock info93 138 } 94 95 96 97
Note: See TracChangeset
for help on using the changeset viewer.