Overview
  • Namespace
  • Class

Namespaces

  • None
  • WC_POS
    • Admin
      • Settings
        • Receipt
    • API
    • Gateways
    • Integrations
    • Products

Classes

  • WC_POS\Activator
  • WC_POS\Admin
  • WC_POS\Admin\Gateways
  • WC_POS\Admin\Menu
  • WC_POS\Admin\Notices
  • WC_POS\Admin\Orders
  • WC_POS\Admin\Page
  • WC_POS\Admin\Permalink
  • WC_POS\Admin\Plugins
  • WC_POS\Admin\Products
  • WC_POS\Admin\Settings
  • WC_POS\Admin\Settings\Access
  • WC_POS\Admin\Settings\Checkout
  • WC_POS\Admin\Settings\Customers
  • WC_POS\Admin\Settings\Gateways
  • WC_POS\Admin\Settings\General
  • WC_POS\Admin\Settings\HotKeys
  • WC_POS\Admin\Settings\Page
  • WC_POS\Admin\Settings\Receipt\Options
  • WC_POS\Admin\Settings\Receipt\Template
  • WC_POS\Admin\Settings\Receipts
  • WC_POS\Admin\Settings\Status
  • WC_POS\Admin\Settings\Tools
  • WC_POS\Admin\Status
  • WC_POS\Ajax
  • WC_POS\API
  • WC_POS\API\Coupons
  • WC_POS\API\Customers
  • WC_POS\API\Gateways
  • WC_POS\API\i18n
  • WC_POS\API\Orders
  • WC_POS\API\Params
  • WC_POS\API\Payload
  • WC_POS\API\Products
  • WC_POS\API\Settings
  • WC_POS\API\Support
  • WC_POS\API\Templates
  • WC_POS\Customers
  • WC_POS\Deactivator
  • WC_POS\Gateways
  • WC_POS\Gateways\Card
  • WC_POS\Gateways\Cash
  • WC_POS\i18n
  • WC_POS\Integrations\Bookings
  • WC_POS\Products
  • WC_POS\Products\Visibility
  • WC_POS\Setup
  • WC_POS\Status
  • WC_POS\Tax
  • WC_POS\Template

