Has anyone used ChatGPT to generate code?

Developer
Od United States
Użytkownik od lip 2023

I was reading an article ([url=https://resources.altium.com/p/using-chatgpt-automated-testing]altium[/url]) about testing PCB's with [url=https://chat.openai.com/]ChatGPT[/url], an AI driven beta product that is still free, I believe.  I thought of a post by @s22_tech that asked about a better way to do some JavaScript coding.  That thread is academic now, since @tim included the thousands seperator in the latest release of LiteCart, but I found the potential capabilities of ChatGPT intriguing.  I was curious if anyone had any experience using ChatGPT for anything, but especially asking it to generate code.

Moderator
Od Lithuania
Użytkownik od mar 2016

I have tried using it several times, but honestly it didn't worked out for me.

It can work for some specific cases but these have to be tested out individually.

I hear that ChatGPT4(paid) is somewhat better than ChatGPT3.5(free), but this needs to be confirmed.

tim
Founder
Od Sweden
Użytkownik od maj 2013
tim

I have used Github Copilot in Visual Studio Code, which is quite accurate in autocompleting code for LiteCart. But I haven't tried Chat GPT. I don't think it's clever enough to figure out framework environments just yet.

Merchant
Od United Kingdom
Użytkownik od kwi 2023

I used it to create a novelty add to cart animation that spins the product pic up to the cart icon. The kids love it but the parents hate it because it encourages the kids to add more to the cart than they're allowed lol.

check it out at https://candypalace.net

Developer
Od United States
Użytkownik od lip 2023

SWEET!

tim
Founder
Od Sweden
Użytkownik od maj 2013
tim

Wow that is supernice :)

Merchant
Od United Kingdom
Użytkownik od kwi 2023

Thanks Tim. There is still a fair bit of work to do to get the site where I want it. but the site is working well. But i've really got to give you the credit, Firstly for coding LiteCart which in my opinion is one of the best free scripts out there. Believe me I've tried them all but many are too complicated for me who's just learning how to code. I'm finding LiteCart fairly easy to get my head around and learning all the time. 

As for the point of my reply to this topic about chatGPT I simply asked it to look at the code of your original add to cart animation and asked it to fly the product image to the cart in a spinning motion. And to my surprise it came up with what you see on the site. I've got 10 grandkids who all love the feature. who says websites cant be fun to use lol.

tim
Founder
Od Sweden
Użytkownik od maj 2013
tim

Thank you for the kind words, they  made me smile. I am truly trying my best to always make this platform simpler, better, faster, and even more fun to play with. 🙂

That is pretty impressive by ChatGPT. I only used it for simpler things like "Can you give me a comma separated list of all EU countries by their two letter ISO code?".

Merchant
Od United Kingdom
Użytkownik od kwi 2023

Tried to use chatgpt to make some modifications but it couldn't really come up with a solution. So my son Kyle stepped in. He's at college studying computer science. Anyway I wanted the shopping cart out of the header and placed at the bottom right always in view so the parents could easily keep an eye on the number of items the kids were adding to the cart. I also wanted the subtotal displayed. I think what my son came up with looks very cool. I would appreciate any feedback on this. Cheers.

You can see a demo here:

https://www.candypalace.net/seriously-sour-c-20/juicy-drop-chews-67g-p-640

Merchant
Od United Kingdom
Użytkownik od kwi 2023

One thing that we haven't got our heads around yet is how the quantity in the cart badge is updated without reloading the page. We cant seem to find the code that does this. We would like the same for the cart subtotal. Temporally we have used location.reload(); at the end of the JS animation to achieve this but would rather have the subtotal update without the page reload.

Merchant
Od United Kingdom
Użytkownik od kwi 2023

My apologies we put location.reload(); at the bottom of the following code in app.js

// Update cart / Keep alive
  var num_cart_updates = 0;
  window.updateCart = function(data) {
    $.ajax({
      url: window._env.platform.url + 'ajax/cart.json',
      type: data ? 'post' : 'get',
      data: data,
      cache: false,
      async: true,
      dataType: 'json',
      beforeSend: function(jqXHR) {
        jqXHR.overrideMimeType('text/html;charset=' + $('meta[charset]').attr('charset'));
      },
      error: function(jqXHR, textStatus, errorThrown) {
        if (data) alert('Error while updating cart');
        console.error('Error while updating cart');
        console.debug(jqXHR.responseText);
      },
      success: function(json) {
        if (json['alert']) alert(json['alert']);
        $('#cart .items').html('');
        if (json['items']) {
          $.each(json['items'], function(i, item){
            $('#cart .items').append('<li><a href="'+ item.link +'">'+ item.quantity +' x '+ item.name +' - '+ item.formatted_price +'</a></li>');
          });
          $('#cart .items').append('<li class="dropdown-divider"></li>');
        }
        $('#cart .items').append('<li><a href="' + window._env.platform.url + 'checkout"><i class="fa fa-shopping-cart"></i> ' + json['text_total'] + ': <span class="formatted-value">'+ json['formatted_value'] +'</a></li>');
        $('#cart .quantity').html(json['quantity'] ? json['quantity'] : '');
        $('#cart .formatted_value').html(json['formatted_value'] ? json['quantity'] : '');
        [b]location.reload();[/b]
      }
    });

Moderator
Od Lithuania
Użytkownik od mar 2016

I think you should make all basket linking to cart instead only the red circle. Also for mobile it could be a little smaller as now it takes a lot of space for smaller screens. This is not the best UX for your clients.

Merchant
Od United Kingdom
Użytkownik od kwi 2023

Hi Dodo Thanks for your feedback. we have sorted the link issue you mentioned and reduced the size of the cart widget by 25%. It displays as intended on all the devices we have tested it on - mobile small screen, desktop and tv's. We have had positive feedback from the parents and their children who are our regular customers. the kids love the animation of the product image spinning to the cart but the parents were complaining the that the kids were trigger happy firing many products to the cart and they couldn't see how many products had been added and the cart sub total unless they scrolled to the top of the page. So this is the reason we took the cart out of the menu bar and made it always visible in the bottom right of the screen. The feedback we have had from the parents is that it doesn't interfere with the user experience but enhances it because they can now see what they are spending. The background image is a picture of the actual bag we deliver the sweets in which personalise with the kids names. Yes it requires work but we are learning.

tim
Founder
Od Sweden
Użytkownik od maj 2013
tim

I think it turned out great! My kid would love it.

Merchant
Od United Kingdom
Użytkownik od kwi 2023

Thanks Tim. Yes i'd say it's almost how we want it other than using the location.reload(); so the cart sub total updates. We didn't really want to reload the page every time something is added to the cart but we couldn't find another way of doing it and we can't find how the item quantity updates without a page reload, We were hoping we could replicate that for the cart sub total.

tim
Founder
Od Sweden
Użytkownik od maj 2013
tim

ajax/cart.json returns the subtotal value in the parameter value:

{"items":[],"quantity":0,"value":0,"formatted_value":"$0","text_total":"Total"}

Merchant
Od United Kingdom
Użytkownik od kwi 2023

Hi Tim. Thanks for that. This is how we are currently getting the cart total in box_cart.inc.php:<?php echo $cart_total ? $cart_total : ''; ?> and then location.reload(); in app.js 
We are not sure how to use the code you posted.

Thanks for pointing me in the right direction Tim. I'm Finally getting somewhere with it.

tim
Founder
Od Sweden
Użytkownik od maj 2013
tim

If you look at the updateCart() function in app.js you have a success handler that handles the ajax result. You need to address the right node elements for updating.
https://github.com/litecart/litecart/blob/2.5.4/public_html/includes/templates/default.catalog/js/app.js#L175-L186

The default code expects a node named <div id="cart"> holding <span class="formatted-value"></span>.
$('#cart .formatted_value').html(json['formatted_value']);
Reference your element instead.
$('#cart-total').html(json['formatted_value']);

Merchant
Od United Kingdom
Użytkownik od kwi 2023

Thanks very much for your help Tim. Much appreciated.

Developer
Od United States
Użytkownik od lip 2023

When I first posted this a few months back, I knew next to nothing about chatGPT or LLM, now I'm feeling like I am developing "AI Fatigue", with the hype train racing down the tracks.  It was so refreshing to me that Blender 4.0 just has a lot of incredible new features with no AI buzz words.

Bravo Blender!!!

Ty
This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.