PluginProbe ʕ •ᴥ•ʔ
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). / 2.7.5
CommerceBird – AI Command Center, ERP Integrations & B2B for WooCommerce (Zoho, Exact Online). v2.7.5
3.0.3 3.0.2 3.0.1 trunk 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.7.91 2.7.92 2.7.93 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0
commercebird / includes / classes / zoho-inventory / class-multi-currency.php
commercebird / includes / classes / zoho-inventory Last commit date
class-cmbird-categories-zi.php 7 months ago class-cmbird-image-zi.php 5 months ago class-import-items.php 4 months ago class-import-price-list.php 9 months ago class-multi-currency.php 7 months ago class-order-sync.php 4 months ago class-product.php 4 months ago class-users-contact.php 4 months ago index.php 1 year ago
class-multi-currency.php
98 lines
1 <?php
2
3 /**
4 * All Multi Currency related functions.
5 *
6 * @package WooZo Inventory
7 * @category Zoho Integration
8 * @author Roadmap Studios
9 * @link https://commercebird.com
10 */
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 class CMBIRD_Multicurrency_Zoho {
16
17 private $config;
18 public function __construct() {
19
20 $config = array(
21
22 'MulticurrencyZI' => array(
23 'OID' => get_option( 'cmbird_zoho_inventory_oid' ),
24 'APIURL' => get_option( 'cmbird_zoho_inventory_url' ),
25
26 ),
27
28 );
29
30 $this->config = $config;
31 }
32
33 /**
34 * Retrieve the currency ID for a given user currency.
35 *
36 * Execute a cURL call to retrieve all currencies from Zoho Inventory,
37 * and then loop through the response to find the matching currency code.
38 * If a match is found, update the user meta with the currency ID and code.
39 *
40 * @param string $user_currency The user currency to retrieve the ID for.
41 * @param int $userid The user ID to update the meta for.
42 * @param object $order The order object to update the meta for (if applicable).
43 *
44 * @return int The currency ID.
45 */
46 public function zoho_currency_data( $user_currency, $userid = '', $order = 0 ) {
47 $zoho_inventory_oid = $this->config['MulticurrencyZI']['OID'];
48 $zoho_inventory_url = $this->config['MulticurrencyZI']['APIURL'];
49
50 $cache_key = 'cmbird_zoho_inventory_currencies';
51 $currencies = wp_cache_get( $cache_key );
52 if ( false === $currencies ) {
53 $currencies = get_option( $cache_key );
54 if ( empty( $currencies ) ) {
55 $url = $zoho_inventory_url . 'inventory/v1/settings/currencies?organization_id=' . $zoho_inventory_oid;
56 $execute_curl_call_handle = new CMBIRD_API_Handler_Zoho();
57 $response = $execute_curl_call_handle->execute_curl_call_get( $url );
58 if ( isset( $response->code ) && ( 0 === $response->code || '0' === $response->code ) && ! empty( $response->currencies ) ) {
59 $currencies = $response->currencies;
60 // filter out unnecessary data before caching. Only store currency_id and currency_code.
61 $currencies = array_map(
62 function ( $currency ) {
63 return (object) array(
64 'currency_id' => $currency->currency_id,
65 'currency_code' => $currency->currency_code,
66 );
67 },
68 $currencies
69 );
70 update_option( $cache_key, $currencies, false );
71 }
72 }
73 wp_cache_set( $cache_key, $currencies );
74 }
75
76 if ( empty( $currencies ) ) {
77 return 0;
78 }
79
80 $currency_id = 0;
81 foreach ( $currencies as $value ) {
82 if ( $value->currency_code === $user_currency ) {
83 $currency_id = $value->currency_id;
84 if ( '' === $userid ) {
85 $order->update_meta_data( 'zi_currency_id', $value->currency_id );
86 $order->update_meta_data( 'zi_currency_code', $value->currency_code );
87 } else {
88 update_user_meta( $userid, 'zi_currency_id', $value->currency_id );
89 update_user_meta( $userid, 'zi_currency_code', $value->currency_code );
90 }
91 break;
92 }
93 }
94
95 return $currency_id;
96 }
97 }
98