I have custom extension in magento 2. In that, saleslist table to save order & product list with seller.

saleslist table

mageproduct_id | order_id | seller_id | magequntity(varchar)

select * from saleslist where order_id in (36,37) and mageproduct_id = 2 and seller_id = 20 order by magequantity desc

I am applying above query from below code & this successful return data but not able to sort by magequantity. It's obvious because of VARCHAR datatype.

$trackingcol_saleslist = $this->_objectManager->create('<extesion>\<module>\Model\Saleslist')
                                                        ['in' => $order_id_list]

                                                foreach ($trackingcol_saleslist as $info) {

I have other option to achieve this like, changing column datatype VARCHAR to INT or taking $trackingcol_saleslist as array & apply array sorting.

But I am looking for applying CAST & CONVERT Datatype VARCHAR to INT in magento query. Is this possible in magento?

  • you can change varchar to int by upgrade schema in module – Rakesh Jesadiya Nov 24 '16 at 8:49
  • As I mentioned, that's the one of solution. If I have change, will might affect on other pages. To avoid multiple pages change, I am looking for casing. – Dev Nov 24 '16 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.