2

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')
                                                    ->getCollection()
                                                    ->addFieldToFilter(
                                                        'mageproduct_id',
                                                        $product_id
                                                    )->addFieldToFilter(
                                                        'order_id',
                                                        ['in' => $order_id_list]
                                                    )->addFieldToFilter(
                                                        'seller_id',
                                                        $sellerId
                                                    )->setOrder('magequantity','DESC');

                                                foreach ($trackingcol_saleslist as $info) {
                                                 print_r($info->getData());
                                                }

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?

2
  • you can change varchar to int by upgrade schema in module Commented Nov 24, 2016 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
    Commented Nov 24, 2016 at 9:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.