Home Forums WoodMart support forum Problem with REST API (PUT in products/attributes)

Problem with REST API (PUT in products/attributes)

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #93474

    jcmachado
    Participant

    I’m trying to sync my ERP data with my WooCommerce Store and, after installing Woodmart Theme, I’m getting the following error trying to update the Product Attributes:
    Uncaught Error: Call to undefined function woodmart_admin_scripts_localize()

    What is the workaround?
    Following, the complete error log:

    Notice: Undefined index: attribute_swatch_size in /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-content/themes/woodmart/inc/integrations/woocommerce/modules/attributes-meta-boxes.php on line 17

    Notice: Undefined index: attribute_show_on_product in /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-content/themes/woodmart/inc/integrations/woocommerce/modules/attributes-meta-boxes.php on line 19

    Fatal error: Uncaught Error: Call to undefined function woodmart_admin_scripts_localize() in /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-content/themes/woodmart/inc/integrations/woocommerce/modules/attributes-meta-boxes.php:22 Stack trace: #0 /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-includes/class-wp-hook.php(286): woodmart_wc_attribute_update(387, Array, ‘carne-por-espet…’) #1 /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array) #2 /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-content/plugins/woocommerce/includes/wc-attribute-functions.php(520): do_action(‘woocommerce_att…’, 387, Array, ‘carne-por-espet…’) #4 /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-content/plugins/woocommerce/includes/wc-attribute-functions.php(607): wc_create_attribute(Array) #5 /home/222535.cloudwaysapps.com/wm in /home/222535.cloudwaysapps.com/wmwmqusqsy/public_html/wp-content/themes/woodmart/inc/integrations/woocommerce/modules/attributes-meta-boxes.php on line 22

    #93483

    Artem Temos
    Keymaster

    Hi,

    Please, describe to us your problems in a bit more details. Attach some screenshots and provide us with a list of steps on how to reproduce it on your website. We will need your admin and FTP access to check this as well.

    Thank you in advance.

    #93495

    jcmachado
    Participant

    Thank you for the response.

    Well, I have a program which uses the WooCommerce REST API in order to create products, its attributes and other product data from my ERP. Its simply uses http requests as documented by the API. I’m having a problem specifically when I try to update product attributes.

    When I try a PUT request in wp-json/wc/v2/products/attributes/id endpoint, I end receiving the “Uncaught Error: Call to undefined function woodmart_admin_scripts_localize()” error.

    Can you test the request using Postman (https://www.getpostman.com) app or ARC Chrome Extension? The instructions are below.

    Attachments:
    You must be logged in to view attached files.
    #93557

    Artem Temos
    Keymaster

    Hi,

    We need your admin access also. Be sure that you don’t have any extra plugins installed and don’t use a child theme.

    Regards

    #93663

    jcmachado
    Participant

    Well, I do have some extra plugins, in order to support all my online store needs. But I think is somewhat related to Woodstore Theme (hence the error message) and because I tested the same process in my old store, with the same plugins but using Storefront theme.

    Tha admin accessa credentials are provided below.

    #93687

    Artem Temos
    Keymaster

    Anyway, we need to disable them to be able to check without a plugin. If you can’t do this on your live website, we suggest you create a development copy where you can do such experiments.

    #93833

    jcmachado
    Participant

    We can do this in our current live site. Just e-mail me, please, during your access so I can be aware of any inconsistency.

    Can you e-mail me at the beginning and the end of your interaction?

    #93941

    Artem Temos
    Keymaster

    Hi,

    We just checked it but there are two problems: we can’t connect to your server with the FTP you provided and we don’t see errors, just 500 Internal Server Error.

    #94025

    jcmachado
    Participant

    Hello!

    In order to get the described error message instead of the simple error 500 message, you have to enable the define('WP_DEBUG', false); directive in wp-config.php file. I leave it as false to prevent unwanted error messages displayed to the users.

    If you succeed in accessing the FTP, can you set it to true to test and then set it back to false, please?

    Are you trying to access by FTP or SFTP? Can you send me your IP so I can whitelist it?

    Thanks.

    #94036

    Artem Temos
    Keymaster

    Try to add the following PHP code snippet to the child theme functions.php file to fix this

    add_action( 'woocommerce_attribute_updated', 'woodmart_wc_attribute_update', 20, 3);
    function woodmart_wc_attribute_update( $attribute_id, $attribute, $old_attribute_name ) {
    	update_option( 'woodmart_pa_' . $attribute['attribute_name'] . '_swatch_size', $_POST['attribute_swatch_size'] );
    
    	update_option( 'woodmart_pa_' . $attribute['attribute_name'] . '_show_on_product', $_POST['attribute_show_on_product'] );
    
    	// Change value of selected option
    	if( function_exists( 'woodmart_admin_scripts_localize' ) ) 
    	woodmart_admin_scripts_localize();
    }
    #94128

    jcmachado
    Participant

    Apparently, everything is working fine!
    Thank you very much!

    #94162

    Artem Temos
    Keymaster

    You are welcome.

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Problem with REST API (PUT in products/attributes)’ is closed to new replies.