Ich habe eine E-Commerce-App, die vor einigen Tagen gut funktioniert hat. Nachdem ich das WordPress- und Woocommerce-Plugin aktualisiert habe, funktionierte die App plötzlich nicht mehr.
Ich denke, das liegt an dem Plugin, das ich verwende (mstore app-mobile), aber leider ist es nicht möglich, dieses Plugin zu aktualisieren.
Der Fehler tritt bei dieser updateCartQty-Funktion auf. Meine Vermutung ist, dass etwas über den Funktionsparameter.
public function updateCartQty()
{
$cart_item_key = $_REQUEST['key'];
$qty = (int)$_REQUEST['quantity'];
global $woocommerce;
$woocommerce->cart->set_quantity($cart_item_key, $qty);
$this->cart();
}
Dies ist die Protokolldatei:
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
Systeminformationen:
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) ###
Was kann ich tun, um diesen Fehler zu beheben? Ich freue mich über jede Hilfe. Vielen Dank für Ihre Zeit.
BEARBEITEN 1: Ich habe die geändert $_REQUEST zu $_POST und setze den Debug auf $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()
Funktion
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();
}
AUSGANG:
<script>console.debug( "PHP DEBUG: 120705de7e61c5b322ad798b8ef225a7" );</script>
BEARBEITEN 2:
Datei: wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276): WC_Cart->set_quantity()
Ich habe die Array-Position eingestellt, aber der Fehler bleibt bestehen:
$cart_item_key = $_POST['key'][0];
$qty = (int)$_POST['quantity'][0];
AUSGANG
BEARBEITEN 3:
Datei: wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276): WC_Cart->set_quantity()
Verwendung von 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();
}
Die Ausgabe:
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"
}
BEARBEITEN 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;
}
}
BEARBEITEN 5:
Wie von @Vincenzo Di Gaetano vorgeschlagen, hat das Überprüfen des cart_item_key vor dem Inkrement das Problem gelöst.
globaler $woocommerce; if ( $woocommerce->cart->get_cart_item( $cart_item_key ) ) { $woocommerce->cart->set_quantity( $cart_item_key, $qty ); }
Höchstwahrscheinlich
$_REQUEST['key']
enthält nicht die Artikel-ID des Einkaufswagens. Versuchen Sie, avar_dump($_REQUEST['key'])
oder var_dump($_REQUEST) und überprüfen Sie den Wert.– Vincenzo di Gaetano
23. Februar 2021 um 20:47 Uhr
Erwägen Sie die Verwendung von
$_GET
und$_POST
Variablen, um die Werte zu erhalten, falls möglich.– Vincenzo di Gaetano
23. Februar 2021 um 20:49 Uhr
@VincenzoDiGaetano Vielen Dank für Ihren Kommentar. Ich habe die Änderung von $_REQUEST zu $_POST vorgenommen. Der Schlüssel sieht gut aus, aber ich denke, dass einige Informationen fehlen. Ich habe die Frage auch mit weiteren Informationen aktualisiert
– Diego Desenvolvedor
24. Februar 2021 um 0:20 Uhr
Was ist auf Zeile 225? /var/www/html/ecommerce/htdocs/wp-content/plugins/woocommerce/includes/class-wc-cart-totals.php:225
– Juan
26. Februar 2021 um 11:46 Uhr
Versuchen Sie, sich zu ändern
$qty = (int)$_POST['quantity'];
zu$qty = $_POST['quantity'];
als Schnur– Juan
26. Februar 2021 um 11:50 Uhr