Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
coax committed Feb 4, 2024
1 parent e1e2717 commit 30bbf57
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 26 deletions.
74 changes: 55 additions & 19 deletions solo-for-woocommerce/lib/solo-woocommerce-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,35 @@
die;
}

// Version check
$version_check = get_transient('solo_tag');
$tag = $installed = 'v' . SOLO_VERSION;
if ($version_check<>$installed) {
$tag = get_transient('solo_tag');
$url = get_transient('solo_url');

if (!$version_check) {
$opts = ['http' => ['method' => 'GET', 'header' => ['User-Agent: PHP']]];
$context = stream_context_create($opts);
$json = file_get_contents('https://api.github.com/repos/coax/solo-for-woocommerce/releases', false, $context);
$decoded_json = json_decode($json, true);
if (isset($decoded_json[0]['name'])) {
$tag = $decoded_json[0]['name'];
$url = $decoded_json[0]['assets'][0]['browser_download_url'];
}
// Create temporary transients (instead session)
set_transient('solo_tag', $tag, 60*60*12);
set_transient('solo_url', $url, 60*60*12);
}

if ($installed<>$tag) {
?>
<div class="notice notice-warning is-dismissible"><p><?php echo __('Dostupna je nova verzija dodatka', 'solo-for-woocommerce'); ?>: <a href="https://github.com/coax/solo-for-woocommerce/releases" target="_blank">Solo for WooCommerce <?php echo $tag; ?></a></p><p><a href="<?php echo $url; ?>" class="button-secondary"><?php echo __('Preuzmi novu verziju', 'solo-for-woocommerce'); ?></a></p></div>
<?php
}
}

// Tabs
$default_tab = null;
$tab = isset($_GET['tab']) ? $_GET['tab'] : $default_tab;

Expand Down Expand Up @@ -66,8 +95,11 @@
<th>
<label for="token"><?php echo __('API token', 'solo-for-woocommerce'); ?><sup class="tooltip" title="<?php echo __('Upiši svoj API token. Token ćeš pronaći u web servisu klikom na Postavke.', 'solo-for-woocommerce'); ?>"></sup></label>
</th>
<td>
<input type="text" name="solo_woocommerce_postavke[token]" id="token" value="<?php echo $token; ?>" autocorrect="off" autocomplete="off" maxlength="33" placeholder="" class="regular-text">
<td class="mailserver-pass-wrap">
<span class="wp-pwd">
<input type="password" name="solo_woocommerce_postavke[token]" id="token" value="<?php echo $token; ?>" autocorrect="off" autocomplete="off" maxlength="33" placeholder="" class="regular-text" class="mailserver-pass-wrap">
<button type="button" class="button wp-hide-pw hide-if-no-js" id="toggle"><span class="dashicons dashicons-visibility"></span></button>
</span>
<p class="description"><?php if ($token==''): ?><?php echo __('Upiši i spremi promjene kako bi se otvorile ostale opcije.', 'solo-for-woocommerce'); ?><?php else: ?><a href="#" class="provjera"><?php echo __('Provjeri valjanost tokena', 'solo-for-woocommerce'); ?></a><?php endif; ?></p>
</td>
</tr>
Expand Down Expand Up @@ -198,34 +230,34 @@
$gateway_title = $translations[$gateway_id];

