Plugin Directory

Changeset 2674209


Ignore:
Timestamp:
02/07/2022 11:36:10 AM (4 years ago)
Author:
vuefront
Message:

add version 2.1.2

Location:
vuefront
Files:
491 added
10 edited

Legend:

Unmodified
Added
Removed
  • vuefront/trunk/mapping.json

    r2601831 r2674209  
    2424
    2525    "updateApp": "common/home/updateApp",
     26    "updateSite": "common/home/updateSite",
    2627
    2728    "searchUrl": "common/home/searchUrl",
     
    5859    "updateCart": "store/cart/update",
    5960    "removeCart": "store/cart/remove",
     61    "clearCart": "store/cart/clear",
    6062
    6163    "category": "store/category/get",
     
    8486
    8587    "contactSend": "common/contact/send",
    86     "contact": "common/contact/get"
     88    "contact": "common/contact/get",
     89
     90    "version": "common/home/version"
    8791}
  • vuefront/trunk/plugin.php

    r2640599 r2674209  
    44 * Plugin URI: https://github.com/vuefront/wordpress
    55 * Description: VueFront CMS Connect App for Wordpress.
    6  * Version: 2.1.1
     6 * Version: 2.1.2
    77 * Author: VueFront
    88 * Author URI: http://vuefront.com
     
    3838add_action('wp_ajax_vf_turn_off', 'VFA_vuefront_admin_action_turn_off');
    3939add_action('wp_ajax_vf_information', 'VFA_vuefront_admin_action_vf_information');
    40 register_activation_hook (__FILE__, 'VFA_install');
    41 add_action( 'plugins_loaded', 'VFA_update_db_check' );
     40register_activation_hook(__FILE__, 'VFA_install');
     41
     42add_action('plugins_loaded', 'VFA_update_db_check');
    4243
    4344function VFA_vuefront_admin_styles()
     
    7475}
    7576
    76 function VFA_vuefront_admin_action_settings() {
     77function VFA_vuefront_admin_action_settings()
     78{
    7779    $vfSetting = get_option('vuefront-settings') ? get_option('vuefront-settings') : array();
    7880    echo json_encode(
    79         $vfSetting
    80     , JSON_FORCE_OBJECT);
    81 
    82     wp_die();
    83 }
    84 
    85 function VFA_vuefront_admin_action_settings_edit() {
    86         $vfSetting = json_decode(stripslashes(html_entity_decode($_POST['setting'], ENT_QUOTES, 'UTF-8')), true);
    87         update_option('vuefront-settings', $vfSetting);
    88 
    89         echo json_encode(
    90             array('success' => 'success')
    91         );
     81        $vfSetting,
     82        JSON_FORCE_OBJECT
     83    );
     84
     85    wp_die();
     86}
     87
     88function VFA_vuefront_admin_action_settings_edit()
     89{
     90    $vfSetting = json_decode(stripslashes(html_entity_decode($_POST['setting'], ENT_QUOTES, 'UTF-8')), true);
     91    update_option('vuefront-settings', $vfSetting);
     92
     93    echo json_encode(
     94        array('success' => 'success')
     95    );
    9296   
    93         wp_die();
     97    wp_die();
    9498}
    9599
     
    153157}
    154158
    155 function VFA_install () {
    156    global $wpdb;
    157 
    158    $table_name = $wpdb->prefix . "vuefront_url";
    159 
    160    $charset_collate = $wpdb->get_charset_collate();
    161 
    162    $sql = 'CREATE TABLE IF NOT EXISTS `' . $table_name . '` (
     159function VFA_install()
     160{
     161    global $wpdb;
     162
     163    $table_name = $wpdb->prefix . "vuefront_url";
     164
     165    $charset_collate = $wpdb->get_charset_collate();
     166
     167    $sql = 'CREATE TABLE IF NOT EXISTS `' . $table_name . '` (
    163168            `id_url` int(11) unsigned NOT NULL AUTO_INCREMENT,
    164169            `id` varchar( 255 ) NOT NULL,
     
    168173        ) '.$charset_collate;
    169174
    170    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    171     dbDelta( $sql );
    172 }
    173 
    174 function VFA_update_db_check() {
     175    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
     176    dbDelta($sql);
     177}
     178
     179function VFA_update_db_check()
     180{
    175181    global $vfa_db_version;
    176     if ( get_site_option( 'vfa_db_version' ) != $vfa_db_version ) {
     182    if (get_site_option('vfa_db_version') != $vfa_db_version) {
    177183        VFA_install();
    178184    }
    179185}
    180186
    181 function VFA_vuefront_admin_action_apps_edit() {
     187function VFA_vuefront_admin_action_apps_edit()
     188{
    182189    $setting = get_option('vuefront-apps');
    183190
     
    436443
    437444    $registry->set('request', $request);
     445    $registry->set('response', rest_ensure_response(array()));
    438446
    439447    $output = $registry->get('load')->resolver('startup/startup');
     
    464472        'callback' => 'VFA_RestApi',
    465473    ));
     474
     475    register_rest_route('vuefront/v1', '/graphql', array(
     476      'methods'  => 'GET',
     477      'callback' => 'VFA_RestApi',
     478  ));
    466479
    467480    register_rest_route('vuefront/v1', '/callback', array(
  • vuefront/trunk/readme.txt

    r2640599 r2674209  
    66Tested up to: 5.2.1
    77Requires PHP: 5.5.0
    8 Stable tag: 2.1.1
     8Stable tag: 2.0.0
    99License: GPLv2
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6565
    6666== Changelog ==
    67 = 2.1.1 =
    68 Redesign admin panel
    69 
    70 = 2.1.0 =
    71 Extended API
    72 Bug fixes
    73 
    7467= 2.0.0 =
    7568Added new admin design with Vuejs
  • vuefront/trunk/resolver/common/account.php

    r2601831 r2674209  
    11<?php
    22
    3 class VFA_ResolverCommonAccount extends VFA_Resolver {
    4     public function customerList($args)
     3class VFA_ResolverCommonAccount extends VFA_Resolver
     4{
     5    public function customerList($args)
    56    {
    67        $this->load->model('common/customer');
     
    1112            'sort' => $args['sort'],
    1213            'order' => $args['order'],
    13             'count_total' => true
     14            'count_total' => true
    1415        );
    1516
     
    1819        }
    1920
    20 
    21         $filter_data['role'] = get_option('default_role');
    22 
    23         $args                = wp_parse_args( $filter_data );
    24    
    25         $user_search = new WP_User_Query( $args );
    26    
    27         $customer_total = $user_search->get_total();
    28         $results = $user_search->get_results();
     21        $filter_data['role'] = get_option('default_role');
     22
     23        $args = wp_parse_args($filter_data);
     24   
     25        $user_search = new WP_User_Query($args);
     26   
     27        $customer_total = $user_search->get_total();
     28        $results = $user_search->get_results();
    2929
    3030        $customers = array();
    3131
    3232        foreach ($results as $result) {
    33             $customers[] = $this->get($result->ID);
     33            $customers[] = $this->get($result->ID);
    3434        }
    3535
     
    4646    }
    4747
    48     public function getCustomer($args) {
     48    public function getCustomer($args)
     49    {
    4950        $this->load->model('common/customer');
    5051        $customer_info =  $this->get($args['id']);
     
    5455            'lastName'  => $customer_info['lastName'],
    5556            'email'     => $customer_info['email'],
    56         );
    57     }
    58     public function login( $args ) {
    59 
    60         try {
    61             $this->load->model( 'common/token' );
    62             $token_info = $this->model_common_token->getToken( $args );
    63 
    64             $customer = $this->get($token_info['user_id']);
    65 
    66             $this->load->model('common/vuefront');
    67             $this->model_common_vuefront->pushEvent('login_customer', array(
    68                 'customer_id' => $token_info['user_id'],
    69                 'firstname' => $customer['firstName'],
    70                 'lastname' => $customer['lastName'],
    71                 'email' => $customer['email']
    72             ));
    73 
    74             return array( 'token' => $token_info['token'], 'customer' => $this->get( $token_info['user_id'] ) );
    75 
    76         } catch ( \Exception $e ) {
    77             throw new \Exception( $e->getMessage() );
    78         }
    79     }
    80 
    81     public function logout( $args ) {
    82         global $current_user;
    83 
    84         $user = wp_get_current_user();
    85 
    86         $customer = array(
    87             'id'        => $user->ID,
    88             'email'     => $user->user_email,
    89             'firstName' => $user->user_firstname,
    90             'lastName'  => $user->user_lastname
    91         );
    92 
    93         $this->load->model('common/vuefront');
    94         $this->model_common_vuefront->pushEvent('logout_customer', array(
    95             'customer_id' => $customer['id'],
    96             'firstname' => $customer['firstName'],
    97             'lastname' => $customer['lastName'],
    98             'email' => $customer['email']
    99         ));
    100         wp_logout();
    101 
    102         return array(
    103             'status' => is_user_logged_in()
    104         );
    105     }
    106 
    107     public function register( $args ) {
    108         $customer = $args['customer'];
    109 
    110         $userdata = array(
    111             'user_pass'  => $customer['password'],
    112             'user_login' => $customer['email'],
    113             'user_email' => $customer['email'],
    114             'first_name' => $customer['firstName'],
    115             'last_name'  => $customer['lastName']
    116         );
    117 
    118         $user_id = wp_insert_user( $userdata );
    119         if ( ! is_wp_error( $user_id ) ) {
    120             $this->load->model('common/vuefront');
    121             $this->model_common_vuefront->pushEvent('create_customer', array(
    122                 'customer_id' => $user_id,
    123                 'firstname' => $customer['firstName'],
    124                 'lastname' => $customer['lastName'],
    125                 'email' => $customer['email']
    126             ));
    127             return $this->get( $user_id );
    128         } else {
    129             $error = reset( $user_id->errors );
    130             throw new Exception( $error[0] );
    131         }
    132     }
    133 
    134     public function edit( $args ) {
    135         global $current_user;
    136 
    137         $customer_data = $args['customer'];
    138 
    139         $current_user->first_name = $customer_data['firstName'];
    140         $current_user->last_name  = $customer_data['lastName'];
    141         $current_user->user_email = $customer_data['email'];
    142 
    143         wp_update_user( $current_user );
    144 
    145         return $this->get( $current_user->ID );
    146     }
    147 
    148     public function editPassword( $args ) {
    149         global $current_user;
    150 
    151         return $this->get( $current_user->ID );
    152     }
    153 
    154     public function get( $user_id ) {
    155         $user = get_user_by( 'ID', $user_id );
    156 
    157         return array(
    158             'id'        => $user->ID,
    159             'email'     => $user->user_email,
    160             'firstName' => $user->first_name,
    161             'lastName'  => $user->last_name
    162         );
    163     }
    164 
    165     public function isLogged( $args ) {
    166         $customer = array();
    167 
    168         if ( is_user_logged_in() ) {
    169             $user = wp_get_current_user();
    170 
    171             $customer = array(
    172                 'id'        => $user->ID,
    173                 'email'     => $user->user_email,
    174                 'firstName' => $user->user_firstname,
    175                 'lastName'  => $user->user_lastname
    176             );
    177         }
    178 
    179         return array(
    180             'status'   => is_user_logged_in(),
    181             'customer' => $customer
    182         );
    183     }
    184 
    185     public function address( $args ) {
    186         $address = array();
    187 
    188         global $current_user;
    189 
    190         switch ( $args['id'] ) {
    191             case 'billing':
    192                 $address = array(
    193                     'id'        => 'billing',
    194                     'firstName' => get_user_meta( $current_user->ID, 'billing_first_name', true ),
    195                     'lastName'  => get_user_meta( $current_user->ID, 'billing_last_name', true ),
    196                     'company'   => get_user_meta( $current_user->ID, 'billing_company', true ),
    197                     'address1'  => get_user_meta( $current_user->ID, 'billing_address_1', true ),
    198                     'address2'  => get_user_meta( $current_user->ID, 'billing_address_2', true ),
    199                     'zoneId'    => '',
    200                     'zone'      => array(
    201                         'id'   => '',
    202                         'name' => ''
    203                     ),
    204                     'country'   => $this->load->resolver( 'common/country/get', array(
    205                         'id' => get_user_meta( $current_user->ID, 'billing_country', true )
    206                     ) ),
    207                     'countryId' => get_user_meta( $current_user->ID, 'billing_country', true ),
    208                     'city'      => get_user_meta( $current_user->ID, 'billing_city', true ),
    209                     'zipcode'   => get_user_meta( $current_user->ID, 'billing_postcode', true )
    210                 );
    211                 break;
    212             case 'shipping':
    213                 $address = array(
    214                     'id'        => 'shipping',
    215                     'firstName' => get_user_meta( $current_user->ID, 'shipping_first_name', true ),
    216                     'lastName'  => get_user_meta( $current_user->ID, 'shipping_last_name', true ),
    217                     'company'   => get_user_meta( $current_user->ID, 'shipping_company', true ),
    218                     'address1'  => get_user_meta( $current_user->ID, 'shipping_address_1', true ),
    219                     'address2'  => get_user_meta( $current_user->ID, 'shipping_address_2', true ),
    220                     'zoneId'    => '',
    221                     'zone'      => array(
    222                         'id'   => '',
    223                         'name' => ''
    224                     ),
    225                     'country'   => $this->load->resolver( 'common/country/get', array(
    226                         'id' => get_user_meta( $current_user->ID, 'shipping_country', true )
    227                     ) ),
    228                     'countryId' => get_user_meta( $current_user->ID, 'shipping_country', true ),
    229                     'city'      => get_user_meta( $current_user->ID, 'shipping_city', true ),
    230                     'zipcode'   => get_user_meta( $current_user->ID, 'shipping_postcode', true )
    231                 );
    232                 break;
    233         }
    234 
    235         return $address;
    236     }
    237 
    238     public function addressList( $args ) {
    239 
    240         $ids = array( 'billing', 'shipping' );
    241 
    242         $address = array();
    243 
    244         foreach ( $ids as $value ) {
    245             $address[] = $this->address( array( 'id' => $value ) );
    246         }
    247 
    248         return $address;
    249     }
    250 
    251     public function editAddress( $args ) {
    252         global $current_user;
    253 
    254         $prefix = $args['id'];
    255 
    256         $data = array(
    257             'firstName' => '_first_name',
    258             'lastName'  => '_last_name',
    259             'company'   => '_company',
    260             'address1'  => '_address_1',
    261             'address2'  => '_address_2',
    262             'countryId' => '_country',
    263             'city'      => '_city',
    264             'zipcode'   => '_postcode'
    265         );
    266 
    267         foreach ( $data as $key => $value ) {
    268             update_user_meta( $current_user->ID, $prefix . $value, $args['address'][ $key ] );
    269         }
    270 
    271         return $this->address( $args );
    272     }
    273 
    274     public function addAddress( $args ) {
    275         throw new Exception( 'Adding an address is not possible in Wordpress' );
    276     }
    277 
    278     public function removeAddress( $args ) {
    279         throw new Exception( 'Removing an address is not possible in Wordpress' );
    280     }
     57            'phone'     => get_user_meta($args['id'], 'phone', true)
     58        );
     59    }
     60    public function login($args)
     61    {
     62        try {
     63            $this->load->model('common/token');
     64            $token_info = $this->model_common_token->getToken($args);
     65
     66            $customer = $this->get($token_info['user_id']);
     67
     68            $this->load->model('common/vuefront');
     69            $this->model_common_vuefront->pushEvent('login_customer', array(
     70                'customer_id' => $token_info['user_id'],
     71                'firstname' => $customer['firstName'],
     72                'lastname' => $customer['lastName'],
     73                'email' => $customer['email']
     74            ));
     75
     76            return array( 'token' => $token_info['token'], 'customer' => $this->get($token_info['user_id']) );
     77        } catch (\Exception $e) {
     78            throw new \Exception($e->getMessage());
     79        }
     80    }
     81
     82    public function logout($args)
     83    {
     84        global $current_user;
     85
     86        $user = wp_get_current_user();
     87
     88        $customer = array(
     89            'id'        => $user->ID,
     90            'email'     => $user->user_email,
     91            'firstName' => $user->user_firstname,
     92            'lastName'  => $user->user_lastname
     93        );
     94
     95        $this->load->model('common/vuefront');
     96        $this->model_common_vuefront->pushEvent('logout_customer', array(
     97            'customer_id' => $customer['id'],
     98            'firstname' => $customer['firstName'],
     99            'lastname' => $customer['lastName'],
     100            'email' => $customer['email']
     101        ));
     102        wp_logout();
     103
     104        return array(
     105            'status' => is_user_logged_in()
     106        );
     107    }
     108
     109    public function register($args)
     110    {
     111        $customer = $args['customer'];
     112
     113        $userdata = array(
     114            'user_pass'  => $customer['password'],
     115            'user_login' => $customer['email'],
     116            'user_email' => $customer['email'],
     117            'first_name' => $customer['firstName'],
     118            'last_name'  => $customer['lastName']
     119        );
     120
     121        $user_id = wp_insert_user($userdata);
     122        if (! is_wp_error($user_id)) {
     123            update_user_meta($user_id, 'phone', $customer['phone']);
     124            $this->load->model('common/vuefront');
     125            $this->model_common_vuefront->pushEvent('create_customer', array(
     126                'customer_id' => $user_id,
     127                'firstname' => $customer['firstName'],
     128                'lastname' => $customer['lastName'],
     129                'email' => $customer['email']
     130            ));
     131            return $this->get($user_id);
     132        } else {
     133            $error = reset($user_id->errors);
     134            throw new Exception($error[0]);
     135        }
     136    }
     137
     138    public function edit($args)
     139    {
     140        global $current_user;
     141
     142        $customer_data = $args['customer'];
     143
     144        $current_user->first_name = $customer_data['firstName'];
     145        $current_user->last_name  = $customer_data['lastName'];
     146        $current_user->user_email = $customer_data['email'];
     147
     148        wp_update_user($current_user);
     149
     150        update_user_meta($current_user->ID, 'phone', $customer_data['phone']);
     151
     152        return $this->get($current_user->ID);
     153    }
     154
     155    public function editPassword($args)
     156    {
     157        global $current_user;
     158
     159        return $this->get($current_user->ID);
     160    }
     161
     162    public function get($user_id)
     163    {
     164        $user = get_user_by('ID', $user_id);
     165
     166        return array(
     167            'id'        => $user->ID,
     168            'email'     => $user->user_email,
     169            'firstName' => $user->first_name,
     170            'lastName'  => $user->last_name,
     171            'phone'     => get_user_meta($user_id, 'phone', true)
     172        );
     173    }
     174
     175    public function isLogged($args)
     176    {
     177        $customer = array();
     178
     179        if (is_user_logged_in()) {
     180            $user = wp_get_current_user();
     181
     182            $customer = array(
     183                'id'        => $user->ID,
     184                'email'     => $user->user_email,
     185                'firstName' => $user->user_firstname,
     186                'lastName'  => $user->user_lastname,
     187                'phone'     => get_user_meta($user->ID, 'phone', true)
     188            );
     189        }
     190
     191        return array(
     192            'status'   => is_user_logged_in(),
     193            'customer' => $customer
     194        );
     195    }
     196
     197    public function address($args)
     198    {
     199        $address = array();
     200
     201        global $current_user;
     202
     203        switch ($args['id']) {
     204            case 'billing':
     205                $address = array(
     206                    'id'        => 'billing',
     207                    'firstName' => get_user_meta($current_user->ID, 'billing_first_name', true),
     208                    'lastName'  => get_user_meta($current_user->ID, 'billing_last_name', true),
     209                    'company'   => get_user_meta($current_user->ID, 'billing_company', true),
     210                    'address1'  => get_user_meta($current_user->ID, 'billing_address_1', true),
     211                    'address2'  => get_user_meta($current_user->ID, 'billing_address_2', true),
     212                    'zoneId'    => '',
     213                    'zone'      => array(
     214                        'id'   => '',
     215                        'name' => ''
     216                    ),
     217                    'country'   => $this->load->resolver('common/country/get', array(
     218                        'id' => get_user_meta($current_user->ID, 'billing_country', true)
     219                    )),
     220                    'countryId' => get_user_meta($current_user->ID, 'billing_country', true),
     221                    'city'      => get_user_meta($current_user->ID, 'billing_city', true),
     222                    'zipcode'   => get_user_meta($current_user->ID, 'billing_postcode', true)
     223                );
     224                break;
     225            case 'shipping':
     226                $address = array(
     227                    'id'        => 'shipping',
     228                    'firstName' => get_user_meta($current_user->ID, 'shipping_first_name', true),
     229                    'lastName'  => get_user_meta($current_user->ID, 'shipping_last_name', true),
     230                    'company'   => get_user_meta($current_user->ID, 'shipping_company', true),
     231                    'address1'  => get_user_meta($current_user->ID, 'shipping_address_1', true),
     232                    'address2'  => get_user_meta($current_user->ID, 'shipping_address_2', true),
     233                    'zoneId'    => '',
     234                    'zone'      => array(
     235                        'id'   => '',
     236                        'name' => ''
     237                    ),
     238                    'country'   => $this->load->resolver('common/country/get', array(
     239                        'id' => get_user_meta($current_user->ID, 'shipping_country', true)
     240                    )),
     241                    'countryId' => get_user_meta($current_user->ID, 'shipping_country', true),
     242                    'city'      => get_user_meta($current_user->ID, 'shipping_city', true),
     243                    'zipcode'   => get_user_meta($current_user->ID, 'shipping_postcode', true)
     244                );
     245                break;
     246        }
     247
     248        return $address;
     249    }
     250
     251    public function addressList($args)
     252    {
     253        $ids = array( 'billing', 'shipping' );
     254
     255        $address = array();
     256
     257        foreach ($ids as $value) {
     258            $address[] = $this->address(array( 'id' => $value ));
     259        }
     260
     261        return $address;
     262    }
     263
     264    public function editAddress($args)
     265    {
     266        global $current_user;
     267
     268        $prefix = $args['id'];
     269
     270        $data = array(
     271            'firstName' => '_first_name',
     272            'lastName'  => '_last_name',
     273            'company'   => '_company',
     274            'address1'  => '_address_1',
     275            'address2'  => '_address_2',
     276            'countryId' => '_country',
     277            'city'      => '_city',
     278            'zipcode'   => '_postcode'
     279        );
     280
     281        foreach ($data as $key => $value) {
     282            update_user_meta($current_user->ID, $prefix . $value, $args['address'][ $key ]);
     283        }
     284
     285        return $this->address($args);
     286    }
     287
     288    public function addAddress($args)
     289    {
     290        throw new Exception('Adding an address is not possible in Wordpress');
     291    }
     292
     293    public function removeAddress($args)
     294    {
     295        throw new Exception('Removing an address is not possible in Wordpress');
     296    }
    281297}
  • vuefront/trunk/resolver/common/home.php

    r2601831 r2674209  
    33class VFA_ResolverCommonHome extends VFA_Resolver
    44{
    5     public function get() {
     5    public function get()
     6    {
    67        return array(
    78            'meta' => array(
     
    1314    }
    1415
    15     public function searchUrl($args) {
     16    public function searchUrl($args)
     17    {
    1618        $this->load->model('common/seo');
    1719
     
    2931    }
    3032
     33    public function updateSite($args)
     34    {
     35        try {
     36            $tmpFile = download_url("https://vuefront2019.s3.amazonaws.com/sites/".$args['number']."/vuefront-app.tar");
     37            VFA_vuefront_rmdir(ABSPATH . 'vuefront');
     38            $phar = new PharData($tmpFile);
     39            $phar->extractTo(ABSPATH . 'vuefront');
     40        } catch (\Exception $e) {
     41            echo $e->getMessage();
     42        }
     43    }
     44
    3145    public function authProxy($args)
    3246    {
    3347        $this->load->model('common/vuefront');
    3448
    35         if (!is_user_logged_in() ) {
     49        if (!is_user_logged_in()) {
    3650            return;
    3751        }
     
    5165        return $result['token'];
    5266    }
     67
     68    public function version()
     69    {
     70        return "1.0.0";
     71    }
    5372}
  • vuefront/trunk/resolver/startup/startup.php

    r2601831 r2674209  
    88    public function index()
    99    {
    10         if ($this->request->get_param('cors')) {
    11             if (! empty($_SERVER['HTTP_ORIGIN'])) {
    12                 header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
    13             } else {
    14                 header('Access-Control-Allow-Origin: *');
    15             }
    16             header('Access-Control-Allow-Methods: POST, OPTIONS');
    17             header('Access-Control-Allow-Credentials: true');
    18             header('Access-Control-Allow-Headers: accept,Referer,content-type,x-forwaded-for,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,cache-control,Content-Type,Range,Token,token,Cookie,cookie,content-type');
    19         }
    20 
    21         $this->load->model('startup/startup');
    22         $this->load->model('common/vuefront');
    23 
    24         try {
    25             $resolvers = $this->model_startup_startup->getResolvers();
    26             $files = array(VFA_DIR_PLUGIN . 'schema.graphql');
    27 
    28             if ($this->model_common_vuefront->checkAccess()) {
    29                 $files[] = VFA_DIR_PLUGIN . 'schemaAdmin.graphql';
     10        if ($this->request->get_method() === 'POST') {
     11            if ($this->request->get_param('cors')) {
     12                if (! empty($_SERVER['HTTP_ORIGIN'])) {
     13                    header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
     14                } else {
     15                    header('Access-Control-Allow-Origin: *');
     16                }
     17                header('Access-Control-Allow-Methods: POST, OPTIONS');
     18                header('Access-Control-Allow-Credentials: true');
     19                header('Access-Control-Allow-Headers: accept,Referer,content-type,x-forwaded-for,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,cache-control,Content-Type,Range,Token,token,Cookie,cookie,content-type');
    3020            }
    3121
    32             $sources = array_map('file_get_contents', $files);
     22            $this->load->model('startup/startup');
     23            $this->load->model('common/vuefront');
    3324
    34             $source = $this->model_common_vuefront->mergeSchemas(($sources));
    35             $schema    = BuildSchema::build($source);
    36             $rawInput  = file_get_contents('php://input');
    37             $input     = json_decode($rawInput, true);
    38             $query     = $input['query'];
     25            try {
     26                $resolvers = $this->model_startup_startup->getResolvers();
     27                $files = array(VFA_DIR_PLUGIN . 'schema.graphql');
    3928
    40             $variableValues = isset($input['variables']) ? $input['variables'] : null;
    41             $result         = GraphQL::executeQuery($schema, $query, $resolvers, null, $variableValues);
    42         } catch (\Exception $e) {
    43             $result = [
     29                if ($this->model_common_vuefront->checkAccess()) {
     30                    $files[] = VFA_DIR_PLUGIN . 'schemaAdmin.graphql';
     31                }
     32
     33                $sources = array_map('file_get_contents', $files);
     34
     35                $source = $this->model_common_vuefront->mergeSchemas(($sources));
     36                $schema    = BuildSchema::build($source);
     37                $rawInput  = file_get_contents('php://input');
     38                $input     = json_decode($rawInput, true);
     39                $query     = $input['query'];
     40
     41                $variableValues = isset($input['variables']) ? $input['variables'] : null;
     42                $result         = GraphQL::executeQuery($schema, $query, $resolvers, null, $variableValues);
     43            } catch (\Exception $e) {
     44                $result = [
    4445                'error' => [
    4546                    'message' => $e->getMessage()
    4647                ]
    4748            ];
     49            }
     50
     51            $this->response->set_data($result);
     52            return $this->response;
     53        } else {
     54            header('Content-type: text/html');
     55            echo "<html> <head> <title>Simple GraphiQL Example</title> <link href='https://unpkg.com/graphiql/graphiql.min.css' rel='stylesheet'/> </head> <body style='margin: 0;'> <div id='graphiql' style='height: 100vh;'></div><script crossorigin src='https://unpkg.com/react/umd/react.production.min.js' ></script> <script crossorigin src='https://unpkg.com/react-dom/umd/react-dom.production.min.js' ></script> <script crossorigin src='https://unpkg.com/graphiql/graphiql.min.js' ></script> <script>const fetcher=GraphiQL.createFetcher({url: window.location.href}); ReactDOM.render( React.createElement(GraphiQL,{fetcher: fetcher}), document.getElementById('graphiql'), ); </script> </body> </html>";
     56            exit;
    4857        }
    49 
    50 
    51         return $result;
    5258    }
    5359
  • vuefront/trunk/resolver/store/cart.php

    r2601831 r2674209  
    33class VFA_ResolverStoreCart extends VFA_Resolver
    44{
    5     public function add($args) {
     5    public function add($args)
     6    {
    67        $this->load->model('store/product');
    78        $this->load->model('store/cart');
     
    1516            }
    1617            $variation_id = $this->find_matching_product_variation_id($args['id'], $options);
    17             if(!$variation_id) {
     18            if (!$variation_id) {
    1819                throw new \Exception('Please select an option.');
    1920            }
     
    3233        return $this->get($args);
    3334    }
    34     public function update($args) {
     35    public function update($args)
     36    {
    3537        WC()->cart->set_quantity($args['key'], $args['quantity']);
    3638
     39        $this->load->model('store/cart');
    3740        $this->load->model('common/vuefront');
    3841        $this->model_common_vuefront->pushEvent('update_cart', array(
     
    4447        return $this->get($args);
    4548    }
    46     public function remove($args) {
     49    public function remove($args)
     50    {
    4751        WC()->cart->remove_cart_item($args['key']);
    4852
     53        $this->load->model('store/cart');
    4954        $this->load->model('common/vuefront');
    5055        $this->model_common_vuefront->pushEvent('update_cart', array(
     
    5661        return $this->get($args);
    5762    }
    58     public function get($args) {
     63    public function get($args)
     64    {
    5965        $cart = array();
    6066        $this->load->model('store/product');
     
    8288    }
    8389
     90    public function clear($args)
     91    {
     92        WC()->cart->empty_cart();
     93
     94        $this->load->model('common/vuefront');
     95        $this->model_common_vuefront->pushEvent('update_cart', array(
     96          'cart' => $this->model_store_cart->prepareCart(),
     97          'customer_id' => '',
     98          'guest' => false
     99      ));
     100        return $this->get($args);
     101    }
     102
    84103    public function find_matching_product_variation_id($product_id, $attributes)
    85104    {
  • vuefront/trunk/schema.graphql

    r2601831 r2674209  
    9292  lastName: String
    9393  email: String
     94  phone: String
    9495}
    9596
     
    9899  lastName: String
    99100  email: String
     101  phone: String
    100102  password: String
    101103}
     
    485487  manufacturer(id: String): Manufacturer
    486488  authProxy(app: String): String
     489  version: String
    487490}
    488491
     
    501504  updateCart(key: String, quantity: Int = 1): Cart
    502505  removeCart(key: String): Cart
     506  clearCart: Cart
    503507  addToCompare(id: Int): [Product]
    504508  removeCompare(id: String): [Product]
  • vuefront/trunk/schemaAdmin.graphql

    r2601831 r2674209  
    4949type RootMutationType {
    5050   updateApp(name: String, settings: InputAppSetting): AppSetting
     51   updateSite(number: Int): Boolean
    5152}
  • vuefront/trunk/system/engine/resolver.php

    r2601831 r2674209  
    1818 * @property VFA_ModelStoreManufacturer $model_store_manufacturer
    1919 * @property WP_REST_Request $request
     20 * @property WP_REST_Response $response
    2021 */
    21 abstract class VFA_Resolver {
    22     protected $registry;
     22abstract class VFA_Resolver
     23{
     24    protected $registry;
    2325
    24     public function __construct($registry) {
    25         $this->registry = $registry;
    26     }
     26    public function __construct($registry)
     27    {
     28        $this->registry = $registry;
     29    }
    2730
    28     public function __get($key) {
    29         return $this->registry->get($key);
    30     }
     31    public function __get($key)
     32    {
     33        return $this->registry->get($key);
     34    }
    3135
    32     public function __set($key, $value) {
    33         $this->registry->set($key, $value);
    34     }
     36    public function __set($key, $value)
     37    {
     38        $this->registry->set($key, $value);
     39    }
    3540}
Note: See TracChangeset for help on using the changeset viewer.