WPIntell

Source evidence

Fatal error in variation SKU

Search SKU to Product page · support · 2017-10-03T13:06:00+00:00

complaintsentiment
highseverity
0.96relevance
2replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

3 / 28 rows with source links

10.7% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

25 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
Bastien Ho unresolved
Hi, when using SKU in attribute variations, the search results on a fatal error : Fatal error: Uncaught exception 'Exception' with message 'Invalid Product.' in /wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php:134 Stack trace: #0 /wp-content/plugins/woocommerce/includes/class-wc-data-store.php(147): WC_Product_Data_Store_CPT->read(Object(WC_Product)) #1 /wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(126): WC_Data_Store->read(Object(WC_Product)) #2 /wp-content/plugins/woo-search-on-product-sku/index.php(19): WC_Product->__construct('1131') #3 /wp-content/plugins/woo-search-on-product-sku/index.php(31): wsops_get_product_by_sku('MDCM') #4 [internal function]: wsops_product_redirect('') #5 /wp-includes/class-wp-hook.php(298): call_user_func_array('wsops in /wp-content/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php on line 134 This is a blocking issue. This topic was modified 8 years, 7 months ago by Bastien Ho . This patch does the trick: <?php function wsops_get_product_by_sku( $sku ) { global $wpdb; $un_spaced_sku = str_replace(' ', '', $sku); $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND (meta_value='%s' OR meta_value='%s') LIMIT 1", $sku , $un_spaced_sku ) ); $post_type = get_post_type($product_id); if ( $product_id && $post_type=='product_variation') { $product_variation = get_post($product_id); if(!is_wp_error($product_variation) && $product_variation->post_parent){ return new WC_Product( $product_variation->post_parent ); } }elseif ( $product_id && $post_type=='product') { return new WC_Product( $product_id ); } return null; } ?> Hi, any chance to see this patch implemetend ? BR. This reply was modified 8 years, 7 months ago by Bastien Ho .

Comments

2 shown
Bastien Ho 2017-10-03T13:23:00+00:00

This patch does the trick: <?php function wsops_get_product_by_sku( $sku ) { global $wpdb; $un_spaced_sku = str_replace(' ', '', $sku); $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND (meta_value='%s' OR meta_value='%s') LIMIT 1", $sku , $un_spaced_sku ) ); $post_type = get_post_type($product_id); if ( $product_id && $post_type=='product_variation') { $product_variation = get_post($product_id); if(!is_wp_error($product_variation) && $product_variation->post_parent){ return new WC_Product( $product_variation->post_parent ); } }elseif ( $product_id && $post_type=='product') { return new WC_Product( $product_id ); } return null; } ?>

Bastien Ho 2017-10-24T13:45:00+00:00

Hi, any chance to see this patch implemetend ? BR. This reply was modified 8 years, 7 months ago by Bastien Ho .