Skip to content

Commit

Permalink
9.4 release (#512)
Browse files Browse the repository at this point in the history
* version bump
* readme
* improve rest api function
* save 9.4
  • Loading branch information
aiiddqd authored Oct 20, 2023
1 parent 3518cb3 commit 880b638
Show file tree
Hide file tree
Showing 23 changed files with 2,036 additions and 2,018 deletions.
10 changes: 6 additions & 4 deletions includes/OrderShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WooMS;

use function WooMS\request;

defined('ABSPATH') || exit;

/**
Expand All @@ -21,7 +23,7 @@ public static function init()

/**
* skip import service if the service is shipment
*
*
* issue https://github.com/wpcraft-ru/wooms/issues/314
*/
public static function skip_service_if_shipment($skip_boolean, $row_api_data)
Expand All @@ -39,7 +41,7 @@ public static function skip_service_if_shipment($skip_boolean, $row_api_data)

/**
* chg_order_data
*
*
* fix https://github.com/wpcraft-ru/wooms/issues/186
*/
public static function chg_order_data($data, $order_id)
Expand Down Expand Up @@ -77,9 +79,9 @@ public static function chg_order_data($data, $order_id)
*/
public static function get_meta_for_shipment_item($order_shipment_item_code)
{
$url = 'https://online.moysklad.ru/api/remap/1.2/entity/service';
$url = 'entity/service';
$url = add_query_arg('filter=code', $order_shipment_item_code, $url);
$data = wooms_request($url);
$data = request($url);

if (empty($data['rows'][0]['meta'])) {
return false;
Expand Down
7 changes: 5 additions & 2 deletions includes/OrderStatusesFromSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace WooMS;

use function WooMS\request;


/**
* Send statuses from WooCommerce to moysklad.ru
*/
Expand Down Expand Up @@ -91,8 +94,8 @@ public static function get_meta_status_for_orders($changed_status = '')

$statuses = get_transient('wooms_order_statuses');
if (empty($statuses)) {
$url_statuses = 'https://online.moysklad.ru/api/remap/1.2/entity/customerorder/metadata';
$statuses = wooms_request($url_statuses);
$url_statuses = 'entity/customerorder/metadata';
$statuses = request($url_statuses);
$statuses = $statuses["states"];
set_transient('wooms_order_statuses', $statuses, 600);
}
Expand Down
49 changes: 26 additions & 23 deletions includes/OrderUpdateFromMoySklad.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Exception;

use function WooMS\request;


/**
* Send statuses from moysklad.ru to WooCommerce
*/
Expand Down Expand Up @@ -71,11 +74,11 @@ public static function lock_callback_update($order_id)

/**
* update_order_status
*
*
* use hook wooms_update_order_from_moysklad
*
*
* @param \WC_Order $order
*
*
* @return \WC_Order - order object
*/
public static function update_order_status($order, $data_api)
Expand All @@ -85,7 +88,7 @@ public static function update_order_status($order, $data_api)
}

$state_url = $data_api["state"]["meta"]["href"];
$state_data = wooms_request($state_url);
$state_data = request($state_url);
if (empty($state_data['name'])) {
return $order;
}
Expand Down Expand Up @@ -116,9 +119,9 @@ public static function update_order_status($order, $data_api)

/**
* update_order_items
*
*
* @param \WC_Order $order
*
*
* @return \WC_Order - order object
*/
public static function update_order_items($order, $data_api)
Expand All @@ -130,7 +133,7 @@ public static function update_order_items($order, $data_api)

$url_api = $data_api['positions']['meta']['href'];

$data = wooms_request($url_api);
$data = request($url_api);


$shipment_product_href = self::get_shipment_product_href();
Expand Down Expand Up @@ -219,7 +222,7 @@ public static function update_order_items($order, $data_api)

/**
* get item_id from order and wooms_id
*
*
* @param string $wooms_uuid
* @param \WC_Order $order
*/
Expand All @@ -246,7 +249,7 @@ public static function get_order_item_id_by_wooms_id($wooms_uuid, $order)

/**
* Get wooms id from line item
*
*
* @param \WC_Order_Item_Product $line_item
*/
public static function get_wooms_id_from_line_item($line_item)
Expand All @@ -271,10 +274,10 @@ public static function get_wooms_id_from_line_item($line_item)

/**
* Skip order update from site, if exist task to update from MoySklad
*
*
* @param bool $skip
* @param \WC_Order $order
*
*
* @return bool - skip or no
*/
public static function skip_order_update_from_site($skip, $order)
Expand Down Expand Up @@ -303,9 +306,9 @@ public static function get_shipment_product_href()
return false;
}

$url_api = sprintf('https://online.moysklad.ru/api/remap/1.2/entity/service?filter=code=%s', $code);
$url_api = sprintf('entity/service?filter=code=%s', $code);

$data = wooms_request($url_api);
$data = request($url_api);

if (empty($data['rows'][0]['meta']['href'])) {
return false;
Expand Down Expand Up @@ -383,9 +386,9 @@ public static function update_order_from_moysklad($order_id = 0)
return false;
}

$url_api = sprintf('https://online.moysklad.ru/api/remap/1.2/entity/customerorder/%s', $wooms_id);
$url_api = sprintf('entity/customerorder/%s', $wooms_id);

$data = wooms_request($url_api);
$data = request($url_api);

$order = apply_filters('wooms_update_order_from_moysklad', $order, $data);

Expand Down Expand Up @@ -520,8 +523,8 @@ public static function get_status_order_webhook()
{

$check = self::check_webhooks_and_try_fix();
$url = 'https://online.moysklad.ru/api/remap/1.2/entity/webhook?limit=50';
$data = wooms_request($url);
$url = 'entity/webhook?limit=50';
$data = request($url);

$webhooks = array();

Expand Down Expand Up @@ -568,8 +571,8 @@ public static function get_status_order_webhook()
public static function check_webhooks_and_try_fix()
{

$url = 'https://online.moysklad.ru/api/remap/1.2/entity/webhook';
$data = wooms_request($url);
$url = 'entity/webhook';
$data = request($url);

$webhooks = array();

Expand Down Expand Up @@ -599,8 +602,8 @@ public static function check_webhooks_and_try_fix()
} else {
//пытаемся удалить лишний хук
foreach ($webhooks as $id => $value) {
$url = 'https://online.moysklad.ru/api/remap/1.2/entity/webhook/' . $id;
$check = wooms_request($url, null, 'DELETE');
$url = 'entity/webhook/' . $id;
$check = request($url, null, 'DELETE');
}

return false;
Expand All @@ -615,7 +618,7 @@ public static function check_webhooks_and_try_fix()
'action' => "UPDATE",
"entityType" => "customerorder",
);
$result = wooms_request($url, $data);
$result = request($url, $data);

if (empty($result)) {
return false;
Expand Down Expand Up @@ -752,7 +755,7 @@ public static function get_data_order_from_moysklad($data_request)

$url = $data["events"][0]["meta"]["href"];

$data_order = wooms_request($url);
$data_order = request($url);
if (empty($data_order['id'])) {
return;
}
Expand Down
43 changes: 19 additions & 24 deletions includes/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WooMS;

use function WooMS\request;

defined('ABSPATH') || exit;

/**
Expand Down Expand Up @@ -132,9 +134,8 @@ public static function order_update_to_moysklad($order_id, $order = false)
}
}

$url = 'https://online.moysklad.ru/api/remap/1.2/entity/customerorder/' . $wooms_id;

$data = wooms_request($url);
$api_path = 'entity/customerorder/' . $wooms_id;
$data = request($api_path);

/**
* Preparation the data for update an existing order
Expand Down Expand Up @@ -166,7 +167,7 @@ public static function order_update_to_moysklad($order_id, $order = false)
}


$result = wooms_request($url, $data, 'PUT');
$result = request($api_path, $data, 'PUT');

if (empty($result["id"])) {
do_action(
Expand Down Expand Up @@ -220,8 +221,7 @@ public static function add_currency($data_order, $order_id, $order = [])
}

if (!$data = get_transient('wooms_currency_api')) {
$url = 'https://online.moysklad.ru/api/remap/1.2/entity/currency/';
$data = wooms_request($url);
$data = request('entity/currency/');
set_transient('wooms_currency_api', $data, HOUR_IN_SECONDS);
}

Expand Down Expand Up @@ -442,9 +442,7 @@ public static function send_order($order_id, $order = [])
*/
$data = apply_filters('wooms_order_data', $data, $order_id, $order);

$url = 'https://online.moysklad.ru/api/remap/1.2/entity/customerorder';

$result = wooms_request($url, $data, 'POST');
$result = request('entity/customerorder', $data, 'POST');

if (empty($result['id']) || !isset($result['id']) || isset($result['errors'])) {
update_post_meta($order_id, 'wooms_send_timestamp', date("Y-m-d H:i:s"));
Expand Down Expand Up @@ -581,7 +579,7 @@ public static function add_positions($data_order, $order_id, $order = [])
'vat' => 0,
'assortment' => array(
'meta' => array(
"href" => "https://online.moysklad.ru/api/remap/1.2/entity/{$product_type}/" . $uuid,
"href" => \WooMS\get_api_url("entity/{$product_type}/" . $uuid),
"type" => "{$product_type}",
"mediaType" => "application/json",
),
Expand Down Expand Up @@ -627,8 +625,7 @@ public static function get_product_type($item)
*/
public static function get_data_organization()
{
$url = 'https://online.moysklad.ru/api/remap/1.2/entity/organization';
$data = wooms_request($url);
$data = request('entity/organization');

if (empty($data['rows'][0]['meta'])) {
do_action(
Expand Down Expand Up @@ -697,7 +694,7 @@ public static function agent_update_data($data_order, $order_id, $order = false)
);

$url = $data_order['agent']['meta']['href'];
$result = wooms_request($url, $data, 'PUT');
$result = request($url, $data, 'PUT');

return $data_order;
}
Expand Down Expand Up @@ -728,9 +725,7 @@ public static function add_agent_by_phone($data_order, $order_id, $order = false
if (!empty($phone)) {

$phone = self::phone_prepare($phone);
$url_search_agent = 'https://online.moysklad.ru/api/remap/1.2/entity/counterparty?search=' . $phone;

$data_agents = wooms_request($url_search_agent);
$data_agents = request('entity/counterparty?search=' . $phone);
if (isset($data_agents['rows'][0]['phone'])) {
$agent_meta = $data_agents['rows'][0];
}
Expand Down Expand Up @@ -775,8 +770,8 @@ public static function add_agent_as_new($data_order, $order_id, $order = false)
"email" => $order->get_billing_email()
);

$url = 'https://online.moysklad.ru/api/remap/1.2/entity/counterparty';
$result = wooms_request($url, $data, 'POST');
$url = 'entity/counterparty';
$result = request($url, $data, 'POST');

if (empty($result["meta"])) {
return $data_order;
Expand Down Expand Up @@ -820,8 +815,8 @@ public static function add_client_as_agent($data_order, $order_id, $order = fals
$agent_meta = [];

if (!empty($data['email'])) {
$url_search_agent = 'https://online.moysklad.ru/api/remap/1.2/entity/counterparty?filter=email=' . $data['email'];
$data_agents = wooms_request($url_search_agent);
$url_search_agent = 'entity/counterparty?filter=email=' . $data['email'];
$data_agents = request($url_search_agent);
if (isset($data_agents['rows'][0]['email'])) {
$agent_meta = $data_agents['rows'][0];
}
Expand All @@ -847,8 +842,8 @@ public static function check_agent_uuid($agent_uuid)
return false;
}

$url = 'https://online.moysklad.ru/api/remap/1.2/entity/counterparty/' . $agent_uuid;
$result = wooms_request($url);
$url = 'entity/counterparty/' . $agent_uuid;
$result = request($url);
if (empty($result['id'])) {
return false;
}
Expand Down Expand Up @@ -991,8 +986,8 @@ public static function get_data_order_phone($order_id, $order = false)
*/
public static function get_agent_meta_by_email($email = '')
{
$url_search_agent = 'https://online.moysklad.ru/api/remap/1.2/entity/counterparty?filter=email=' . $email;
$data_agents = wooms_request($url_search_agent);
$url_search_agent = 'entity/counterparty?filter=email=' . $email;
$data_agents = request($url_search_agent);
if (empty($data_agents['rows'][0]['meta'])) {
return false;
}
Expand Down
9 changes: 6 additions & 3 deletions includes/ProductAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace WooMS;

use function WooMS\request;


if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
Expand Down Expand Up @@ -36,7 +39,7 @@ public static function add_text($atts){
return $atts;
}


/**
* Update product
*/
Expand Down Expand Up @@ -85,7 +88,7 @@ public static function update_product($product, $item)
$product_attributes = apply_filters('wooms_attributes', $product_attributes, $product_id, $item);

do_action( 'wooms_logger', __CLASS__,
sprintf('Артибуты Продукта: %s (%s) сохранены', $product->get_title(), $product->get_id()),
sprintf('Артибуты Продукта: %s (%s) сохранены', $product->get_title(), $product->get_id()),
$product_attributes
);

Expand Down Expand Up @@ -207,7 +210,7 @@ public static function update_country($product_attributes, $product_id, $value)
$url = $value['country']["meta"]["href"];
}

$data_api = wooms_request($url);
$data_api = request($url);

if(empty($data_api["name"])){
return $product_attributes;
Expand Down
Loading

0 comments on commit 880b638

Please sign in to comment.