• Resolved aviegrinberg

    (@aviegrinberg)


    Hello thank you for the excellent work.

    This is all in dev so no urgency, I am working with a local install of WordPress, PHP, etc. and using NextJS as the font end.

    I am adding 3 products in sequence in postman, the first product is added to the cart {“id”:”1134″,”quantity”:”1″} using the url : https://localhost/wp-json/cocart/v2/cart/add-item without an issue. When I add the second item I use the cart_key returned as a param in postman as documented, no issues here either and I get two items returned in the response.

    The third item is the issue (intermittently or depending on the product sequence strangely enough). I get a postman error as follows:

    <html>

    <head><title>502 Bad Gateway</title></head>

    <body>

    <center><h1>502 Bad Gateway</h1></center>

    <hr><center>nginx/1.18.0 (Ubuntu)</center>

    </body>

    </html>

    However when I query the cart separately (using the same cart_key in postman: https://localhost/wp-json/cocart/v2/cart/items?cart_key=e7a13688bf9b4d7d864c51f9037f37 I get all three items and their correct quantities.

    When I uninstall the enhanced Plugin everything works fine, no 502 errors, but I really need the stock quantities returned from the enhanced plugin as it makes the font end code much simpler (just a single cart array)

    • This topic was modified 1 month, 3 weeks ago by aviegrinberg. Reason: i had a typo which needed to be corrected
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter aviegrinberg

    (@aviegrinberg)

    Hi just to follow up I read your article about setting up a custom plugin and it compelled me to look at the underlying code in this plugin as well in the wp-content/plugins/cocart-get-enhanced/includes/filters/filter-v2.php file. I just commented out the two filters separately and retried the postman steps above, and found the problem was within the ‘return_product_details’ filter. After commenting out a few sections of that particular filter, I was able to isolate the issue to the following block of code which I dont really need for my project (so i just commented it out in my plugin) but just so you are aware:

    // Product gallery images.

    // $gallery_ids = $_product->get_gallery_image_ids();

    // $cart_contents[ $item_key ]['gallery'] = array();

    // if ( ! empty( $gallery_ids ) ) {

    // foreach ( $gallery_ids as $image_id ) {

    // $gallery_id = apply_filters( 'cocart_item_gallery', $image_id, $cart_item, $item_key );

    // $gallery_src = wp_get_attachment_image_src( $gallery_id, apply_filters( 'cocart_item_gallery_thumbnail_size', 'woocommerce_thumbnail' ) );

    // /**

    // * Filters the source of the product gallery image.

    // *

    // * @param string $gallery_src URL of the product gallery image.

    // */

    // $gallery_src = apply_filters( 'cocart_item_thumbnail_src', $gallery_src[0], $cart_item, $item_key, $removed_item );

    // $cart_contents[ $item_key ]['gallery'][ $gallery_id ] = $gallery_src;

    // }

    // }
    Plugin Author Sébastien Dumont

    (@sebd86)

    Seems there was an issue with the third product, so that part of the code you disabled could not identify and it crashed when returning the response. Would be better if you had the actual error to identify the exact line to fix.

    Thread Starter aviegrinberg

    (@aviegrinberg)

    I enabled PHP logging by downloading a plugin called “Error Log Monitor” because I am unfamiliar with the WordPress / PHP environment. Doing this alone removed the 502 error in postman. Looking at the new error log I noticed the following warning:

    Warning: Undefined variable $removed_item in /var/www/html/wp-content/plugins/cocart-get-cart-enhanced/includes/filters/filter-v2.php on line 101

    So I just removed that variable completely and the warning disappeared as well. Thank you for the guidance much appreciated.

    Plugin Author Sébastien Dumont

    (@sebd86)

    Thank you for reporting the exact error. Much appreciated. A patch will be uploaded soon.

    Thread Starter aviegrinberg

    (@aviegrinberg)

    Awesome thank you ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.