carloslozada
carloslozada

Reputation: 29

Automatically generate product sort number

Thanks for looking at my question.

I'm not a dev so please be patience

I have source this code on github 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 DB if the product have 0 and it will do it from 5000 in reverse 4999...1....(-50000 - infinity )

I need to do it the opposite and the correct way (for me) from 1 to N

Thanks for your collaboration,

<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'] = ( 5000 - $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>

File admin/controller/catalog/product.php

File admin/model/catalog/product.php

Upvotes: 0

Views: 45

Answers (1)

Sempoinus
Sempoinus

Reputation: 81

I'm not really familiar with opencart, so I'll give you my guesses

Firstly, try if you can change this "after" for "before"

<add position="after">

I'm really just curious if it works :D

My second guess would be to just switch

    $data['sort_order'] = ( 5000 - $this->request->get['product_id'] );]]></add> // this line for
    $data['sort_order'] = ( 0 + $this->request->get['product_id']  );]]></add> // something like this

Upvotes: 1

Related Questions