Php “如何修复”;未捕获错误:调用成员函数get“tax”class()on null;在商业中?

Php “如何修复”;未捕获错误:调用成员函数get“tax”class()on null;在商业中?,php,wordpress,ionic-framework,woocommerce,Php,Wordpress,Ionic Framework,Woocommerce,我有一个电子商务应用程序,几天前运行良好。在我更新wordpress和woocommerce插件后,应用程序突然停止工作 我想这就是我使用的插件(mstore app mobile)的原因,但不幸的是,无法更新此插件 此updateCartQty函数发生错误。我的猜测是关于函数参数 public function updateCartQty() { $cart_item_key = $_REQUEST['key']; $qty = (int)$_REQUEST['qu

我有一个电子商务应用程序,几天前运行良好。在我更新wordpress和woocommerce插件后,应用程序突然停止工作

我想这就是我使用的插件(mstore app mobile)的原因,但不幸的是,无法更新此插件

此updateCartQty函数发生错误。我的猜测是关于函数参数

public function updateCartQty()
{        
   $cart_item_key = $_REQUEST['key'];
   $qty = (int)$_REQUEST['quantity'];

   global $woocommerce;
   $woocommerce->cart->set_quantity($cart_item_key, $qty);   
   $this->cart();    
}
这是日志文件:

2021-02-22T23:43:48+00:00 CRITICAL Uncaught Error: Call to a member function get_tax_class() on null in /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php:225
Stack trace:
#0 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(651): WC_Cart_Totals->get_items_from_cart()
#1 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(143): WC_Cart_Totals->calculate_item_totals()
#2 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php(134): WC_Cart_Totals->calculate()
#3 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1369): WC_Cart_Totals->__construct()
#4 /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1328): WC_Cart->calculate_totals()
#5 /var/www/html/ecommerce/htdocs/wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1277): WC_Cart->set_quantity()
#6 , em /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php, na linha 225
系统信息:

WC Version: 5.0.0
REST API Version: ✔ 5.0.0
WC Blocks Version: ✔ 4.0.0
Action Scheduler Version: ✔ 3.1.6
WC Admin Version: ✔ 1.9.0
Log Directory Writable: ✔
WP Version: 5.6.2
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: ✔
Language: pt_BR
External object cache: –

### Server Environment ###

Server Info: Apache/2.4.18 (Ubuntu)
PHP Version: 7.4.15
PHP Post Max Size: 8 MB
PHP Time Limit: 30
PHP Max Input Vars: 1000
cURL Version: 7.47.0
OpenSSL/1.0.2g

SUHOSIN Installed: –
MySQL Version: 8.0.20
Max Upload Size: 2 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

### Database ###

WC Database Version: 5.0.0

### Active Plugins (13) ###

Redux: por Redux.io + Dovy Paukstys – 4.1.24
Akismet Anti-Spam: por Automattic – 4.1.8
All in One SEO: por Equipe All in One SEO – 4.0.15
Google Analytics for WordPress by MonsterInsights: por MonsterInsights – 7.16.2
Jetpack por WordPress.com: por Automattic – 9.4
Monetization Code plugin: por aerin Singh – 1.0
Mstoreapp Mobile Multivendor: por Mstoreapp – 9.0.1
Simple Tags: por WebFactory Ltd – 2.63
WCFM - WooCommerce Frontend Manager: por WC Lovers – 6.5.6
WCFM - WooCommerce Multivendor Marketplace: por WC Lovers – 3.4.6
WCFM - WooCommerce Multivendor Membership: por WC Lovers – 2.9.5
WooCommerce: por Automattic – 5.0.0
WP Mail SMTP: por WPForms – 2.6.0

### Inactive Plugins (0) ###
如何解决此错误?谢谢你的帮助。谢谢你抽出时间

编辑1:我已将$\u请求更改为$\u POST,并在$cart\u item\u key=$\u请求['key']上设置调试

**File:** wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276): WC_Cart->set_quantity()
功能

public function updateCartQty() {

        $cart_item_key = $_POST['key'];
        $qty = (int)$_POST['quantity'];

        echo "<script>console.debug( \"PHP DEBUG: $cart_item_key\" );</script>";
    
        global $woocommerce;
        $woocommerce->cart->set_quantity($cart_item_key, $qty);
        $this->cart();    
    }

输出

编辑3:

<script>console.debug( "PHP DEBUG: 120705de7e61c5b322ad798b8ef225a7" );</script>
array(6) {
  ["key"]=>
  string(32) "431cfe4bd4a84b68398e14af4be0bdc3"
  ["quantity"]=>
  string(1) "3"
  ["update_cart"]=>
  string(11) "Update Cart"
  ["_wpnonce"]=>
  string(10) "52e75170fc"
  ["lang"]=>
  string(2) "en"
  ["mstoreapp"]=>
  string(1) "1"
}
**File:** wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php

protected function get_items_from_cart() {
                $this->items = array();

                foreach ( $this->cart->get_cart() as $cart_item_key => $cart_item ) {
                        $item                          = $this->get_default_item_props();
                        $item->key                     = $cart_item_key;
                        $item->object                  = $cart_item;
                        $item->tax_class               = $cart_item['data']->get_tax_class();
                        $item->taxable                 = 'taxable' === $cart_item['data']->get_tax_status(); // LINE 225
                        $item->price_includes_tax      = wc_prices_include_tax();
                        $item->quantity                = $cart_item['quantity'];
                        $item->price                   = wc_add_number_precision_deep( $cart_item['data']->get_price() * $cart_item['quantity'] );
                        $item->product                 = $cart_item['data'];
                        $item->tax_rates               = $this->get_item_tax_rates( $item );
                        $this->items[ $cart_item_key ] = $item;
                }
        }
文件:wp content/plugins/mstoreapp mobile app multivendor/public/class mstoreapp mobile app public.php(1276):WC\u Cart->set\u quantity()

使用var\u dump($\u POST):

输出:

<script>console.debug( "PHP DEBUG: 120705de7e61c5b322ad798b8ef225a7" );</script>
array(6) {
  ["key"]=>
  string(32) "431cfe4bd4a84b68398e14af4be0bdc3"
  ["quantity"]=>
  string(1) "3"
  ["update_cart"]=>
  string(11) "Update Cart"
  ["_wpnonce"]=>
  string(10) "52e75170fc"
  ["lang"]=>
  string(2) "en"
  ["mstoreapp"]=>
  string(1) "1"
}
**File:** wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php

protected function get_items_from_cart() {
                $this->items = array();

                foreach ( $this->cart->get_cart() as $cart_item_key => $cart_item ) {
                        $item                          = $this->get_default_item_props();
                        $item->key                     = $cart_item_key;
                        $item->object                  = $cart_item;
                        $item->tax_class               = $cart_item['data']->get_tax_class();
                        $item->taxable                 = 'taxable' === $cart_item['data']->get_tax_status(); // LINE 225
                        $item->price_includes_tax      = wc_prices_include_tax();
                        $item->quantity                = $cart_item['quantity'];
                        $item->price                   = wc_add_number_precision_deep( $cart_item['data']->get_price() * $cart_item['quantity'] );
                        $item->product                 = $cart_item['data'];
                        $item->tax_rates               = $this->get_item_tax_rates( $item );
                        $this->items[ $cart_item_key ] = $item;
                }
        }
编辑4:

<script>console.debug( "PHP DEBUG: 120705de7e61c5b322ad798b8ef225a7" );</script>
array(6) {
  ["key"]=>
  string(32) "431cfe4bd4a84b68398e14af4be0bdc3"
  ["quantity"]=>
  string(1) "3"
  ["update_cart"]=>
  string(11) "Update Cart"
  ["_wpnonce"]=>
  string(10) "52e75170fc"
  ["lang"]=>
  string(2) "en"
  ["mstoreapp"]=>
  string(1) "1"
}
**File:** wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php

protected function get_items_from_cart() {
                $this->items = array();

                foreach ( $this->cart->get_cart() as $cart_item_key => $cart_item ) {
                        $item                          = $this->get_default_item_props();
                        $item->key                     = $cart_item_key;
                        $item->object                  = $cart_item;
                        $item->tax_class               = $cart_item['data']->get_tax_class();
                        $item->taxable                 = 'taxable' === $cart_item['data']->get_tax_status(); // LINE 225
                        $item->price_includes_tax      = wc_prices_include_tax();
                        $item->quantity                = $cart_item['quantity'];
                        $item->price                   = wc_add_number_precision_deep( $cart_item['data']->get_price() * $cart_item['quantity'] );
                        $item->product                 = $cart_item['data'];
                        $item->tax_rates               = $this->get_item_tax_rates( $item );
                        $this->items[ $cart_item_key ] = $item;
                }
        }
编辑5: 正如@Vincenzo Di Gaetano所建议的,在增量之前检查购物车项目密钥已经解决了问题

全球商业;如果($woocommerce->cart->get\u cart\u项目( $cart_项目_键){ $WOOMerce->cart->set_数量($cart_item_key,$qty);}


$\u POST
变量(编辑3)
var\u dump
中可以清楚地看出,您必须通过以下方式获取购物车项目密钥和数量:

$cart_item_key = $_POST['key'];
$qty = (int)$_POST['quantity'];
Uncaught错误:调用成员函数get\u tax\u class()on null
错误可能是因为购物车项目键没有 存在

因此,您可以添加如下检查:

global $woocommerce;
if ( $woocommerce->cart->get_cart_item( $cart_item_key ) ) {
    $woocommerce->cart->set_quantity( $cart_item_key, $qty );
}
这肯定会修复错误。

但是,如果您的函数应该始终获取正确的购物车项目密钥,则需要仔细检查如何获取(或如何传递)购物车项目密钥

你的评论的答案是:

购物车项目键由类的方法生成


< P>此方法在同一类的方法中被调用。

最可能的是<代码> $i请求(‘KEY’)/代码>不包含CART项ID。尝试执行<代码> VARYDUMP($IO请求[键] ])/ValueDUP($AI请求)并检查值。考虑使用<代码> $yGET和<代码> $POST < /Cord>变量来获取值,如果可能的话。@VincenzoDiGaetano谢谢你的评论。我已将$\u请求更改为$\u发布。钥匙看起来很好,但我认为缺少一些信息。我还更新了问题的更多信息。第225行有什么内容/var/www/html/ecommerce/htdocs/wp-content/plugins/woocmerce/includes/class-wc-cart-totals.php:225尝试更改
$qty=(int)$\u POST['quantity']
$quantity=$\u POST['quantity']对于您的响应非常严格,但不起作用。同样的错误,好的。能否转储$\u POST变量并显示结果?因此,就在
updateCartQty()
方法声明之后添加
var\u dump($\u POST)。我已经用var\u转储信息更新了问题。也许是客户方面的问题?我已经更新了我的答案。当然是为了这么少。我添加了对文档的引用。