Skip to content

Commit

Permalink
Merge pull request #3 from affili-ir/v2-commission
Browse files Browse the repository at this point in the history
V2 commission
  • Loading branch information
davodsaraei authored Dec 22, 2021
2 parents 882c64b + a721992 commit 96dce49
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 637 deletions.
2 changes: 1 addition & 1 deletion affili_ir.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Plugin Name: affili_ir
* Plugin URI: https://github.com/affili-ir/wordpress
* Description: The WordPress plugin for Affili's merchants.
* Version: 3.2.0
* Version: 2.0.0
* Author: Affili IR
* Author URI: https://affili.ir
* License: GPLv2 or later
Expand Down
38 changes: 0 additions & 38 deletions assets/css/admin-style-main.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,6 @@
}
}

/* For Select2
.select2-container .select2-selection--single {
height: inherit;
min-height: calc(1.5em + .75rem + 2px);
} */


.wp-core-ui .select2-container .select2-selection--single {
display: block;
width: 100%;
height: calc(1.5em + .75rem + 2px);
padding: .375rem .75rem;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: .25rem;
transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}

.wp-core-ui .select2-container .select2-selection--single {
font-size: 14px;
line-height: 2;
color: #32373c;
border-color: #7e8993;
box-shadow: none;
border-radius: 3px;
padding: 0 8px 0 24px;
min-height: 30px;
-webkit-appearance: none;
cursor: pointer;
vertical-align: middle;
}


.affili-card-inform {
min-width:100%;
margin-top:5px!important;
Expand Down
30 changes: 1 addition & 29 deletions assets/js/admin-script-main.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
jQuery(function($){
// multiple select with AJAX search
$('#affili-ir-select2-categories').select2({
ajax: {
url: ajaxurl, // AJAX URL is predefined in WordPress admin
dataType: 'json',
delay: 250, // delay in ms while typing when to perform a AJAX search
data: function (params) {
return {
q: params.term, // search query
action: 'affili_find_category' // AJAX action for admin-ajax.php
};
},
processResults: function( data ) {
var options = [];
if ( data ) {
// data is the array of arrays, and each of them contains ID and the Label of the option
$.each( data, function( index, text ) { // do not forget that "index" is just auto incremented value
options.push( { id: text[0], text: text[1] } );
});

}
return {
results: options
};
},
cache: true
},
minimumInputLength: 3 // the minimum of symbols to input before perform a search
});
//
});
93 changes: 16 additions & 77 deletions classes/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@


require_once 'Woocommerce.php';
require_once 'ListTable.php';
require_once 'Installer.php';
require_once 'ActivePluginsCheck.php';


use AffiliIR\ActivePluginsCheck as AffiliIR_ActivePluginsCheck;
use AffiliIR\Woocommerce as AffiliIR_Woocommerce;
use AffiliIR\ListTable as AffiliIR_ListTable;
use AffiliIR\Installer as AffiliIR_Installer;

class Action
Expand Down Expand Up @@ -57,27 +53,18 @@ public function menu()

public function renderPage()
{
$show_brand = AffiliIR_ActivePluginsCheck::wooBrandActiveCheck();
$woocommerce = new AffiliIR_Woocommerce;

$account_id = $this->getAccountId();
$custom_code = $this->getCustomCode();
$plugin_name = $this->plugin_name;

$list_table = new AffiliIR_ListTable();
$list_table->prepare_items();

include_once __DIR__.'/../views/form.php';
}

public function loadAdminStyles()
{
wp_enqueue_style( 'affili-ir-admin-style', plugins_url('assets/css/admin-style-main.css',__DIR__), false, '1.0.0' );
wp_enqueue_style( 'affili-ir-admin-style', plugins_url('assets/css/admin-style-main.css',__DIR__), false, '2.0.0' );

wp_enqueue_style('select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css' );
wp_enqueue_script('select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js', array('jquery') );

wp_enqueue_script('affili-ir-admin-script', plugins_url('assets/js/admin-script-main.js', __DIR__), array( 'jquery', 'select2' ) );
wp_enqueue_script('affili-ir-admin-script', plugins_url('assets/js/admin-script-main.js', __DIR__), array( 'jquery') );
}

public function setAccountId()
Expand All @@ -104,9 +91,6 @@ public function setAccountId()
]);
}

