• Hello,
    First thanks for this really great product.
    Since I make the last update, I alway have a Fatal Error in my log,
    PHP Fatal error: Uncaught Error: Call to undefined method WP_Error::get_data() in /home/admin/web/myWebsite.com/public_html/wp-content/plugins/woocommerce-pos/includes/apiv2/class-wc-pos-products.php:154

    I tried to see what happen and it happens when POS tried to get variable product.
    Here is a part of your code :

    public function product_response( $response, $product, $request ) {
    		$data = $response->get_data();
    		$type = isset( $data['type'] ) ? $data['type'] : '';
    
    		if ( $type == 'variable' ) :
    			// nested variations
    			foreach ( $data['variations'] as &$variation ) :
    
    				if ( version_compare( WC()->version, '3.7', '<' ) ) {
    					$response = WC()->api->WC_REST_Product_Variations_Controller->get_item(
    						array(
    							'id'         => $variation,
    							'product_id' => $variation
    						)
    					);
    				} else {
    					$variation_controller = new WC_REST_Product_Variations_Controller();
    					$response             = $variation_controller->get_item(
    						array(
    							'id'         => $variation,
    							'product_id' => $variation
    						)
    					);
    				}
    				$variation = $response->get_data();
    			endforeach;
    		endif;
    ...
    

    In a conditionnal for new woocommerce version you call function get_item() which doesn’t exist for WC_REST_Product_Variations_Controller.
    And you want to add into it a class objet.

    $response             = $variation_controller->get_item(
    						array(
    							'id'         => $variation, (Variation is not numeric here and you want to add it to 'id'
    							'product_id' => $variation
    						)
    					);
    

    And when I Print out WP_Error message, I got
    ID non valide.

    Hope you can check it in next release.
    Thank you

    • This topic was modified 5 years, 7 months ago by manaka02.
Viewing 1 replies (of 1 total)
  • Thread Starter manaka02

    (@manaka02)

    If I change it like this, it works :

    else {
    					$variation_controller = new WC_REST_Product_Variations_Controller();
    					$response             = $variation_controller->get_item(
    						array(
    							'id'         => $variation['id'],
    							'product_id' => $variation
    						)
    					);
    				}
    

    use $variation[id] instead of $variation

Viewing 1 replies (of 1 total)
  • The topic ‘Variable Product Case : Fatal Error’ is closed to new replies.