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?