// Dynamic variable error handling
if (isset(${$gateway_id . '_'})) {
$dynamic_var_ = ${$gateway_id . '_'};
$dynamic_var__ = ${$gateway_id . '__'};
if (isset(${$gateway_id . '1'})) {
$dynamic_var1 = ${$gateway_id . '1'};
$dynamic_var2 = ${$gateway_id . '2'};
} else {
$dynamic_var_ = $dynamic_var__ = '';
$dynamic_var1 = $dynamic_var2 = '';
}
?>
<div class="card">
<h3><a href="admin.php?page=wc-settings&tab=checkout&section=<?php echo esc_attr($gateway_id); ?>" target="_blank"><?php echo $gateway_title; ?></a></h3>
<p><?php echo $gateway_description; ?></p>
<hr>
<label for="<?php echo esc_attr($gateway_id); ?>"><?php echo __('Automatski kreiraj', 'solo-for-woocommerce'); ?></label>
<select name="solo_woocommerce_postavke[<?php echo esc_attr($gateway_id); ?>_]" id="<?php echo esc_attr($gateway_id); ?>">
<select name="solo_woocommerce_postavke[<?php echo esc_attr($gateway_id); ?>1]" id="<?php echo esc_attr($gateway_id); ?>">
<?php
$types = [__('ništa', 'solo-for-woocommerce') => '', __('račun', 'solo-for-woocommerce') => 'racun', __('ponudu', 'solo-for-woocommerce') => 'ponuda'];

foreach ($types as $key => $value) {
echo '<option value="' . $value . '"' . (($dynamic_var_==$value) ? ' selected' : '') . '>' . $key . '</option>';
echo '<option value="' . $value . '"' . (($dynamic_var1==$value) ? ' selected' : '') . '>' . $key . '</option>';
}
?>
</select>
<label for="<?php echo esc_attr($gateway_id); ?>"><?php echo __('u koraku', 'solo-for-woocommerce'); ?></label>
<select name="solo_woocommerce_postavke[<?php echo esc_attr($gateway_id); ?>__]" id="<?php echo esc_attr($gateway_id); ?>">
<label for="<?php echo esc_attr($gateway_id); ?>"><?php echo __('kada', 'solo-for-woocommerce'); ?></label>
<select name="solo_woocommerce_postavke[<?php echo esc_attr($gateway_id); ?>2]" id="<?php echo esc_attr($gateway_id); ?>">
<?php
$actions = ["Checkout" => "on-hold", "Completed" => "completed"];
$actions = ["primiš narudžbu (bez uplate)" => 1, "kupac uplati" => 2];

foreach ($actions as $key => $value) {
echo '<option value="' . $value . '"' . (($dynamic_var__==$value) ? ' selected' : '') . '>' . $key . '</option>';
echo '<option value="' . $value . '"' . (($dynamic_var2==$value) ? ' selected' : '') . '>' . $key . '</option>';
}
?>
</select>
Expand All @@ -235,8 +267,8 @@
}
?>
<br><div class="notice notice-info inline">
<p><?php echo __('<b>Checkout</b> korak se izvršava čim kupac napravi narudžbu neovisno o tipu plaćanja', 'solo-for-woocommerce'); ?></p>
<p><?php echo __('<b>Completed</b> korak se izvršava kada narudžbu obilježiš kao <u>završenu</u> u WooCommerce administraciji ili kada naplata karticom bude uspješna (automatski)', 'solo-for-woocommerce'); ?></p>
<p><?php echo __('Akcija <b>"primiš narudžbu (bez uplate)"</b> se izvršava čim kupac napravi narudžbu neovisno o tipu plaćanja. Takve narudžbe će imati status <span class="status processing">Processing / U obradi</span> ili <span class="status on-hold">On hold / Na čekanju</span> u WooCommerce popisu narudžbi.', 'solo-for-woocommerce'); ?></p>
<p><?php echo __('Akcija <b>"kupac uplati"</b> se izvršava kada narudžbu obilježiš kao <span class="status completed">Completed / Završeno</span> u WooCommerce popisu narudžbi ili kada naplata karticom bude uspješna (trebalo bi automatski promijeniti status).', 'solo-for-woocommerce'); ?></p>
</div>
<?php submit_button(__('Spremi promjene', 'solo-for-woocommerce')); ?>
<?php
Expand Down Expand Up @@ -365,18 +397,22 @@ function timeago($datetime) {
}

