Plugin Directory

Changeset 3435849


Ignore:
Timestamp:
01/09/2026 11:35:18 AM (3 months ago)
Author:
openpos
Message:

update pos url

Location:
wpos-lite-version
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • wpos-lite-version/tags/3.0/includes/Core.php

    r3377825 r3435849  
    21612161    function get_pos_url($sub_str = ''){
    21622162     
    2163         $pos_url = apply_filters('op_pos_url',WPOSL_URL.'/pos/');
    2164         if($sub_str)
    2165         {
    2166             $pos_url = trim(rtrim($pos_url,'/'));   
    2167            
    2168             $pos_url .= '/'.$sub_str;
    2169         }
     2163        $pos_url = apply_filters('op_pos_url','https://pos.wpos.app/#/');
     2164       
     2165       
    21702166        return  $pos_url;
    21712167    }
  • wpos-lite-version/tags/3.1/includes/Core.php

    r3377906 r3435849  
    21612161    function get_pos_url($sub_str = ''){
    21622162     
    2163         $pos_url = apply_filters('op_pos_url',WPOSL_URL.'/pos/');
    2164         if($sub_str)
    2165         {
    2166             $pos_url = trim(rtrim($pos_url,'/'));   
    2167            
    2168             $pos_url .= '/'.$sub_str;
    2169         }
     2163        $pos_url = apply_filters('op_pos_url','https://pos.wpos.app/#/');
     2164       
     2165       
    21702166        return  $pos_url;
    21712167    }
  • wpos-lite-version/tags/3.1/readme.txt

    r3377296 r3435849  
    3939
    4040🎥 Watch the demo video:
    41 https://www.youtube.com/watch?v=dQw4w9WgXcQ
     41https://youtu.be/zqCd4Ox3NIk?si=CUv6q0m76N4inOMM
    4242
    4343---
  • wpos-lite-version/trunk/includes/Core.php

    r3376736 r3435849  
    4949            $locale = determine_locale();
    5050            unload_textdomain( 'openpos', true );
    51             load_textdomain( 'openpos', trailingslashit(OPENPOS_DIR).'languages/openpos-' . $locale . '.mo' );
    52             load_plugin_textdomain( 'openpos', false,  trailingslashit(OPENPOS_DIR).'languages/' );
     51            load_textdomain( 'openpos', trailingslashit(WPOSL_DIR).'languages/openpos-' . $locale . '.mo' );
     52            load_plugin_textdomain( 'openpos', false,  trailingslashit(WPOSL_DIR).'languages/' );
    5353        //end
    5454    }
     
    104104    }
    105105    public function getPluginInfo(){
    106         $this->plugin_info = get_plugin_data(OPENPOS_DIR.'woocommerce-openpos.php');
     106        $this->plugin_info = get_plugin_data(WPOSL_DIR.'index.php');
    107107        return $this->plugin_info;
    108108    }
     
    18561856
    18571857
    1858         $file_path = rtrim(OPENPOS_DIR,'/').'/default/'.$file_name;
     1858        $file_path = rtrim(WPOSL_DIR,'/').'/default/'.$file_name;
    18591859
    18601860        $theme_file_path = rtrim(get_stylesheet_directory(),'/').'/woocommerce-openpos/'.$file_name;
     
    18661866            {
    18671867                $file_name = 'receipt_incl_tax_template_body.txt';
    1868                 $file_path = rtrim(OPENPOS_DIR,'/').'/default/'.$file_name;
     1868                $file_path = rtrim(WPOSL_DIR,'/').'/default/'.$file_name;
    18691869            }
    18701870        }
    18711871        $_gift_file_name = 'receipt_gift_template_body.txt';
    1872         $gift_file_path = rtrim(OPENPOS_DIR,'/').'/default/'.$_gift_file_name;
     1872        $gift_file_path = rtrim(WPOSL_DIR,'/').'/default/'.$_gift_file_name;
    18731873
    18741874        $gift_theme_file_path = rtrim(get_stylesheet_directory(),'/').'/woocommerce-openpos/'.$_gift_file_name;
     
    20392039    public function getReceiptFontCss(){
    20402040        $font_css = array();
    2041         $font_css['receipt_font'] = OPENPOS_URL.'/pos/font.css';
     2041        $font_css['receipt_font'] = WPOSL_URL.'/pos/font.css';
    20422042        return $font_css;
    20432043    }
     
    21612161    function get_pos_url($sub_str = ''){
    21622162     
    2163         $pos_url = apply_filters('op_pos_url',OPENPOS_URL.'/pos/');
    2164         if($sub_str)
    2165         {
    2166             $pos_url = trim(rtrim($pos_url,'/'));   
    2167            
    2168             $pos_url .= '/'.$sub_str;
    2169         }
     2163        $pos_url = apply_filters('op_pos_url','https://pos.wpos.app/#/');
     2164       
     2165       
    21702166        return  $pos_url;
    21712167    }
    21722168    function get_kitchen_url($wareshouse_id = 0,$base = false){
    21732169     
    2174         $pos_url = apply_filters('op_kitchen_url',OPENPOS_URL.'/kitchen/');
     2170        $pos_url = apply_filters('op_kitchen_url',WPOSL_URL.'/kitchen/');
    21752171       
    21762172        if(!$base)
     
    21902186    function get_bill_url($register_id = 0,$base = false){
    21912187     
    2192         $pos_url = apply_filters('op_bill_url',OPENPOS_URL.'/bill/');
     2188        $pos_url = apply_filters('op_bill_url',WPOSL_URL.'/bill/');
    21932189       
    21942190        if(!$base)
     
    22082204    }
    22092205    function get_customer_url($params = array()){
    2210         $customer_url = apply_filters('op_customer_url',OPENPOS_URL.'/customer/');
     2206        $customer_url = apply_filters('op_customer_url',WPOSL_URL.'/customer/');
    22112207        if(!empty($params))
    22122208        {
     
    22632259    }
    22642260    function getTemplatePath($file_name){
    2265         #$templath_path = OPENPOS_DIR.'templates/emails/';
    22662261        $templath_dir = 'woocommerce-openpos/';
    22672262        $check_dirs = array(
     
    22702265            trailingslashit( get_stylesheet_directory() ),
    22712266            trailingslashit( get_template_directory() ),
    2272             trailingslashit( OPENPOS_DIR ) . 'templates/',
     2267            trailingslashit( WPOSL_DIR ) . 'templates/',
    22732268        );
    22742269        foreach ( $check_dirs as $dir ) {
  • wpos-lite-version/trunk/includes/api/Auth.php

    r3376736 r3435849  
    505505                        $setting['pos_disable_item_discount'] = 'yes';
    506506                        $setting['pos_disable_cart_discount'] = 'yes';
     507                        $setting['pos_cart_tab'] = 'no'; // disable multi tab login for customer mode and waiter mode
    507508                        $setting['pos_cart_buttons'] = array(
    508509                            'cart-note',
     
    560561                    $setting['pos_weight_barcode_prefix'] = '20';
    561562                }
     563               
     564               
    562565
    563566                $session_data['setting'] = $setting;
  • wpos-lite-version/trunk/includes/api/Cart.php

    r3372360 r3435849  
    8181                if(!$register_id )
    8282                {
    83                     throw new Exception(__('Register not found','wpos-lite'));
     83                    throw new Exception(__('Register not found','openpos'));
    8484                }
    8585                $warehouse_meta_key = $this->warehouse_class->get_order_meta_key();
     
    135135                   
    136136                }else{
    137                     throw new Exception(__('No cart found','wpos-lite'));
     137                    throw new Exception(__('No cart found','openpos'));
    138138                }
    139139                $result['response']['data'] = $carts;
     
    163163                if(!$order_number)
    164164                {
    165                     throw new Exception( __('Cart Not found','wpos-lite') );
     165                    throw new Exception( __('Cart Not found','openpos') );
    166166                }else{
    167167                    if(!$this->core_class->enable_hpos())
     
    177177                    if(!$order)
    178178                    {
    179                         throw new Exception( __('Cart Not found','wpos-lite') );
     179                        throw new Exception( __('Cart Not found','openpos') );
    180180                    }
    181181                    $cart_data = get_post_meta($order->ID,'_op_cart_data');
     
    192192                    if(!$cart_data || !is_array($cart_data) || empty($cart_data))
    193193                    {
    194                         throw new Exception( __('Cart Not found','wpos-lite')   );
     194                        throw new Exception( __('Cart Not found','openpos')   );
    195195                    }else{
    196196                        $result['response']['data'] = $cart_data;
     
    264264                }else{
    265265
    266                     throw new  Exception(__('Cart Not Found', 'wpos-lite'));
     266                    throw new  Exception(__('Cart Not Found', 'openpos'));
    267267                }
    268268               
     
    295295                    if(!isset($register['id']))
    296296                    {
    297                         throw new Exception(__('Register not found','wpos-lite'));
     297                        throw new Exception(__('Register not found','openpos'));
    298298                    }
    299299                    $register_id = $register['id'];
     
    430430   
    431431                $result['response']['status'] = 1;
    432                 $result['response']['data'] = $this->cart_class->getShippingMethod($by_data,$cart);
     432                $result['response']['data'] = $this->cart_class->getShippingMethod($by_data,$cart,true);
    433433   
    434434                do_action('op_get_online_shipping_method',$result,$session_data);
     
    468468                {
    469469                    $result['response']['status'] = 1;
    470                     $cost = $this->cart_class->getShippingCost($by_data,$cart);
     470                    $cost = $this->cart_class->getShippingCost($by_data,$cart,true);
    471471                    if(!empty($cost))
    472472                    {
     
    555555                            if($a_coupon->get_individual_use())
    556556                            {
    557                                 throw new Exception(sprintf(__('Coupon %s is invidual use','wpos-lite'),$_a['code']));
     557                                throw new Exception(sprintf(__('Coupon %s is invidual use','openpos'),$_a['code']));
    558558                            }
    559559                        }
     
    629629                        if($amount < 0)
    630630                        {
    631                             $msg = __('Coupon code has been expired','wpos-lite');
     631                            $msg = __('Coupon code has been expired','openpos');
    632632                            throw new Exception($msg );
    633633                        }
     
    681681                        }
    682682                   
    683                         $result['response']['message'] = sprintf(__("<b>%s</b> discount value: <b>%s</b>", 'wpos-lite'), $code,$string_amnt);
     683                        $result['response']['message'] = sprintf(__("<b>%s</b> discount value: <b>%s</b>", 'openpos'), $code,$string_amnt);
    684684                        $result['response']['status'] = 1;
    685685
  • wpos-lite-version/trunk/index.php

    r3372171 r3435849  
    66Author: anhvnit@gmail.com
    77Author URI: http://openswatch.com/
    8 Version: 3.0
     8Version: 3.1
    99WC requires at least: 2.6
    1010WC tested up to: 4.8.0
  • wpos-lite-version/trunk/lib/class-op-woo-cart.php

    r3372171 r3435849  
    125125            return $cart_data;
    126126        }
    127         public function getShippingMethod($shipping_data,$cart_data){
     127        public function getShippingMethod($shipping_data,$cart_data,$is_api=false){
    128128            global $op_woo;
    129129            do_action('op_get_shipping_method_before',$shipping_data,$cart_data);
     
    140140                $country = $store_country;
    141141            }
     142            $methods_rates = array();
     143            if(!$is_api)
     144            {
     145                WC()->cart->empty_cart();
     146                WC()->session->cleanup_sessions();
     147                $cart = new WC_Cart();
     148
     149                $items = $cart_data['items'];
     150                foreach($items as $item)
     151                {
     152                    $product_id = isset($item['product_id']) ? $item['product_id'] : 0;
     153                    $product_qty = isset($item['qty']) ? $item['qty'] : 0;
     154
     155                    if($product_id && $product_qty)
     156                    {
     157                        $_product = wc_get_product($product_id);
     158                       
     159                        if($_product)
     160                        {
     161                            $parent_id = $product_id;
     162                            $variation_id = 0;
     163                            if($_product->get_type() == 'variation')
     164                            {
     165                                $parent_id = $_product->get_parent_id();
     166                                $variation_id = $product_id;
     167                            }
     168                            try{
     169
     170                                $cart->add_to_cart($parent_id,$product_qty,$variation_id);
     171       
     172                            }catch (Exception $e)
     173                            {
     174                                print_r($e);die;
     175                            }
     176                        }
     177                    }
     178                }
     179
     180
     181                $cart->calculate_totals();
     182
     183                $customer = $cart->get_customer();
     184                $customer->set_shipping_state($state);
     185                $customer->set_shipping_address($address);
     186                $customer->set_shipping_postcode($postcode);
     187                $customer->set_shipping_address_2($address_2);
     188                $customer->set_shipping_country($country);
     189                $customer->set_shipping_city($city);
     190
     191                $customer->set_billing_state($state);
     192                $customer->set_billing_address($address);
     193                $customer->set_billing_postcode($postcode);
     194                $customer->set_billing_address_2($address_2);
     195                $customer->set_billing_country($country);
     196                $customer->set_billing_city($city);
     197
     198                $customer->set_calculated_shipping(false);
     199                $cart->calculate_shipping();
     200                $packages = WC()->shipping()->get_packages();
     201               
     202
     203
     204                foreach($packages as $package)
     205                {
     206                    $package_rates = $package['rates'];
     207                    foreach($package_rates as $package_rate)
     208                    {
     209                        $id = $package_rate->get_id();
     210                        $cost = $package_rate->get_cost();
     211                        if(!$cost)
     212                        {
     213                            $cost = 0;
     214                        }
     215                        $tax = $package_rate->get_shipping_tax();
     216                        $label = $package_rate->get_label();
     217                        $tmp = array(
     218                            'code' => $id,
     219                            'label' => $label,
     220                            'title' => sprintf('%s (%s : %s)',$label,__('Cost','openpos'),strip_tags(wc_price($cost+ $tax))),
     221                            'cost' => $cost,
     222                            'tax' => $tax,
     223                        );
     224                        $methods_rates[$id] = $tmp;
     225                    }
     226                }
     227                do_action('op_get_shipping_method_after',$shipping_data,$cart_data);
     228                WC()->session->cleanup_sessions();
     229                WC()->cart->empty_cart();
     230            }else{
     231               
     232                if (isset($cart_data['items']) && !empty($cart_data['items'])) {
     233                    $package = array(
     234                        'contents'        => array(),
     235                        'contents_cost'   => 0,
     236                        'applied_coupons' => array(),
     237                        'destination'     => array(
     238                            'country'   => $country,
     239                            'state'     => $state,
     240                            'postcode'  => $postcode,
     241                            'city'      => $city,
     242                            'address'   => $address,
     243                            'address_2' => $address_2,
     244                        ),
     245                    );
     246                   
     247
     248                    foreach ($cart_data['items'] as $item) {
     249                        $product_id = isset($item['product_id']) ? $item['product_id'] : 0;
     250                        $qty = isset($item['qty']) ? $item['qty'] : 1;
     251                        if ($product_id && $qty) {
     252                            $product = wc_get_product($product_id);
     253                            if ($product) {
     254                                $package['contents'][$product_id] = array(
     255                                    'product_id'   => $product_id,
     256                                    'data'         => $product,
     257                                    'quantity'     => $qty,
     258                                    'line_total'   => $item['final_price'] * $qty,
     259                                    'line_tax'     => $item['total_tax'] ,
     260                                );
     261                                $package['contents_cost'] += $item['total'];
     262                            }else{
     263                                $package['contents'][$product_id] = array(
     264                                    'product_id'   => $product_id,
     265                                    'data'         => array(),
     266                                    'quantity'     => $qty,
     267                                    'line_total'   => $item['final_price'] * $qty,
     268                                    'line_tax'     => $item['total_tax'] ,
     269                                );
     270                                $package['contents_cost'] += $item['total'];
     271                            }
     272                        }
     273                    }
     274
     275                    $methods_rates = $this->get_available_shipping_methods($package['destination'], $package['contents']);
     276                   
     277                   
     278                }
     279            }
     280           
     281            return apply_filters('op_shipping_method_data',array_values($methods_rates));
     282        }
     283        function get_available_shipping_methods( $address, $cart_items ) {
     284           
    142285            WC()->cart->empty_cart();
    143             WC()->session->cleanup_sessions();
    144             $cart = new WC_Cart();
    145 
    146             $items = $cart_data['items'];
    147             foreach($items as $item)
    148             {
    149                 $product_id = isset($item['product_id']) ? $item['product_id'] : 0;
    150                 $product_qty = isset($item['qty']) ? $item['qty'] : 0;
    151 
    152                 if($product_id && $product_qty)
    153                 {
    154                     $_product = wc_get_product($product_id);
     286       
     287           
     288            foreach ( $cart_items as $item ) {
     289                WC()->cart->add_to_cart( $item['product_id'], $item['quantity'] );
     290            }
     291            $packages = [
     292                [
     293                    'contents'        => WC()->cart->get_cart(),
     294                    'contents_cost'   => WC()->cart->get_cart_contents_total(),
     295                    'applied_coupons' => WC()->cart->get_applied_coupons(),
     296                    'user'            => [
     297                        'ID' => get_current_user_id(),
     298                    ],
     299                    'destination'     => [
     300                        'country'   => $address['country'],
     301                        'state'     => $address['state'],
     302                        'postcode'  => $address['postcode'],
     303                        'city'      => $address['city'],
     304                        'address'   => $address['address_1'],
     305                        'address_2' => $address['address_2'] ?? '',
     306                    ],
     307                ]
     308            ];
     309            $shipping = new WC_Shipping();
     310            $shipping->calculate_shipping( $packages );
     311       
     312            $available_methods = [];
     313       
     314            foreach ( $shipping->get_packages() as $package ) {
     315                foreach ( $package['rates'] as $rate_id => $rate ) {
     316
    155317                   
    156                     if($_product)
    157                     {
    158                         $parent_id = $product_id;
    159                         $variation_id = 0;
    160                         if($_product->get_type() == 'variation')
    161                         {
    162                             $parent_id = $_product->get_parent_id();
    163                             $variation_id = $product_id;
    164                         }
    165                         try{
    166 
    167                             $cart->add_to_cart($parent_id,$product_qty,$variation_id);
    168    
    169                         }catch (Exception $e)
    170                         {
    171                             print_r($e);die;
    172                         }
    173                     }
    174                 }
    175             }
    176 
    177 
    178             $cart->calculate_totals();
    179 
    180             $customer = $cart->get_customer();
    181             $customer->set_shipping_state($state);
    182             $customer->set_shipping_address($address);
    183             $customer->set_shipping_postcode($postcode);
    184             $customer->set_shipping_address_2($address_2);
    185             $customer->set_shipping_country($country);
    186             $customer->set_shipping_city($city);
    187 
    188             $customer->set_billing_state($state);
    189             $customer->set_billing_address($address);
    190             $customer->set_billing_postcode($postcode);
    191             $customer->set_billing_address_2($address_2);
    192             $customer->set_billing_country($country);
    193             $customer->set_billing_city($city);
    194 
    195             $customer->set_calculated_shipping(false);
    196             $cart->calculate_shipping();
    197             $packages = WC()->shipping()->get_packages();
    198             $methods_rates = array();
    199 
    200 
    201             foreach($packages as $package)
    202             {
    203                 $package_rates = $package['rates'];
    204                 foreach($package_rates as $package_rate)
    205                 {
    206                     $id = $package_rate->get_id();
    207                     $cost = $package_rate->get_cost();
    208                     if(!$cost)
    209                     {
    210                         $cost = 0;
    211                     }
    212                     $tax = $package_rate->get_shipping_tax();
    213                     $label = $package_rate->get_label();
    214                     $tmp = array(
    215                         'code' => $id,
    216                         'label' => $label,
    217                         'title' => sprintf('%s (%s : %s)',$label,__('Cost','wpos-lite'),strip_tags(wc_price($cost+ $tax))),
    218                         'cost' => $cost,
     318                    $tax = method_exists($rate, 'get_shipping_tax') ? $rate->get_shipping_tax() : 0;
     319                    $label = $rate->get_label();
     320                    $cost = (float) $rate->get_cost();
     321                    $available_methods[$rate_id] = [
     322                        'code'    => $rate_id,
     323                        'id'    => $rate_id,
     324                        'label' => $rate->get_label(),
     325                        'cost'  => (float) $rate->get_cost(),
    219326                        'tax' => $tax,
    220                     );
    221                     $methods_rates[$id] = $tmp;
    222                 }
    223             }
    224             do_action('op_get_shipping_method_after',$shipping_data,$cart_data);
    225             WC()->session->cleanup_sessions();
    226             WC()->cart->empty_cart();
    227             return apply_filters('op_shipping_method_data',array_values($methods_rates));
    228         }
    229         public function getShippingCost($shipping_data,$cart_data){
     327                        'title' => sprintf('%s (%s : %s)',$label,__('Cost','openpos'),strip_tags(wc_price($cost+ $tax))),
     328                    ];
     329                }
     330            }
     331       
     332            return $available_methods;
     333        }
     334       
     335        public function getShippingCost($shipping_data,$cart_data,$is_rest = false){
    230336            global $op_woo;
    231337            $address = isset($shipping_data['']) ? $shipping_data['address'] : '';
     
    241347                $country = $store_country;
    242348            }
    243             $session = WC()->session;
    244             $cart = new WC_Cart();
    245 
    246             $items = $cart_data['items'];
    247             foreach($items as $item)
    248             {
    249                 $product_id = isset($item['product_id']) ? $item['product_id'] : 0;
    250                 $product_qty = isset($item['qty']) ? $item['qty'] : 0;
    251                 if($product_id && $product_qty)
    252                 {
    253                     $cart->add_to_cart($product_id,$product_qty);
    254                 }
    255             }
    256             $cart->calculate_totals();
    257             $shipping_method = $shipping_data['shipping_method'];
    258             $customer = $cart->get_customer();
    259             $customer->set_shipping_state($state);
    260             $customer->set_shipping_address($address);
    261             $customer->set_shipping_postcode($postcode);
    262             $customer->set_shipping_address_2($address_2);
    263             $customer->set_shipping_country($country);
    264             $customer->set_shipping_city($city);
    265             $customer->set_calculated_shipping(false);
    266             $cart->calculate_shipping();
    267             $packages = WC()->shipping()->get_packages();
    268349            $shipping_cost = array();
    269350            $shipping_tax = array();
    270351            $shipping_methods = array();
    271             foreach($packages as $package)
    272             {
    273                 $package_rates = $package['rates'];
    274                 foreach($package_rates as $package_rate)
    275                 {
    276 
    277                     $method_id = $package_rate->method_id;
    278                     if($method_id == $shipping_method)
    279                     {
    280                         $shipping_methods[] = $package_rate;
    281                     }
    282                 }
    283             }
     352            if(!$is_rest)
     353            {
     354                $session = WC()->session;
     355                $cart = new WC_Cart();
     356   
     357                $items = $cart_data['items'];
     358                foreach($items as $item)
     359                {
     360                    $product_id = isset($item['product_id']) ? $item['product_id'] : 0;
     361                    $product_qty = isset($item['qty']) ? $item['qty'] : 0;
     362                    if($product_id && $product_qty)
     363                    {
     364                        $cart->add_to_cart($product_id,$product_qty);
     365                    }
     366                }
     367                $cart->calculate_totals();
     368                $shipping_method = $shipping_data['shipping_method'];
     369                $customer = $cart->get_customer();
     370                $customer->set_shipping_state($state);
     371                $customer->set_shipping_address($address);
     372                $customer->set_shipping_postcode($postcode);
     373                $customer->set_shipping_address_2($address_2);
     374                $customer->set_shipping_country($country);
     375                $customer->set_shipping_city($city);
     376                $customer->set_calculated_shipping(false);
     377                $cart->calculate_shipping();
     378                $packages = WC()->shipping()->get_packages();
     379               
     380                foreach($packages as $package)
     381                {
     382                    $package_rates = $package['rates'];
     383                    foreach($package_rates as $package_rate)
     384                    {
     385   
     386                        $method_id = $package_rate->method_id;
     387                        if($method_id == $shipping_method)
     388                        {
     389                            $shipping_methods[] = $package_rate;
     390                        }
     391                    }
     392                }
     393            }else{
     394                //rest api calc shipping method
     395            }
     396           
    284397            foreach($shipping_methods as $shipping_method)
    285398            {
     
    312425            return array();
    313426        }
    314         public function getCartDiscount($cart_data){
     427        public function getCartDiscount($cart_data,$is_api = false){
    315428            $result = array();
    316             $session = WC()->session;
    317             $cart = new WC_Cart();
     429           
    318430            $customer_data = $cart_data['customer'];
    319 
    320             if(!empty($customer_data)) {
    321 
    322                 if ($customer_data['id'] && $customer_data['id'] > 0) {
    323                     wp_set_current_user($customer_data['id']);
    324                 }
    325 
    326             }
    327             $items = $cart_data['items'];
    328             foreach($items as $item)
    329             {
    330                 $product_id = isset($item['product_id']) ? $item['product_id'] : 0;
    331                 $product_qty = isset($item['qty']) ? $item['qty'] : 0;
    332                 if($product_id && $product_qty)
    333                 {
    334                     $cart->add_to_cart($product_id,$product_qty);
    335                 }
    336             }
    337 
    338             $post_customer_data = array();
    339             if(!empty($customer_data))
    340             {
    341                 $customer = $cart->get_customer();
    342 
    343 
    344                 if(isset($customer_data['email']) && $customer_data['email'])
    345                 {
    346                     $customer->set_email($customer_data['email']);
    347                     $post_customer_data['billing_email'] = $customer_data['email'];
    348                 }
    349                 if(isset($customer_data['firstname']) && $customer_data['firstname'])
    350                 {
    351                     $customer->set_first_name($customer_data['firstname']);
    352                     $post_customer_data['billing_first_name'] = $customer_data['firstname'];
    353                 }
    354                 if(isset($customer_data['lastname']) && $customer_data['lastname'])
    355                 {
    356                     $customer->set_last_name($customer_data['lastname']);
    357                     $post_customer_data['billing_last_name'] = $customer_data['lastname'];
    358                 }
    359                 if($customer_data['address'])
    360                 {
    361                     $customer->set_address($customer_data['address']);
    362                     $post_customer_data['billing_address_1'] = $customer_data['address'];
    363                 }
    364 
    365                 if(isset($customer_data['address_2']) && $customer_data['address_2'])
    366                 {
    367                     $customer->set_address_2($customer_data['address_2']);
    368                     $post_customer_data['billing_address_2'] = $customer_data['address_2'];
    369                 }
    370 
    371                 if(isset($customer_data['state']) && $customer_data['state'])
    372                 {
    373                     $customer->set_state($customer_data['state']);
    374                     $post_customer_data['billing_state'] = $customer_data['state'];
    375                 }
    376 
    377                 if(isset($customer_data['city']) && $customer_data['city'])
    378                 {
    379                     $customer->set_city($customer_data['city']);
    380                     $post_customer_data['billing_city'] = $customer_data['city'];
    381                 }
    382 
    383                 if(isset($customer_data['country']) && $customer_data['country'])
    384                 {
    385                     $customer->set_country($customer_data['country']);
    386                     $post_customer_data['billing_country'] = $customer_data['country'];
    387                 }
    388 
    389                 if(isset($customer_data['postcode']) && $customer_data['postcode'])
    390                 {
    391                     $customer->set_postcode($customer_data['postcode']);
    392                     $post_customer_data['billing_postcode'] = $customer_data['postcode'];
    393                 }
    394                 WC()->customer = $customer;
    395 
    396             }
    397             WC()->session->set('refresh_totals', true);
    398             $cart->calculate_totals();
    399             WC()->cart = $cart;
    400 
    401             $post_data = implode('&',$post_customer_data);
    402             $_POST['billing_email'] = $customer_data['email'];
    403             $_POST['post_data'] = $post_data;
    404             $_GET['wc-ajax'] = 'update_order_review';
    405 
    406            
    407             $cart->calculate_totals();
    408            
    409             $discount_amount = 0;
    410             $coupons  = WC()->cart->get_coupons();
    411             $discount_type = 'fixed';
    412             foreach($coupons as $coupon)
    413             {
    414                 $discount_amount += $coupon->get_amount();
    415                 $tmp_discount_type = $coupon->get_discount_type();
    416                 if($tmp_discount_type == 'percent')
    417                 {
    418                     $discount_type = 'percent';
    419                 }
    420             }
    421             if($discount_amount)
    422             {
    423                 $result = array(
    424                     'discount_amount' => $discount_amount,
    425                     'discount_type' => $discount_type // percent , fixed
    426                    
    427                 );
    428             }
    429 
    430             wp_set_current_user(0);
     431            if(!$is_api)
     432            {
     433                $cart = new WC_Cart();
     434                if(!empty($customer_data)) {
     435
     436                    if ($customer_data['id'] && $customer_data['id'] > 0) {
     437                        wp_set_current_user($customer_data['id']);
     438                    }
     439   
     440                }
     441                $items = $cart_data['items'];
     442                foreach($items as $item)
     443                {
     444                    $product_id = isset($item['product_id']) ? $item['product_id'] : 0;
     445                    $product_qty = isset($item['qty']) ? $item['qty'] : 0;
     446                    if($product_id && $product_qty)
     447                    {
     448                        $cart->add_to_cart($product_id,$product_qty);
     449                    }
     450                }
     451   
     452                $post_customer_data = array();
     453                if(!empty($customer_data))
     454                {
     455                    $customer = $cart->get_customer();
     456   
     457   
     458                    if(isset($customer_data['email']) && $customer_data['email'])
     459                    {
     460                        $customer->set_email($customer_data['email']);
     461                        $post_customer_data['billing_email'] = $customer_data['email'];
     462                    }
     463                    if(isset($customer_data['firstname']) && $customer_data['firstname'])
     464                    {
     465                        $customer->set_first_name($customer_data['firstname']);
     466                        $post_customer_data['billing_first_name'] = $customer_data['firstname'];
     467                    }
     468                    if(isset($customer_data['lastname']) && $customer_data['lastname'])
     469                    {
     470                        $customer->set_last_name($customer_data['lastname']);
     471                        $post_customer_data['billing_last_name'] = $customer_data['lastname'];
     472                    }
     473                    if($customer_data['address'])
     474                    {
     475                        $customer->set_address($customer_data['address']);
     476                        $post_customer_data['billing_address_1'] = $customer_data['address'];
     477                    }
     478   
     479                    if(isset($customer_data['address_2']) && $customer_data['address_2'])
     480                    {
     481                        $customer->set_address_2($customer_data['address_2']);
     482                        $post_customer_data['billing_address_2'] = $customer_data['address_2'];
     483                    }
     484   
     485                    if(isset($customer_data['state']) && $customer_data['state'])
     486                    {
     487                        $customer->set_state($customer_data['state']);
     488                        $post_customer_data['billing_state'] = $customer_data['state'];
     489                    }
     490   
     491                    if(isset($customer_data['city']) && $customer_data['city'])
     492                    {
     493                        $customer->set_city($customer_data['city']);
     494                        $post_customer_data['billing_city'] = $customer_data['city'];
     495                    }
     496   
     497                    if(isset($customer_data['country']) && $customer_data['country'])
     498                    {
     499                        $customer->set_country($customer_data['country']);
     500                        $post_customer_data['billing_country'] = $customer_data['country'];
     501                    }
     502   
     503                    if(isset($customer_data['postcode']) && $customer_data['postcode'])
     504                    {
     505                        $customer->set_postcode($customer_data['postcode']);
     506                        $post_customer_data['billing_postcode'] = $customer_data['postcode'];
     507                    }
     508                    WC()->customer = $customer;
     509   
     510                }
     511                WC()->session->set('refresh_totals', true);
     512                $cart->calculate_totals();
     513                WC()->cart = $cart;
     514   
     515                $post_data = implode('&',$post_customer_data);
     516                $_POST['billing_email'] = $customer_data['email'];
     517                $_POST['post_data'] = $post_data;
     518                $_GET['wc-ajax'] = 'update_order_review';
     519   
     520               
     521                $cart->calculate_totals();
     522               
     523                $discount_amount = 0;
     524                $coupons  = WC()->cart->get_coupons();
     525                $discount_type = 'fixed';
     526                foreach($coupons as $coupon)
     527                {
     528                    $discount_amount += $coupon->get_amount();
     529                    $tmp_discount_type = $coupon->get_discount_type();
     530                    if($tmp_discount_type == 'percent')
     531                    {
     532                        $discount_type = 'percent';
     533                    }
     534                }
     535                if($discount_amount)
     536                {
     537                    $result = array(
     538                        'discount_amount' => $discount_amount,
     539                        'discount_type' => $discount_type // percent , fixed
     540                       
     541                    );
     542                }
     543   
     544                wp_set_current_user(0);
     545            }else{
     546                // api calc discount
     547            }
     548           
    431549            return $result;
    432550        }
  • wpos-lite-version/trunk/readme.txt

    r3373861 r3435849  
    3939
    4040🎥 Watch the demo video:
    41 https://www.youtube.com/watch?v=dQw4w9WgXcQ
     41https://youtu.be/zqCd4Ox3NIk?si=CUv6q0m76N4inOMM
    4242
    4343---
Note: See TracChangeset for help on using the changeset viewer.