Changeset 1535401
- Timestamp:
- 11/17/16 02:48:27 (3 months ago)
- Location:
- mauticommerce/trunk
- Files:
-
- 4 edited
-
inc/class.admin.php (modified) (2 diffs)
-
inc/class.order.php (modified) (9 diffs)
-
mauticommerce.php (modified) (7 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mauticommerce/trunk/inc/class.admin.php
r1392590 r1535401 112 112 $this->mauticommece_settings['form_id'] = ''; 113 113 } 114 echo "<input type='text' name='mauticommece_settings[form_id]' value='" . $this->mauticommece_settings['form_id']. "'>";114 echo "<input type='text' name='mauticommece_settings[form_id]' value='" . $this->mauticommece_settings['form_id'] . "'>"; 115 115 } 116 116 … … 124 124 $this->mauticommece_settings['url'] = ''; 125 125 } 126 echo "<input type='url' name='mauticommece_settings[url]' value='" . $this->mauticommece_settings['url']. "' style='width:100%;'>";126 echo "<input type='url' name='mauticommece_settings[url]' value='" . $this->mauticommece_settings['url'] . "' style='width:100%;'>"; 127 127 } 128 128 -
mauticommerce/trunk/inc/class.order.php
r1424450 r1535401 37 37 } 38 38 39 /** 40 * Subscribe order information to Mautic 41 * 42 * @param string $order_id Order 43 * @param string $status post status (default:'new') 44 * @param string $new_status new post status (default:'pending') 45 * @access public 46 * @since 0.0.1 47 **/ 39 48 public function subscribe_to_mautic( $order_id, $status = 'new', $new_status = 'pending' ) { 40 49 $order = wc_get_order( $order_id ); … … 43 52 } 44 53 45 private function _create_query( $order ) { 54 /** 55 * create query to send Mautic 56 * 57 * @param WC_Order $order WooCommerce order object 58 * @since 0.0.1 59 * @access private 60 * @return array $query posted mautic query 61 **/ 62 private function _create_query( WC_Order $order ) { 46 63 $query = array( 47 64 'address1' => $order->billing_address_1, … … 58 75 'order_id' => $order->id, 59 76 ); 77 78 /** 79 * Filter the query that customize Mautic query 80 * 81 * @since 0.0.1 82 * @param $query default mautic query 83 * @param WC_Order $order WooCommerce order object 84 **/ 60 85 return apply_filters( 'mauticommerce_query_mapping', $query, $order ); 61 86 } 62 87 88 /** 89 * Get country name 90 * 91 * @since 0.0.1 92 * @access private 93 * @param string $country_code 94 * @return string $country_name | Exception 95 * @ 96 **/ 63 97 private function _get_country_name( $country_code ) { 64 $countries = wp_remote_get( path_join( M auticommerce__URL, 'inc/assets/json/country.json' ) );98 $countries = wp_remote_get( path_join( MAUTICOMMERCE_URL, 'inc/assets/json/country.json' ) ); 65 99 try { 66 67 68 100 if ( is_wp_error( $countries ) ) { 69 101 throw new Exception( 'invalid json data.' ); … … 76 108 return $country_name; 77 109 } catch ( Exception $e ) { 78 $msg = "Mauticommerce Error:". $e->getMessage();110 $msg = 'Mauticommerce Error:' . $e->getMessage(); 79 111 error_log( $msg ); 80 $WC_Country = new WC_Countries(); 81 return $WC_Country->get_countries()[$country_code]; 82 } 83 } 84 112 $wc_country = new WC_Countries(); 113 return $wc_country->get_countries()[ $country_code ]; 114 } 115 } 116 117 /** 118 * Get state name 119 * 120 * @since 0.0.1 121 * @access private 122 * @param string $country_code country code 123 * @param string $state_code state code 124 * @return string | Exception 125 **/ 85 126 private function _get_states_name( $country_code, $state_code ) { 86 $states = wp_remote_get( path_join( M auticommerce__URL, 'inc/assets/json/states.json' ) );127 $states = wp_remote_get( path_join( MAUTICOMMERCE_URL, 'inc/assets/json/states.json' ) ); 87 128 try { 88 129 if ( is_wp_error( $states ) ) { … … 96 137 return $state_name; 97 138 } catch ( Exception $e ) { 98 $msg = "Mauticommerce Error:". $e->getMessage();139 $msg = 'Mauticommerce Error:' . $e->getMessage(); 99 140 error_log( $msg ); 100 $WC_Country = new WC_Countries(); 101 return $WC_Country->get_states( $country_code )[ $state_code ]; 102 } 103 } 104 141 $wc_country = new WC_Countries(); 142 return $wc_country->get_states( $country_code )[ $state_code ]; 143 } 144 } 145 146 /** 147 * Subscribe to Mautic 148 * 149 * @param array $query Posted mautic query 150 * @access private 151 * @since 0.0.1 152 **/ 105 153 private function _subscribe( $query ) { 106 154 $ip = $this->_get_ip(); … … 124 172 ), 125 173 'body' => $data, 126 'cookies' => array() 174 'cookies' => array(), 127 175 ) 128 176 ); … … 133 181 } 134 182 183 /** 184 * get ip 185 * 186 * @access private 187 * @return string 188 * @since 0.0.1 189 **/ 135 190 private function _get_ip() { 136 191 $ip_list = [ 192 'REMOTE_ADDR', 137 193 'HTTP_CLIENT_IP', 138 194 'HTTP_X_FORWARDED_FOR', … … 140 196 'HTTP_X_CLUSTER_CLIENT_IP', 141 197 'HTTP_FORWARDED_FOR', 142 'HTTP_FORWARDED' 198 'HTTP_FORWARDED', 143 199 ]; 144 200 foreach ( $ip_list as $key ) { … … 148 204 $ip = esc_attr( $_SERVER[ $key ] ); 149 205 if ( ! strpos( $ip, ',' ) ) { 150 $ips = explode( ',', $ip );206 $ips = explode( ',', $ip ); 151 207 foreach ( $ips as &$val ) { 152 208 $val = trim( $val ); 153 209 } 154 $ip = end ( $ips );210 $ip = end( $ips ); 155 211 } 156 212 $ip = trim( $ip ); -
mauticommerce/trunk/mauticommerce.php
r1424450 r1535401 2 2 /** 3 3 * Plugin Name: Mauticommerce 4 * Version: 0.1. 04 * Version: 0.1.1 5 5 * Descrtiption: Senf Woo Wommerce customer information to Mautic Form. 6 6 * Author: hideokamoto … … 12 12 */ 13 13 if ( ! mautic_is_activate_woocommerce() ) { 14 $Mauticommerce_Err = new Mauticommerce_Err(); 15 $msg = array( 16 __( 'MautiCommerce Need "WooCommerce" Plugin.' , 'mauticommerce' ), 17 __( 'Please Activate it.' , 'mauticommerce' ), 18 ); 19 $e = new WP_Error( 'MautiCommerce Activation Error', $msg ); 20 $Mauticommerce_Err->show_error_message( $e ); 21 add_action( 'admin_notices', array( $Mauticommerce_Err, 'admin_notices' ) ); 14 $mauticommerce_err = new Mauticommerce_Err(); 15 $mauticommerce_err->activation_fail(); 22 16 return false; 23 17 } 24 define( 'M auticommerce__PATH', plugin_dir_path( __FILE__ ) );25 define( 'M auticommerce__URL', plugin_dir_url( __FILE__ ) );26 define( 'M auticommerce_ROOT', __FILE__ );18 define( 'MAUTICOMMERCE_PATH', plugin_dir_path( __FILE__ ) ); 19 define( 'MAUTICOMMERCE_URL', plugin_dir_url( __FILE__ ) ); 20 define( 'MAUTICOMMERCE_ROOT', __FILE__ ); 27 21 28 22 require_once 'inc/class.admin.php'; 29 23 require_once 'inc/class.order.php'; 30 24 31 $ Mauticommerce = Mauticommerce::get_instance();32 $ Mauticommerce->init();25 $mauticommerce = Mauticommerce::get_instance(); 26 $mauticommerce->init(); 33 27 34 28 class Mauticommerce { 35 private $Base;36 29 private static $instance; 37 30 private static $text_domain; … … 58 51 59 52 if ( ! $text_domain ) { 60 $data = get_file_data( M auticommerce_ROOT , array( 'text_domain' => 'Text Domain' ) );53 $data = get_file_data( MAUTICOMMERCE_ROOT , array( 'text_domain' => 'Text Domain' ) ); 61 54 $text_domain = $data['text_domain']; 62 55 } … … 69 62 add_action( 'admin_init', array( $admin, 'settings_init' ) ); 70 63 $order = Mauticommerce_Order::get_instance(); 71 add_action( 'woocommerce_checkout_update_order_meta', array( $order, 'subscribe_to_mautic' ) );64 add_action( 'woocommerce_checkout_update_order_meta', array( $order, 'subscribe_to_mautic' ) ); 72 65 } 73 66 } 74 67 75 68 class Mauticommerce_Err { 69 /** 70 * Set Error to fail to Actiavation Plugin 71 * 72 * @since 0.1.1 73 **/ 74 public function activation_fail() { 75 $msg = array( 76 __( 'MautiCommerce Need "WooCommerce" Plugin.' , 'mauticommerce' ), 77 __( 'Please Activate it.' , 'mauticommerce' ), 78 ); 79 $e = new WP_Error( 'MautiCommerce Activation Error', $msg ); 80 $this->show_error_message( $e ); 81 add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 82 return $e; 83 } 76 84 77 85 /** … … 81 89 **/ 82 90 public function admin_notices() { 83 if ( $message List = get_transient( 'mautic-admin-errors' ) ) {84 $this->show_notice_html( $message List );91 if ( $message_list = get_transient( 'mautic-admin-errors' ) ) { 92 $this->show_notice_html( $message_list ); 85 93 } 86 94 } … … 108 116 * @since 0.1.0 109 117 */ 110 public function show_notice_html( $message List ) {111 foreach ( $message List as $key => $messages ) {118 public function show_notice_html( $message_list ) { 119 foreach ( $message_list as $key => $messages ) { 112 120 $html = "<div class='error'><ul>"; 113 foreach ( (array) $messages as $key => $message ) {121 foreach ( (array) $messages as $key => $message ) { 114 122 $html .= "<li>{$message}</li>"; 115 123 } … … 127 135 */ 128 136 function mautic_is_activate_woocommerce() { 129 $active Plugins = get_option('active_plugins');137 $active_plugins = get_option( 'active_plugins' ); 130 138 $plugin = 'woocommerce/woocommerce.php'; 131 if ( ! array_search( $plugin, $active Plugins ) && file_exists( WP_PLUGIN_DIR. '/'. $plugin ) ) {139 if ( ! array_search( $plugin, $active_plugins ) && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) { 132 140 return false; 133 141 } else { -
mauticommerce/trunk/readme.txt
r1424450 r1535401 4 4 Requires at least: 4.4.2 5 5 Tested up to:4.4.2 6 Stable tag: 0.1. 06 Stable tag: 0.1.1 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 21 21 Mautic may or may not be installed before the Mauticommerce plugin. 22 22 You will need a functioning Mautic installation and a new Mautic Form for this plugin to work. 23 24 ## Document 25 - [API reference: https://amimoto-ami.github.io/mauticommerce/index.html](https://amimoto-ami.github.io/mauticommerce/index.html) 23 26 24 27 == Installation == … … 74 77 75 78 == Changelog == 79 = 0.1.1 = 80 * Bug fix 81 * Create document site 76 82 77 83 = 0.1.0 = … … 89 95 == Upgrade Notice == 90 96 91 = 0.1.0 = 92 * Country & State Mapping for Mautic 97 = 0.1.1 = 98 * Bug fix 99 * Create document site
Note: See TracChangeset
for help on using the changeset viewer.