Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
update coupon code module to laravel api routes
  • Loading branch information
bobimicroweber committed Mar 15, 2022
1 parent 437a4be commit 9ea93e8
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 17 deletions.
16 changes: 13 additions & 3 deletions userfiles/modules/shop/coupons/config.php
Expand Up @@ -9,7 +9,6 @@
* @copyright 2018 Microweber
*/


$config = array();
$config['name'] ="Coupons";
$config['author'] = "Bozhidar Slaveykov";
Expand All @@ -18,9 +17,20 @@
$config['ui_admin'] = false;

$config['categories'] = "online shop";
$config['version'] = 0.24;
$config['version'] = "0.3";
$config['position'] = 26;

/*
$config['settings']['autoload_namespace'] = [
[
'path' => _DIR_ . '/src/',
'namespace' => 'MicroweberPackages\\Modules\\Shop\\Coupons\\'
],
];*/
$config['settings']['service_provider'] = [
\MicroweberPackages\Modules\Shop\Coupons\ShopCouponServiceProvider::class
];

$config['tables'] = array(
'cart_coupons' => array(
'id' => 'integer',
Expand All @@ -42,4 +52,4 @@
'uses_count' => 'integer',
'use_date' => 'dateTime'
)
);
);
26 changes: 12 additions & 14 deletions userfiles/modules/shop/coupons/functions.php
Expand Up @@ -10,7 +10,8 @@
*/
include __DIR__ . DS . 'src/CouponClass.php';

api_expose('coupon_apply');
autoload_add_namespace(__DIR__ . '/src/', 'MicroweberPackages\\Modules\\Shop\\Coupons\\');

function coupon_apply($params = array())
{
$json = array();
Expand Down Expand Up @@ -97,7 +98,6 @@ function coupon_apply($params = array())
return $json;
}

api_expose_admin('coupons_save_coupon');
function coupons_save_coupon($couponData = array())
{
$json = array();
Expand Down Expand Up @@ -149,7 +149,7 @@ function coupons_save_coupon($couponData = array())
return $json;
}

api_expose_admin('coupon_log_customer');

function coupon_log_customer($coupon_code, $customer_email, $customer_ip)
{
$coupon = coupon_get_by_code($coupon_code);
Expand Down Expand Up @@ -178,7 +178,7 @@ function coupon_log_customer($coupon_code, $customer_email, $customer_ip)
$couponLogId = db_save($table, $couponLogData);
}

api_expose_admin('coupon_log_get_by_code_and_customer_email_and_ip');

function coupon_log_get_by_code_and_customer_email_and_ip($coupon_code, $customer_email, $customer_ip)
{
$table = "cart_coupon_logs";
Expand All @@ -192,7 +192,6 @@ function coupon_log_get_by_code_and_customer_email_and_ip($coupon_code, $custome
));
}

api_expose_admin('coupon_log_get_by_code_and_customer_ip');
function coupon_log_get_by_code_and_customer_ip($coupon_code, $customer_ip)
{
$table = "cart_coupon_logs";
Expand All @@ -205,7 +204,6 @@ function coupon_log_get_by_code_and_customer_ip($coupon_code, $customer_ip)
));
}

api_expose_admin('coupon_logs_get_by_code');
function coupon_logs_get_by_code($coupon_code)
{
$table = "cart_coupon_logs";
Expand All @@ -216,7 +214,6 @@ function coupon_logs_get_by_code($coupon_code)
->toArray();
}

api_expose_admin('coupon_get_all');
function coupon_get_all()
{
$table = 'cart_coupons';
Expand All @@ -233,7 +230,6 @@ function coupon_get_all()
}


api_expose_admin('coupon_logs');
function coupon_logs()
{
$table = 'cart_coupon_logs';
Expand All @@ -249,7 +245,6 @@ function coupon_logs()
return $readyCoupons;
}

api_expose_admin('coupon_get_by_id');
function coupon_get_by_id($coupon_id)
{
$table = "cart_coupons";
Expand All @@ -261,7 +256,6 @@ function coupon_get_by_id($coupon_id)
));
}

api_expose_admin('coupon_get_by_code');
function coupon_get_by_code($coupon_code)
{
$table = "cart_coupons";
Expand All @@ -276,14 +270,19 @@ function coupon_get_by_code($coupon_code)
return $get;
}

api_expose('coupon_delete');
function coupon_delete()
function coupon_delete($data)
{
if (!is_admin())
return;

$table = "cart_coupons";
$couponId = (int)$_POST['coupon_id'];

$couponId = (int) $data['coupon_id'];
if ($couponId == 0) {
return array(
'status' => 'failed'
);
}

$delete = db_delete($table, $couponId);

Expand All @@ -298,7 +297,6 @@ function coupon_delete()
}
}

api_expose_admin('coupons_delete_session');
function coupons_delete_session()
{
mw()->user_manager->session_del('coupon_code');
Expand Down
14 changes: 14 additions & 0 deletions userfiles/modules/shop/coupons/src/ShopCouponServiceProvider.php
@@ -0,0 +1,14 @@
<?php
namespace MicroweberPackages\Modules\Shop\Coupons;


use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class ShopCouponServiceProvider extends ServiceProvider
{
public function register()
{
$this->loadRoutesFrom(__DIR__ . '/routes/api.php');
}
}
39 changes: 39 additions & 0 deletions userfiles/modules/shop/coupons/src/routes/api.php
@@ -0,0 +1,39 @@
<?php
use Illuminate\Support\Facades\Route;

\Route::name('api.')

->prefix('api')
->middleware(['api', 'xss', \Illuminate\Routing\Middleware\ThrottleRequests::class])
// ->namespace('MicroweberPackages\Modules\Shop\Coupons')
->group(function () {

Route::post('coupon_apply', function () {
$data = request()->all();
return coupon_apply($data);
});
Route::post('coupons_delete_session', function () {
$data = request()->all();
return coupons_delete_session($data);
});

});

\Route::name('api.')

->prefix('api')
->middleware(['api', 'xss', 'admin', \Illuminate\Routing\Middleware\ThrottleRequests::class])
// ->namespace('MicroweberPackages\Modules\Shop\Coupons')
->group(function () {

Route::post('coupons_save_coupon', function () {
$data = request()->all();
return coupons_save_coupon($data);
});

Route::post('coupon_delete', function () {
$data = request()->all();
return coupon_delete($data);
});

});

0 comments on commit 9ea93e8

Please sign in to comment.