Plugin Directory

Changeset 2931825


Ignore:
Timestamp:
06/28/2023 12:36:57 PM (3 years ago)
Author:
sitepack
Message:

Plugin update released

Location:
sitepack-connect/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • sitepack-connect/trunk/class.sitepack-connect-rest-api.php

    r2891775 r2931825  
    295295    }
    296296
     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
    297317    private function renderError(string $message)
    298318    {
  • sitepack-connect/trunk/class.sitepack-connect.php

    r2894846 r2931825  
    1313        if (!isset(self::$instance)) {
    1414            self::$instance = new SitePackConnect();
    15 
    1615            self::$instance->init();
    1716        }
  • sitepack-connect/trunk/models/class.sitepack-stock.php

    r2894846 r2931825  
    5353        $locations = [];
    5454
     55        if (is_array($apiData['stock_locations'])) {
     56            foreach ($apiData['stock_locations'] as $stockLocation) {
     57                $locations[] = SitePackStockLocation::fromSitePackConnectData($stockLocation);
     58            }
     59        }
     60
    5561        return new SitePackStock(
    5662            (bool)$apiData['inStock'],
     
    106112
    107113    /**
    108      * @return array
     114     * @return SitePackStockLocation[]
    109115     */
    110116    public function getStockLocations(): array
  • sitepack-connect/trunk/readme.txt

    r2894846 r2931825  
    109109== Changelog ==
    110110
     111= 1.2.0 =
     112
     113Release 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
    111123= 1.1.0 =
    112124
  • sitepack-connect/trunk/sitepack-connect.php

    r2894846 r2931825  
    88Plugin URI: https://sitepack.nl/integraties
    99Description: 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.0
     10Version: 1.2.0
    1111Author: SitePack B.V.
    1212Author URI: https://sitepack.nl
     
    2222
    2323define('SITEPACK_PLUGIN_BASENAME', plugin_basename(__FILE__));
    24 define('SITEPACK_CONNECT_VERSION', '1.0.0');
     24define('SITEPACK_PLUGIN_FILE', __FILE__);
     25define('SITEPACK_CONNECT_VERSION', '1.2.0');
    2526define('SITEPACK_CONNECT_PLUGIN_DIR', plugin_dir_path(__FILE__));
    2627
    2728require_once(SITEPACK_CONNECT_PLUGIN_DIR . 'class.sitepack-connect.php');
    2829require_once(SITEPACK_CONNECT_PLUGIN_DIR . 'class.sitepack-connect-rest-api.php');
     30require_once(SITEPACK_CONNECT_PLUGIN_DIR . 'class.sitepack-frontend.php');
    2931
    3032add_action('init', ['SitePackConnect', 'init']);
     
    3234$sitePackRestApi = new SitePackConnectRestApi();
    3335add_action('rest_api_init', [$sitePackRestApi, 'init']);
     36add_action('wp_ajax_sitepack_product_stock', 'sitePackStockAjaxHandler');
     37add_action('wp_ajax_nopriv_sitepack_product_stock', 'sitePackStockAjaxHandler');
    3438
    3539if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
     
    3741    $admin = new SitePackConnectAdmin();
    3842    $admin->init();
     43}
     44
     45if (is_admin() === false) {
     46    $sitePackFrontend = new SitePackFrontend();
     47    $sitePackFrontend->init();
    3948}
    4049
     
    8190}
    8291
    83 add_action('init', 'spFetchstock');
     92if (!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            }
    84102
    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        }
    89137    }
    90 
    91     $ajaxStock = (bool)apply_filters('sitepack_fetch_live_stock', true);
    92     // TODO: build in stock info
    93138}
    94 
    95 
    96 
    97 
Note: See TracChangeset for help on using the changeset viewer.