Plugin Directory

Changeset 2355591


Ignore:
Timestamp:
08/09/2020 03:42:26 PM (6 years ago)
Author:
casepress
Message:

update 7.10

Location:
wooms/trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • wooms/trunk/functions.php

    r2321770 r2355591  
    1 <?php
     1<?php
     2
    23/**
    34 * General function
     
    1314 * @return array
    1415 */
    15 function wooms_request( $url = '', $data = array(), $type = 'GET' ) {
    16     if ( empty( $url ) ) {
    17       return false;
    18     }
    19  
    20     $url = wooms_fix_url($url);
    21  
    22     if ( isset( $data ) && ! empty( $data ) && 'GET' == $type ) {
    23       $type = 'POST';
    24     }
    25     if ( 'GET' == $type ) {
    26       $data = null;
    27     } else {
    28       $data = json_encode( $data );
    29     }
    30  
    31       $args = array(
    32       'method'      => $type,
    33       'timeout'     => 45,
    34       'redirection' => 5,
    35       'headers'     => array(
    36         "Content-Type"  => 'application/json;charset=utf-8',
    37         'Authorization' => 'Basic ' .
    38                            base64_encode( get_option( 'woomss_login' ) . ':' . get_option( 'woomss_pass' ) ),
    39       ),
    40       'body'        => $data,
     16function wooms_request($url = '', $data = array(), $type = 'GET')
     17{
     18  if (empty($url)) {
     19    return false;
     20  }
     21
     22  $url = wooms_fix_url($url);
     23
     24  if (isset($data) && !empty($data) && 'GET' == $type) {
     25    $type = 'POST';
     26  }
     27  if ('GET' == $type) {
     28    $data = null;
     29  } else {
     30    $data = json_encode($data);
     31  }
     32
     33  $args = array(
     34    'method'      => $type,
     35    'timeout'     => 45,
     36    'redirection' => 5,
     37    'headers'     => array(
     38      "Content-Type"  => 'application/json;charset=utf-8',
     39      'Authorization' => 'Basic ' .
     40        base64_encode(get_option('woomss_login') . ':' . get_option('woomss_pass')),
     41    ),
     42    'body'        => $data,
     43  );
     44
     45  $request = wp_remote_request($url, $args);
     46  if (is_wp_error($request)) {
     47    do_action(
     48      'wooms_logger_error',
     49      $type = 'WooMS-Request',
     50      $title = 'Ошибка REST API WP Error',
     51      $desc = $request->get_error_message()
    4152    );
    4253
    43     $request = wp_remote_request( $url, $args);
    44     if ( is_wp_error( $request ) ) {
     54    return false;
     55  }
     56
     57  if (empty($request['body'])) {
     58    do_action(
     59      'wooms_logger_error',
     60      $type = 'WooMS-Request',
     61      $title = 'REST API вернулся без требуемых данных'
     62    );
     63
     64    return false;
     65  }
     66
     67  $response = json_decode($request['body'], true);
     68
     69  if (!empty($response["errors"]) and is_array($response["errors"])) {
     70    foreach ($response["errors"] as $error) {
    4571      do_action(
    4672        'wooms_logger_error',
    4773        $type = 'WooMS-Request',
    48         $title = 'Ошибка REST API WP Error',
    49         $desc = $request->get_error_message()
     74        $title = $url,
     75        $response
    5076      );
    51  
     77    }
     78  }
     79
     80  return $response;
     81}
     82
     83
     84function wooms_get_wooms_id_from_href($href = '')
     85{
     86  if (empty($href)) {
     87    return false;
     88  }
     89
     90  $url_parts = explode('/', $href);
     91
     92  return array_pop($url_parts);
     93}
     94
     95/**
     96 * Get product id by UUID from metafield
     97 * or false
     98 *
     99 * XXX move to \WooMS\Products\Bundle::get_product_id_by_uuid
     100 */
     101function wooms_get_product_id_by_uuid($uuid)
     102{
     103
     104  $posts = get_posts('post_type=product&meta_key=wooms_id&meta_value=' . $uuid);
     105  if (empty($posts[0]->ID)) {
     106    return false;
     107  } else {
     108    return $posts[0]->ID;
     109  }
     110}
     111
     112/**
     113 * fix bug with url
     114 *
     115 * @link https://github.com/wpcraft-ru/wooms/issues/177
     116 */
     117function wooms_fix_url($url = '')
     118{
     119  $url = str_replace('product_id', 'product.id', $url);
     120  $url = str_replace('store_id', 'store.id', $url);
     121  $url = str_replace('consignment_id', 'consignment.id', $url);
     122  $url = str_replace('variant_id', 'variant.id', $url);
     123  $url = str_replace('productFolder_id', 'productFolder.id', $url);
     124  return $url;
     125}
     126
     127/**
     128 * Check if WooCommerce is activated
     129 */
     130if (!function_exists('is_woocommerce_activated')) {
     131  function is_woocommerce_activated()
     132  {
     133    if (class_exists('woocommerce')) {
     134      return true;
     135    } else {
    52136      return false;
    53137    }
    54  
    55     if ( empty( $request['body'] ) ) {
    56       do_action(
    57         'wooms_logger_error',
    58         $type = 'WooMS-Request',
    59         $title = 'REST API вернулся без требуемых данных'
    60       );
    61  
    62       return false;
    63     }
    64  
    65     $response = json_decode( $request['body'], true );
    66  
    67     if( ! empty($response["errors"]) and is_array($response["errors"]) ){
    68       foreach ($response["errors"] as $error) {
    69         do_action(
    70           'wooms_logger_error',
    71           $type = 'WooMS-Request',
    72           $title = $url,
    73           $response
    74         );
    75       }
    76     }
    77  
    78     return $response;
    79138  }
    80  
    81   /**
    82    * Get product id by UUID from metafield
    83    * or false
    84    *
    85    * XXX move to \WooMS\Products\Bundle::get_product_id_by_uuid
    86    */
    87   function wooms_get_product_id_by_uuid( $uuid ) {
    88  
    89     $posts = get_posts( 'post_type=product&meta_key=wooms_id&meta_value=' . $uuid );
    90     if ( empty( $posts[0]->ID ) ) {
    91       return false;
    92     } else {
    93       return $posts[0]->ID;
    94     }
    95   }
    96  
    97   /**
    98    * fix bug with url
    99    *
    100    * @link https://github.com/wpcraft-ru/wooms/issues/177
    101    */
    102   function wooms_fix_url($url = ''){
    103       $url = str_replace('product_id', 'product.id', $url);
    104       $url = str_replace('store_id', 'store.id', $url);
    105       $url = str_replace('consignment_id', 'consignment.id', $url);
    106       $url = str_replace('variant_id', 'variant.id', $url);
    107       $url = str_replace('productFolder_id', 'productFolder.id', $url);
    108       return $url;
    109   }
    110 
    111   /**
    112  * Check if WooCommerce is activated
    113  */
    114 if ( ! function_exists( 'is_woocommerce_activated' ) ) {
    115     function is_woocommerce_activated() {
    116         if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; }
    117     }
    118139}
  • wooms/trunk/inc/MSImagesTrait.php

    r2324468 r2355591  
    3737
    3838        $get = wp_remote_get($image_url, $args);
     39
     40        if( is_wp_error( $get ) ) {
     41            do_action(
     42                'wooms_logger_error',
     43                __CLASS__,
     44                sprintf('Ошибка загрузки картинки: %s', $get->get_error_message()),
     45                $get->get_error_code()
     46            );
     47        }
    3948
    4049        if (empty($get['response']['code'])) {
  • wooms/trunk/inc/ProductsCategories.php

    r2324468 r2355591  
    9696          'wooms_logger',
    9797          __CLASS__,
    98           printf('Выбор категории продукта %s (id %s)', $product->get_name(), $product->get_id()),
     98          sprintf('Выбор категории продукта %s (id %s)', $product->get_name(), $product->get_id()),
    9999          [
    100100            '$url' => $url,
  • wooms/trunk/readme.txt

    r2325839 r2355591  
    8383
    8484== Changelog ==
     85
     86= 7.10 =
     87* [XT] Проработка решения для множества складов https://github.com/wpcraft-ru/wooms/issues/327
     88* [XT] Синхронное присвоение номера заказа в магазине https://github.com/wpcraft-ru/wooms/issues/330
     89* [XT] Исправлено. Сбрасывается заказ в "Мой склад" https://github.com/wpcraft-ru/wooms/issues/333
     90* [XT] Ошибка обновления кастомных статусов https://github.com/wpcraft-ru/wooms/issues/332
     91* [XT] Улучшили поиск контрагента по телефону https://github.com/wpcraft-ru/wooms/issues/326
     92* [XT] Связь позиций заказа и wooms_id https://github.com/wpcraft-ru/wooms/issues/335
     93* [XT] Исправление диагностики по веб хукам https://github.com/wpcraft-ru/wooms/issues/321
    8594
    8695= 7.9 =
  • wooms/trunk/wooms.php

    r2325839 r2355591  
    1717 * WP requires at least: 5.0
    1818 * Tested up to: 5.6
    19  * WooMS XT Latest: 7.9
    20  * Version: 7.9
     19 * WooMS XT Latest: 7.10
     20 * Version: 7.10
    2121 */
    2222
Note: See TracChangeset for help on using the changeset viewer.