Tengo una aplicación de comercio electrónico que funcionaba bien hace algunos días. Después de actualizar el complemento de wordpress y woocommerce, la aplicación dejó de funcionar repentinamente.
Creo que eso es algo sobre el complemento que uso (mstore app-mobile), pero desafortunadamente no es posible actualizar este complemento.
El error ocurre en esta función updateCartQty. Supongo que algo sobre el parámetro de función.
public function updateCartQty()
{
$cart_item_key = $_REQUEST['key'];
$qty = (int)$_REQUEST['quantity'];
global $woocommerce;
$woocommerce->cart->set_quantity($cart_item_key, $qty);
$this->cart();
}
Este es el archivo de registro:
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
Información del sistema:
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) ###
¿Qué puedo hacer para solucionar este error? Agradezco cualquier ayuda. Gracias por tu tiempo.
EDITAR 1: he cambiado el $_SOLICITUD a $_POST y configure la depuración en $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()
Función
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();
}
PRODUCCIÓN:
<script>console.debug( "PHP DEBUG: 120705de7e61c5b322ad798b8ef225a7" );</script>
EDITAR 2:
Archivo: wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276): WC_Cart->set_quantity()
Establecí la posición de la matriz pero el error aún persiste:
$cart_item_key = $_POST['key'][0];
$qty = (int)$_POST['quantity'][0];
PRODUCCIÓN
EDITAR 3:
Archivo: wp-content/plugins/mstoreapp-mobile-app-multivendor/public/class-mstoreapp-mobile-app-public.php(1276): WC_Cart->set_quantity()
Usando 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();
}
La salida:
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"
}
EDITAR 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;
}
}
EDITAR 5:
como lo sugiere @Vincenzo Di Gaetano, verificar cart_item_key antes del incremento ha resuelto el problema.
$woocommerce global; if ( $woocommerce->carrito->get_cart_item( $cart_item_key ) ) { $woocommerce->cart->set_quantity( $cart_item_key, $qty ); }
.