Post by Zanato » Wed Feb 12, 2025 11:17 pm

So I asked chatGPT to "Write a VQMOD to add a delete button to the orders page in Admin in opencart" just to save me having to do them one by one. The first and second attempt failed, but on the third attempt, it worked perfect.

I then thought, well I only want this for deleting old missing orders, so why not just "add a button that deletes all missing orders older than 2 months?". And it worked perfect on first attempt.

1500+ orders removed in one click without having to go into the database! ;D

I didn't even tell it which version of OC I'm using (3.0.3).

Ai, interesting, exciting, and worrying, all at the same time.


Code: Select all

  <?xml version="1.0" encoding="UTF-8"?>
<modification>
    <id>Admin Orders Delete Button</id>
    <version>1.5</version>
    <vqmver>2.6.0</vqmver>
    <author>Your Name</author>
    <description>Adds delete buttons to the admin orders page and implements order deletion functions</description>

  <!-- Add Delete Button to Orders List Page -->
    <file name="admin/view/template/sale/order_list.twig">
        <operation>
            <search><![CDATA[<button type="button" data-toggle="tooltip" title="{{ button_filter }}" onclick="$('#filter-order').toggleClass('hidden-sm hidden-xs');" class="btn btn-default hidden-md hidden-lg"><i class="fa fa-filter"></i></button>]]></search>
             <add position="before"><![CDATA[
                <button type="button" id="button-delete" class="btn btn-danger"><i class="fa fa-trash"></i> Delete</button>
                <button type="button" id="button-delete-missing" class="btn btn-warning"><i class="fa fa-trash"></i> Delete Missing Orders (Older than 2 Months)</button>
                <script>
                    document.getElementById('button-delete').addEventListener('click', function() {
                        if (confirm('Are you sure you want to delete the selected orders?')) {
                            var selected = [];
                            document.querySelectorAll('input[name="selected[]"]:checked').forEach(function(el) {
                                selected.push(el.value);
                            });
                            if (selected.length > 0) {
                                let formData = new FormData();
                                selected.forEach(id => formData.append('selected[]', id));
                                fetch('index.php?route=sale/order/deleteOrders&user_token=' + getURLVar('user_token'), {
                                    method: 'POST',
                                    body: formData
                                }).then(response => response.json()).then(data => {
                                    if (data.success) {
                                        location.reload();
                                    } else {
                                        alert('Error deleting orders: ' + (data.error || 'Unknown error'));
                                    }
                                }).catch(error => console.error('Error:', error));
                            } else {
                                alert('No orders selected!');
                            }
                        }
                    });
                    document.getElementById('button-delete-missing').addEventListener('click', function() {
                        if (confirm('Are you sure you want to delete all missing orders older than 2 months?')) {
                            fetch('index.php?route=sale/order/deleteMissingOrders&user_token=' + getURLVar('user_token'), {
                                method: 'POST'
                            }).then(response => response.json()).then(data => {
                                if (data.success) {
                                    location.reload();
                                } else {
                                    alert('Error deleting missing orders: ' + (data.error || 'Unknown error'));
                                }
                            }).catch(error => console.error('Error:', error));
                        }
                    });
                </script>
            ]]></add>
        </operation>
    </file>

    <!-- Add Delete Actions to Controller -->
    <file name="admin/controller/sale/order.php">
        <operation>
            <search><![CDATA[class ControllerSaleOrder extends Controller {]]></search>
            <add position="after"><![CDATA[
                public function deleteOrders() {
                    $this->load->language('sale/order');
                    $json = [];
                    if (!$this->user->hasPermission('modify', 'sale/order')) {
                        $json['error'] = $this->language->get('error_permission');
                    } else {
                        if (!empty($this->request->post['selected']) && is_array($this->request->post['selected'])) {
                            $this->load->model('sale/order');
                            foreach ($this->request->post['selected'] as $order_id) {
                                $this->model_sale_order->deleteOrder($order_id);
                            }
                            $json['success'] = 'Selected orders have been deleted!';
                        } else {
                            $json['error'] = 'No orders selected or invalid format!';
                        }
                    }
                    $this->response->addHeader('Content-Type: application/json');
                    $this->response->setOutput(json_encode($json));
                }
                public function deleteMissingOrders() {
                    $this->load->model('sale/order');
                    $this->model_sale_order->deleteMissingOrders();
                    $this->response->addHeader('Content-Type: application/json');
                    $this->response->setOutput(json_encode(['success' => 'All missing orders older than 2 months have been deleted!']));
                }
            ]]></add>
        </operation>
    </file>

    <!-- Add Delete Missing Orders Function to Model -->
    <file name="admin/model/sale/order.php">
        <operation>
            <search><![CDATA[class ModelSaleOrder extends Model {]]></search>
            <add position="after"><![CDATA[
                public function deleteOrder($order_id) {
                    $this->db->query("DELETE FROM " . DB_PREFIX . "order WHERE order_id = '" . (int)$order_id . "'");
                    $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
                    $this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "'");
                    $this->db->query("DELETE FROM " . DB_PREFIX . "order_history WHERE order_id = '" . (int)$order_id . "'");
                    $this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
                }
                public function deleteMissingOrders() {
                    $this->db->query("DELETE FROM " . DB_PREFIX . "order WHERE order_status_id = 0 AND date_added < DATE_SUB(NOW(), INTERVAL 2 MONTH)");
                }
            ]]></add>
        </operation>
    </file>
</modification>

New member

Posts

Joined
Fri Oct 04, 2013 4:58 am
Location - Dublin, Ireland

Post by Cue4cheap » Thu Feb 13, 2025 2:43 am

ChatGPT is decent but still misses a lot of logic.
I did almost the same for an extension that was written for < 7.3 and asked it to do 8.2. It crashed an burned. The coding is ok but you'll most likely spend more time debugging versus just re-writing it.

Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Zanato » Fri Feb 14, 2025 6:10 pm

Cue4cheap wrote:
Thu Feb 13, 2025 2:43 am
...you'll most likely spend more time debugging versus just re-writing it.
That's the thing though, I'm not a developer. It would have taken me hours of looking at files and other mods, trying this, trying that, before I got even close. Or I could have paid someone, or spent hours in the forums looking for help. ChatGPT did it in seconds with a very simple one sentence prompt. OK, I had to tell it the first two didn't work but it amended it each time and on the third attempt, hey presto!

I was very impressed. But a little concerned too!

I know ChatGPT isn't perfect, but it's getting better and better. In 5 or 6 years time how good will it be? Will it be able to write advanced plugins? A whole ecommerce platform from scratch, in seconds? It must be very worrying for certain professions. I've a brother who's an animator for a small studio here in Ireland, he's already looking at starting a new career. He's convinced his job will be redundant in the next few years because of Ai.

Interesting times ahead.

New member

Posts

Joined
Fri Oct 04, 2013 4:58 am
Location - Dublin, Ireland

Post by Cue4cheap » Sat Feb 15, 2025 10:36 am

Oh I agree with you. But it still has quite a bit to go. For example I updated a modification that is available in the marketplace to be php 8.2 compatible. I then took the original and asked chatgpt to do it too. Not bad.
Then I told it to convert the 2.3.0.2 version to 3.0.4.0 version. It just renamed the tpl files to twig but left the logic as the tpl.
I then gave it an example and told it it still has the old format.
After 3 times of telling it has the wrong logic this is what it still produced

Code: Select all

  <div class="row">{{ $column_left }}
    {% if $column_left && $column_right %}
    {% set class = 'col-sm-6' %}
    <?php } elseif ($column_left || $column_right) { ?>
    {% set class = 'col-sm-9' %}
    <?php } else { ?>
    {% set class = 'col-sm-12' %}
    <?php } ?>
    <div id="content" class="{{ $class }}">{{ $content_top }}
      <h1>{{ $heading_title }}</h1>
      <table class="table table-bordered table-striped table-hover">
	    <thead>
		  <tr>
			<th></th>
			<th>{{ $text_title }}</th>
			<th>{{ $text_description }}</th>
			<th>{{ $text_date }}</th>
			<th class="text-right"></th>
		  </tr>
		</thead>
It is interesting and I DO see a time when this will work so much better but I am also afraid of how much time and tracing it'll take to find the bugs.
I know in my primary job there is no way we'd allow AI to program our equipment as the wrong code can isolate a LOT of customers.
I do say pretty incredible for the time we have had this AI stuff available to us.

Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am

Post by Zanato » Sat Feb 15, 2025 6:37 pm

Cue4cheap wrote:
Sat Feb 15, 2025 10:36 am
After 3 times of telling it has the wrong logic this is what it still produced...
Have you tried with different Models? o1 and 03-mini-high give FAR better results than the default GPT-4o model.

Image

New member

Posts

Joined
Fri Oct 04, 2013 4:58 am
Location - Dublin, Ireland

Post by Cue4cheap » Sun Feb 16, 2025 6:38 am

I am not. I am just using the free one.

Mike

cue4cheap not cheap quality


Expert Member

Posts

Joined
Fri Sep 20, 2013 4:45 am
Who is online

Users browsing this forum: Semrush [Bot] and 10 guests