Skip to content

Commit 928e025

Browse files
committed
Frist commit after developing the plugin
0 parents  commit 928e025

File tree

5 files changed

+705
-0
lines changed

5 files changed

+705
-0
lines changed

Rothco.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
Plugin Name: Rothco
5+
Plugin URI: https://facebook.com/ultimatemahbub
6+
Description: This plugin can sync product from Rothco to woocommerce.
7+
Version: 1.1
8+
Author: Mahbubur Rahman
9+
Author URI: http://facebook.com/ultimatemahbub
10+
License: GPL2
11+
*/
12+
13+
14+
15+
if (! defined('ABSPATH')) {
16+
exit;
17+
}
18+
19+
//require_once($_SERVER['DOCUMENT_ROOT'] .'/wp-config.php');
20+
//require_once($_SERVER['DOCUMENT_ROOT'] .'/wp-load.php');
21+
include_once( plugin_dir_path( __FILE__ ) . 'get_categories.php' );
22+
include_once( plugin_dir_path( __FILE__ ) . 'rothco_sync.php' );
23+
include_once( plugin_dir_path( __FILE__ ) . 'homepage.php' );
24+
25+
26+
27+
28+
29+
30+
31+
add_action( 'admin_menu', 'rothco_menu' );
32+
function rothco_menu() {
33+
// add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
34+
add_menu_page( 'Rothco Sync', 'Rothco Sync', 'manage_options', 'Rothco', 'homepage', 'dashicons-screenoptions', 90 );
35+
}
36+
37+
function rothco_admin_enqueue_scripts(){
38+
global $pagenow;
39+
if ($pagenow=='admin.php') {
40+
41+
42+
// register AngularJS
43+
wp_register_script('angular-core', '//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js', array(), null, false);
44+
wp_enqueue_script('angular-core');
45+
46+
// JS
47+
wp_register_script('prefix_bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js');
48+
wp_enqueue_script('prefix_bootstrap');
49+
50+
// CSS
51+
wp_register_style('prefix_bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
52+
wp_enqueue_style('prefix_bootstrap');
53+
54+
55+
wp_enqueue_script('jquery');
56+
wp_enqueue_script( 'jquery-ui-datepicker', array( 'jquery' ) );
57+
58+
wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
59+
wp_enqueue_style( 'jquery-ui' );
60+
61+
}
62+
}
63+
64+
add_action('admin_enqueue_scripts','rothco_admin_enqueue_scripts');
65+

deactivation.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: mahbub
5+
* Date: 16/06/18
6+
* Time: 01:34
7+
*/
8+
9+
10+
register_deactivation_hook(__FILE__, 'rothco_deactivation');
11+
12+
function rothco_deactivation() {
13+
wp_clear_scheduled_hook('hourly_sync');
14+
}

get_categories.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
3+
require __DIR__ . '/vendor/autoload.php';
4+
5+
6+
use Automattic\WooCommerce\Client;
7+
//require_once($_SERVER['DOCUMENT_ROOT'] .'/wp-config.php');
8+
//require_once($_SERVER['DOCUMENT_ROOT'] .'/wp-load.php');
9+
10+
11+
12+
13+
14+
// Making a Cron Scheduler for category syncronization
15+
16+
add_filter( 'cron_schedules', 'cat_sync' );
17+
function cat_sync( $schedules ) {
18+
$schedules['every_x_hour'] = array(
19+
'interval' => 3600,
20+
'display' => __( 'Cron Job for Category sync', 'textdomain' )
21+
);
22+
return $schedules;
23+
}
24+
25+
26+
if ( ! wp_next_scheduled( 'cat_sync' ) ) {
27+
wp_schedule_event( time(), 'every_x_hour', 'cat_sync' );
28+
}
29+
30+
add_action( 'cat_sync', 'update_rothco_cat' );
31+
32+
/* Cron Scheduler End */
33+
34+
35+
function update_rothco_cat(){
36+
global $wpdb;
37+
$available_slugs = $wpdb->get_results( "SELECT slug FROM wpkc_terms");
38+
39+
$slugs = array();
40+
foreach ($available_slugs as $sl){
41+
$s = $sl->slug;
42+
array_push($slugs,$s);
43+
}
44+
45+
46+
$cat_url = 'https://www.rothco.com/api/categories?format=json&key=58580a658e442647cf98ccdbb5aa737c9571db10&ids=';
47+
48+
49+
for ($i=1;$i<634;$i++){
50+
if (empty(in_array($i, $slugs))) {
51+
$new_cat = $cat_url.$i;
52+
$load_content= file_get_contents($new_cat);
53+
$load_json = json_decode($load_content);
54+
$check_null=$load_json->categories;
55+
if (!empty($check_null)) {
56+
$id = $load_json->categories[0]->id;
57+
$name = $load_json->categories[0]->category_name;
58+
$woocommerce = new Client(
59+
'https://wolfgarholsters.com',
60+
'ck_4b991b9563f48a11ccd86b775c166132b935a437',
61+
'cs_fd00d9201756bc5fe0b749bc59a9d1c83a259e09',
62+
[
63+
'wp_api' => true,
64+
'version' => 'wc/v2',
65+
]
66+
);
67+
68+
$data = [
69+
'name' => $name,
70+
'slug' => $id
71+
];
72+
73+
$woocommerce->post('products/categories', $data);
74+
sleep(3);
75+
76+
}else{
77+
print("No Category");
78+
}
79+
}else{
80+
print("already exits");
81+
}
82+
83+
}
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
}
98+
99+

homepage.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: mahbub
5+
* Date: 22/06/18
6+
* Time: 14:25
7+
*/
8+
9+
function homepage(){
10+
$note = 'This is Rothco API consumer Plugin Home Page. You can update this page for further development.';
11+
echo "<br><br><h2>".$note."</h2>";
12+
}

0 commit comments

Comments
 (0)