Functions

  • is_pos
  • is_pos_admin
  • wc_pos_get_option
  • wc_pos_json_encode
  • wc_pos_locate_template
  • wc_pos_trim_html_string
  • wc_pos_update_option
  • wc_pos_url
  1 <?php
  2 
  3 /**
  4  * POS App parameters
  5  *
  6  * @class    WC_POS_API_Params
  7  * @package  WooCommerce POS
  8  * @author   Paul Kilmurray <paul@kilbot.com.au>
  9  * @link     http://www.woopos.com.au
 10  */
 11 
 12 namespace WC_POS\API;
 13 
 14 use WC_API_Resource;
 15 use WC_API_Server;
 16 use WC_POS\Admin\Settings;
 17 use WC_POS\i18n;
 18 use WC_POS\Tax;
 19 
 20 class Params extends WC_API_Resource {
 21 
 22   protected $base = '/pos/params';
 23 
 24   /**
 25    * Register routes for POS Params
 26    *
 27    * GET /pos
 28    *
 29    * @param array $routes
 30    * @return array
 31    */
 32   public function register_routes( array $routes ){
 33 
 34     # GET /pos/params
 35     $routes[ $this->base ] = array(
 36       array( array( $this, 'get_params' ), WC_API_Server::READABLE )
 37     );
 38 
 39     return $routes;
 40 
 41   }
 42 
 43   /**
 44    * @param null $wc_pos_admin
 45    * @return array
 46    */
 47   public function get_params( $wc_pos_admin = null ){
 48     if( $wc_pos_admin ){
 49       $params = apply_filters( 'woocommerce_pos_{$wc_pos_admin}_params', $this->common_params() + $this->admin_params(), $this );
 50     } else {
 51       $params = apply_filters( 'woocommerce_pos_params', $this->common_params() + $this->frontend_params(), $this );
 52     }
 53     return $params;
 54   }
 55 
 56   /**
 57    *
 58    */
 59   private function common_params(){
 60     return array(
 61       'accounting'  => $this->accounting(),
 62       'customers'   => $this->customers(),
 63       'debug'       => defined( '\SCRIPT_DEBUG' ) && \SCRIPT_DEBUG,
 64       'emulateHTTP' => get_option( 'woocommerce_pos_emulateHTTP' ) === '1',
 65       'idbVersion'  => Settings::get_idb_version(),
 66       'store'         => array( 'name' => get_bloginfo( 'name' ) )
 67     );
 68   }
 69 
 70   /**
 71    *
 72    */
 73   private function frontend_params(){
 74     return array(
 75       'auto_print'    => wc_pos_get_option( 'checkout', 'auto_print_receipt' ),
 76       'denominations' => i18n::currency_denominations(),
 77       'discount_keys' => wc_pos_get_option( 'general', 'discount_quick_keys' ),
 78       'fee'           => wc_pos_get_option( 'general', 'fee' ),
 79       'hotkeys'       => wc_pos_get_option( 'hotkeys', 'hotkeys' ),
 80       'menu'          => $this->menu(),
 81       'shipping'      => $this->shipping(),
 82       'tabs'          => $this->product_tabs(),
 83       'tax'           => $this->tax(),
 84       'tax_classes'   => Tax::tax_classes(),
 85       'tax_rates'     => Tax::tax_rates(),
 86       'user'          => $this->user()
 87     );
 88   }
 89 
 90   /**
 91    *
 92    */
 93   private function admin_params(){
 94     return array(
 95       'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
 96       'nonce'       => wp_create_nonce( \WC_POS\PLUGIN_NAME ),
 97     );
 98   }
 99 
100   /**
101    * Default quick tabs for products
102    *
103    * @return array
104    */
105   private function product_tabs() {
106     return array(
107       'all' => array(
108         /* translators: woocommerce */
109         'label' => __( 'All', 'woocommerce'),
110         'active' => true
111       ),
112       'featured' => array(
113         /* translators: woocommerce */
114         'label' => __( 'Featured', 'woocommerce'),
115         'id' => 'featured:true'
116       ),
117       'onsale' => array(
118         'label' => _x( 'On Sale', 'Product tab: \'On Sale\' products', 'woocommerce-pos'),
119         'id' => 'on_sale:true'
120       ),
121     );
122   }
123 
124   /**
125    * Get the accounting format from user settings
126    * POS uses a plugin to format currency: http://josscrowcroft.github.io/accounting.js/
127    *
128    * @return array $settings
129    */
130   private function accounting() {
131     $decimal    = get_option( 'woocommerce_price_decimal_sep' );
132     $thousand   = get_option( 'woocommerce_price_thousand_sep' );
133     $precision  = get_option( 'woocommerce_price_num_decimals' );
134     return array(
135       'currency' => array(
136         'decimal'   => $decimal,
137         'format'    => $this->currency_format(),
138         'precision' => $precision,
139         'symbol'    => get_woocommerce_currency_symbol( get_woocommerce_currency() ),
140         'thousand'  => $thousand,
141       ),
142       'number' => array(
143         'decimal'   => $decimal,
144         'precision' => $precision,
145         'thousand'  => $thousand,
146       )
147     );
148   }
149 
150   /**
151    * Get the currency format from user settings
152    *
153    * @return array $format
154    */
155   private function currency_format() {
156     $currency_pos = get_option( 'woocommerce_currency_pos' );
157 
158     if( $currency_pos == 'right' )
159       return array('pos' => '%v%s', 'neg' => '- %v%s', 'zero' => '%v%s');
160 
161     if( $currency_pos == 'left_space' )
162       return array('pos' => '%s&nbsp;%v', 'neg' => '- %s&nbsp;%v', 'zero' => '%s&nbsp;%v');
163 
164     if( $currency_pos == 'right_space' )
165       return array('pos' => '%v&nbsp;%s', 'neg' => '- %v&nbsp;%s', 'zero' => '%v&nbsp;%s');
166 
167     // default = left
168     return array('pos' => '%s%v', 'neg' => '- %s%v', 'zero' => '%s%v');
169   }
170 
171   /**
172    * Get the default customer + guest
173    *
174    * @return object $customer
175    */
176   private function customers() {
177 
178     $user_id = wc_pos_get_option( 'customers', 'logged_in_user' ) ?
179       get_current_user_id() :
180       wc_pos_get_option( 'customers', 'default_customer' );
181 
182     if( $user_id ) {
183       $user = get_userdata($user_id);
184       $customers['default'] = array(
185         'id' => $user->ID,
186         'first_name'  => esc_html($user->first_name),
187         'last_name'   => esc_html($user->last_name),
188         'email'       => esc_html($user->user_email),
189         'username'    => esc_html($user->user_login)
190       );
191     }
192 
193     $customers['guest'] = array(
194       'id' => 0,
195       /* translators: woocommerce */
196       'first_name' => __( 'Guest', 'woocommerce' )
197     );
198 
199     return $customers;
200   }
201 
202   /**
203    * Get the woocommerce shop settings
204    *
205    * @return array $settings
206    */
207   private function tax() {
208     return array(
209       'tax_label'             => WC()->countries->tax_or_vat(),
210       'calc_taxes'            => get_option( 'woocommerce_calc_taxes' ),
211       'prices_include_tax'    => get_option( 'woocommerce_prices_include_tax' ),
212       'tax_round_at_subtotal' => get_option( 'woocommerce_tax_round_at_subtotal' ),
213       'tax_display_cart'      => get_option( 'woocommerce_tax_display_cart' ),
214       'tax_total_display'     => get_option( 'woocommerce_tax_total_display' ),
215     );
216   }
217 
218   /**
219    * User settings
220    *
221    * @return array $settings
222    */
223   private function user() {
224     global $current_user;
225 
226     return array(
227       'id'           => $current_user->ID,
228       'username'     => $current_user->user_login,
229       'first_name'   => $current_user->user_firstname,
230       'last_name'    => $current_user->user_lastname,
231       'display_name' => $current_user->display_name,
232       'email'        => $current_user->user_email
233     );
234   }
235 
236   /**
237    *
238    */
239   private function shipping(){
240     $shipping = wc_pos_get_option( 'general', 'shipping' );
241     $shipping['labels'] = self::shipping_labels();
242     return $shipping;
243   }
244 
245   /**
246    * @return array
247    */
248   static public function shipping_labels() {
249 
250     /* translators: woocommerce */
251     $labels = array( '' => __( 'N/A', 'woocommerce' ) );
252 
253     $shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array();
254 
255     foreach( $shipping_methods as $method ){
256       $labels[$method->id] = $method->get_title();
257     }
258 
259     /* translators: woocommerce */
260     $labels['other'] = __( 'Other', 'woocommerce' );
261 
262     return $labels;
263   }
264 
265   /**
266    *
267    */
268   private function menu() {
269 
270     return apply_filters( 'woocommerce_pos_menu', array(
271       array(
272         'id'     => 'pos',
273         'label'  => __( 'POS', 'woocommerce-pos' ),
274         'href'   => '#'
275       ),
276       array(
277         'id'     => 'products',
278         /* translators: woocommerce */
279         'label'  => __( 'Products', 'woocommerce' ),
280         'href'   => admin_url('edit.php?post_type=product')
281       ),
282       array(
283         'id'     => 'orders',
284         /* translators: woocommerce */
285         'label'  => __( 'Orders', 'woocommerce' ),
286         'href'   => admin_url('edit.php?post_type=shop_order')
287       ),
288       array(
289         'id'     => 'customers',
290         /* translators: woocommerce */
291         'label'  => __( 'Customers', 'woocommerce' ),
292         'href'   => admin_url('users.php')
293       ),
294       array(
295         'id'     => 'coupons',
296         /* translators: woocommerce */
297         'label' => __( 'Coupons', 'woocommerce' ),
298         'href'   => admin_url('edit.php?post_type=shop_coupon')
299       ),
300       array(
301         'id'     => 'support',
302         /* translators: woocommerce */
303         'label'  => __( 'Support', 'woocommerce' ),
304         'href'   => '#support'
305       )
306     ));
307 
308   }
309 
310 }
API documentation generated by ApiGen