foreach($results as $row) {
// Beautify zeroes
$api_request = $row->api_request;
$api_request = preg_replace('/token=[a-zA-Z0-9]{29}/', 'token=*****************************', $api_request);
$api_request = nl2br($api_request);
$api_response = $row->api_response;
$api_response = nl2br($api_response);
$created = $row->created;
$updated = $row->updated;
if (!$updated || $updated=='0000-00-00 00:00:00') $updated = '&ndash;';
// Check if sent to customer
$sent = $row->sent;
if (!$sent || $sent=='0000-00-00 00:00:00') $sent = '&ndash;';
?>
<tr class="shrink">
<td><p><a href="post.php?post=<?php echo $row->order_id; ?>&action=edit"><?php echo $row->order_id; ?></a></p></td>
<td><p><?php echo nl2br($row->api_request); ?></p></td>
<td><p><?php echo nl2br($row->api_response); ?></p></td>
<td><p><?php echo $row->created . '<br>' . timeago($row->created); ?></p></td>
<td><p><?php echo $api_request; ?></p></td>
<td><p><?php echo $api_response; ?></p></td>
<td><p><?php echo $created . '<br>' . timeago($created); ?></p></td>
<td><p><?php echo $updated . '<br>' . timeago($updated); ?></p></td>
<td><p><?php echo $sent . '<br>' . timeago($sent); ?></p></td>
</tr>
Expand Down
6 changes: 5 additions & 1 deletion solo-for-woocommerce/lib/solo-woocommerce.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ sup.tooltip {/*position:relative; display:inline-block; margin-left:6px;*/ posit
sup.tooltip:after {content:'?'; position:absolute; top:0; left:0; width:100%; height:100%; color:#fff; background:#666; border-radius:50%; font-weight:600; text-align:center; font-size:10px;}
.jBox-container {padding:12px; font-size:12px; background:#000; color:#fff; border-radius:4px; max-width:340px; line-height:1.2;}
.spinner {float:none;}
#arhiva tbody tr.shrink p {position:relative; height:75px; overflow:hidden; cursor:pointer;}
#arhiva tbody tr.shrink p {position:relative; height:75px; overflow:hidden; cursor:pointer;}
span.status {padding:3px 6px; border-radius:4px;}
span.status.processing {background:#c6e1c6; color:#5b841b;}
span.status.on-hold {background:#f8dda7; color:#94660c;}
span.status.completed {background:#c8d7e1; color:#2e4453;}
18 changes: 18 additions & 0 deletions solo-for-woocommerce/lib/solo-woocommerce.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions solo-for-woocommerce/solo-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Solo for WooCommerce
* Plugin URI: https://solo.com.hr/api-dokumentacija/dodaci
* Description: Narudžba u tvojoj WooCommerce trgovini će automatski kreirati račun ili ponudu u servisu Solo.
* Version: 1.0
* Version: 1.1
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Solo
Expand All @@ -21,7 +21,7 @@

//// Plugin version
if (!defined('SOLO_VERSION'))
define('SOLO_VERSION', '1.0');
define('SOLO_VERSION', '1.1');

//// Activate plugin
register_activation_hook(
Expand Down Expand Up @@ -536,8 +536,8 @@ function solo_woocommerce_process_order($order_id, $old_status, $new_status) {
foreach ($settings as $key => $value) {
${$key} = $value;
// Find document type and trigger for this order
if ($key==$payment_method . '_') $document_type = $value;
if ($key==$payment_method . '__') $trigger = $value;
if ($key==$payment_method . '1') $document_type = $value;
if ($key==$payment_method . '2') $trigger = $value;
}
}

Expand All @@ -550,8 +550,7 @@ function solo_woocommerce_process_order($order_id, $old_status, $new_status) {
$exists = $wpdb->get_var("SELECT order_id FROM $table_name WHERE order_id=$order_id");

// Proceed on "checkout" or "completed"
if (($new_status=='on-hold' && $old_status=='pending' && $trigger=$new_status && !$exists) || ($new_status=='completed' && $old_status<>$new_status && $trigger=$new_status && !$exists)) {

if (($old_status=='pending' && $new_status=='on-hold' && $trigger==1 && !$exists) || ($old_status=='pending' && $new_status=='processing' && $trigger==1 && !$exists) || ($new_status=='completed' && $old_status<>$new_status && $trigger==2 && !$exists)) {
// Get order information
$date_created = $order->get_date_created();
$kupac_ime = $order->get_billing_first_name();
Expand Down

0 comments on commit 30bbf57

Please sign in to comment.