【发布时间】:2021-05-25 06:09:29
【问题描述】:
我有一个电子商务应用,几天前运行良好。在我更新了 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: 我已将 $_REQUEST 更改为 $_POST 并在 $cart_item_key = $_REQUEST['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();
}
输出:
<script>console.debug( "PHP DEBUG: 120705de7e61c5b322ad798b8ef225a7" );</script>
编辑 2:
文件: wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276):WC_Cart->set_quantity()
我已经设置了数组位置,但错误仍然存在:
$cart_item_key = $_POST['key'][0];
$qty = (int)$_POST['quantity'][0];
输出
编辑 3:
文件: wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276):WC_Cart->set_quantity()
使用 var_dump($_POST):
public function updateCartQty() {
$cart_item_key = $_POST['key'][0];
$qty = (int)$_POST['quantity'][0];
var_dump($_POST);
global $woocommerce;
$woocommerce->cart->set_quantity($cart_item_key, $qty);
$this->cart();
}
输出:
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"
}
编辑 4:
**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 所建议的,在增量解决问题之前检查cart_item_key。
全球 $woocommerce; if ( $woocommerce->cart->get_cart_item( $cart_item_key ) ) { $woocommerce->cart->set_quantity($cart_item_key, $qty); }
【问题讨论】:
-
$_REQUEST['key']很可能不包含购物车商品 ID。尝试执行var_dump($_REQUEST['key'])或 var_dump($_REQUEST) 并检查值。 -
如果可能,考虑使用
$_GET和$_POST变量来获取值。 -
@VincenzoDiGaetano 感谢您的评论。我已将 $_REQUEST 更改为 $_POST。钥匙看起来不错,但我认为缺少一些信息。我还用更多信息更新了问题
-
第 225 行是什么? /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php:225
-
尝试将
$qty = (int)$_POST['quantity'];改为$qty = $_POST['quantity'];作为字符串
标签: php wordpress ionic-framework woocommerce