Post by haxcop » Sun Aug 14, 2022 11:13 pm

Thanks for looking at my question.

I'm not a dev so please be patience

I have source this code on the marketplace but it's not longer maintened... Testing this ocmod on my testing installation in Opencart 3.0.3.6 and 3.0.3.8

This xml file will automatically add a product sort order number in the Frontend if the product have 0 and it will mirror the product ID into the Sort-order field but it won't actually assing it into the DB Table, and it will be good to have it added to the db as well too

Thanks for your collaboration,

https://github.com/opencart/opencart/bl ... roduct.php admin/controller/catalog/product.php
https://github.com/opencart/opencart/bl ... roduct.php admin/model/catalog/product.php

Code: Select all

<file path="admin/controller/catalog/product.php">
        <operation>
            <search><![CDATA[ $data['sort_order'] = $this->request->post['sort_order']; ]]></search>
            <add position="after"><![CDATA[ } elseif ((!empty($product_info)) && ($product_info['sort_order'] == 0)) {
                $data['sort_order'] = ( 0 + $this->request->get['product_id'] );]]></add>
        </operation>
    <!-- Automatic Product Sort Number -->
            <operation>
                <search><![CDATA[ $data['sort_order'] = 1; ]]></search>
                <add position=" replace"><![CDATA[ $data['sort_order'] = 0;]]></add>
            </operation>
        </file>
Last edited by haxcop on Mon Feb 06, 2023 4:13 am, edited 1 time in total.

New member

Posts

Joined
Tue Jan 14, 2014 9:38 pm
Location - Dublin

Post by hpwebdesign » Thu Oct 20, 2022 12:30 pm

Code: Select all

<file path="admin/model/catalog/product.php">
        <operation error="skip">
            <search><![CDATA[if (isset($data['image'])) {]]></search>
            <add position="before"><![CDATA[
            if((int)$data['sort_order'] == 0){
              
              $this->db->query("UPDATE " . DB_PREFIX . "product SET sort_order = '" . (int)$product_id . "' WHERE product_id = '" . (int)$product_id . "'");
               
            }
            ]]></add>
        </operation>
    </file>
I guess you can add this, every time you save (add/edit) a product, the sort order will be replaced with the product_id if the sort order is 0

HP Web Design
http://hpwebdesign.io
Opencart Extension Development | OpenCart Professional Services | OpenCart Tutorials


User avatar
New member

Posts

Joined
Wed Aug 15, 2018 6:58 am
Location - Yogyakarta
Who is online

Users browsing this forum: No registered users and 39 guests