$woocommerce = new AffiliIR_Woocommerce;
$woocommerce->insertCommissionKeys($_POST['item']);

$admin_notice = "success";
$message = __('Data saved successful.', $this->plugin_name);

Expand Down Expand Up @@ -186,7 +170,7 @@ public function setAffiliJs()
{
$script = $this->createInlineScript();

wp_enqueue_script("affili-ir-script", "https://analytics.affili.ir/scripts/affili-js.js");
wp_enqueue_script("affili-ir-script", "https://analytics.affili.ir/scripts/affili-v2.js");
wp_add_inline_script("affili-ir-script", $script);
}

Expand All @@ -212,33 +196,28 @@ public function createInlineScript()

public function trackOrders($order_id)
{
$order_id = apply_filters('woocommerce_thankyou_order_id', absint($GLOBALS['order-received']));
$order_key = apply_filters('woocommerce_thankyou_order_key', empty($_GET['key']) ? '' : wc_clean($_GET['key']));
$order_id = apply_filters('woocommerce_thankyou_order_id', absint($GLOBALS['order-received']));
$order_key = apply_filters('woocommerce_thankyou_order_key', empty($_GET['key']) ? '' : wc_clean($_GET['key']));
$woocommerce = new AffiliIR_Woocommerce;
$order = wc_get_order($order_id);
$order = wc_get_order($order_id);

if ($order_id <= 0) return;

$order_key_check = $woocommerce->isWoo3() ? $order->get_order_key() : $order->order_key;

if ($order_key_check !== $order_key) return;
if ($order_key_check != $order_key) return;

$data = $woocommerce->getOrderData($order);

$commissions = $data['commissions'];
$options = $data['options'];
$external_id = $data['external_id'];
$amount = $data['amount'];
$is_multi = $data['is_multi'];
$default_name = $data['default_name'];
// $order_key = $data['order_key'];

// Check if we have multiple commission names
if($is_multi) {
$script = "affili('conversionMulti', '{$external_id}', '{$amount}', {$commissions}, {$options});";
}else {
$script = "affili('conversion', '{$external_id}', '{$amount}', '{$default_name}', {$options})";
}
$order_id = $data['order_id'];
$amount = $data['amount'];
$options = [
'coupon' => $data['coupon'],
'products' => $data['products']
];
$options = count($options) ? json_encode($options) : json_encode($options, JSON_FORCE_OBJECT);

$script = "affili('conversion', '{$order_id}', '{$amount}', {$options})";

wp_add_inline_script("affili-ir-script", $script);
}
Expand All @@ -263,9 +242,6 @@ public function setup()
add_action('wp_head', [$this, 'setAffiliJs'] );

add_action('woocommerce_thankyou', [$this, 'trackOrders']);

add_action('wp_ajax_affili_find_category', [$this, 'findCategoryAjax']);
add_action('wp_ajax_affili_find_brand', [$this, 'findBrandAjax']);
}

public static function factory()
Expand Down Expand Up @@ -329,43 +305,6 @@ protected function addFlashNotice($notice = '', $type = 'success', $dismissible
update_option('affili_flash_notices', $notices );
}

public function findCategoryAjax()
{
// we will pass category IDs and titles to this array
$return = [];

$search_results = (new AffiliIR_Woocommerce)->getCategories(null, [
'name__like' => $_GET['q'],
]);
foreach($search_results as $result) {
$return[] = [
$result->cat_ID,
$result->cat_name,
];
}
echo json_encode( $return );
wp_die();
}

public function findBrandAjax()
{
// we will pass brand IDs and names to this array
$return = [];

$search_results = (new AffiliIR_Woocommerce)->getBrands(null, [
'name__like' => $_GET['q'],
]);

foreach($search_results as $result) {
$return[] = [
$result->term_id,
$result->name,
];
}
echo json_encode( $return );
wp_die();
}

private function createTableIfNotExists()
{
$sql = AffiliIR_Installer::sqlString();
Expand Down
43 changes: 0 additions & 43 deletions classes/ActivePluginsCheck.php

This file was deleted.

4 changes: 2 additions & 2 deletions classes/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class Installer
{
public static $table = 'affili';
public static $table_version = '1.1.0';
public static $table = 'affili';
public static $table_version = '2.0.0';

public static function activation()
{
Expand Down
Loading

0 comments on commit 96dce49

Please sign in to comment.