X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Custom select Query issue (https://forum.x-cart.com/showthread.php?t=74996)

Sooraj 02-15-2017 04:01 AM

Custom select Query issue
 
Hi,

I was trying to integrate a third party library related to order.
I need to fetch previous order placed customer prior to current order.

MySQL query is
Code:

SELECT order_id FROM `xc_orders` WHERE orig_profile_id=7 AND is_order=1 AND order_id!=11  ORDER BY order_id DESC LIMIT 1

This is my code.

Code:

$condition = array('orig_profile' => 7, 'is_order'=>1, 'order_id!='=>11);
        $lastOrderInfo = \XLite\Core\Database::getRepo('XLite\Model\Order')->findOneBy($condition);
        return $lastOrderInfo->orderNumber;




But I'm getting "Unrecognized field: is_order" error. How to fix this error.

Sooraj 02-17-2017 12:48 AM

Re: Custom select Query issue
 
This is my new code and worked for me.

Code:

$lastOrderId = 0;
$queryBuilder = \XLite\Core\Database::getRepo('XLite\Model\Order')
                ->createPureQueryBuilder('o');
$lastOrderId = $queryBuilder->select('o.orderNumber')
            ->andWhere('o.orig_profile = :profile_id')
            ->andWhere('o.order_id != :order_id')
            ->andWhere('o.orderNumber IS NOT NULL')
            ->orderBy('o.order_id', 'DESC')
            ->setParameter('profile_id', 7)
            ->setParameter('order_id', 11)
            ->setMaxResults(1)
            ->getSingleResult();
return $lastOrderId;



All times are GMT -8. The time now is 03:47 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.