X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   General questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=66)
-   -   Query Builder in Xcart (https://forum.x-cart.com/showthread.php?t=76086)

Soptareanu Alex 03-12-2018 02:48 AM

Query Builder in Xcart
 
Hello I need to retrive some order by shipping status. For that task I try to use query builder but I get some errors.
This is my query :
$aBackOrders = \XLite\Core\Database::getRepo('\XLite\Model\Order' )
->createQueryBuilder('o')
->andWhere('o.shipping_status_id = :id')
->setParameter('id', 4)
->getResult();
And this is the error that i get :
[Semantical Error] line 0, col 78 near 'shipping_status_id': Error: Class XLite\Model\Order has no field or association named shipping_status_id

What I'm doing wrong ?

tony_sologubov 03-12-2018 03:23 AM

Re: Query Builder in Xcart
 
Quote:

Originally Posted by Soptareanu Alex
Hello I need to retrive some order by shipping status. For that task I try to use query builder but I get some errors.
This is my query :
$aBackOrders = \XLite\Core\Database::getRepo('\XLite\Model\Order' )
->createQueryBuilder('o')
->andWhere('o.shipping_status_id = :id')
->setParameter('id', 4)
->getResult();
And this is the error that i get :
[Semantical Error] line 0, col 78 near 'shipping_status_id': Error: Class XLite\Model\Order has no field or association named shipping_status_id

What I'm doing wrong ?


Your request should be as follows:
Code:

$aBackOrders = \XLite\Core\Database::getRepo('\XLite\Model\Order')
                          ->createQueryBuilder('o')
                          ->andWhere('o.shippingStatus = :id')
                          ->setParameter('id', 4)
                          ->getResult();


Doctrine only works with properties in model class (in your case \XLite\Model\Order) and there is no property called 'shipping_status_id'. Instead you should work with 'shippingStatus' property and you can specify its value as ID (in my example) or as an entire \XLite\Model\Order\Status\Shipping object.

Please, let me know if it helps.

Tony

Soptareanu Alex 03-12-2018 04:43 AM

Re: Query Builder in Xcart
 
Quote:

Originally Posted by tony_sologubov
Your request should be as follows:
Code:

$aBackOrders = \XLite\Core\Database::getRepo('\XLite\Model\Order')
                          ->createQueryBuilder('o')
                          ->andWhere('o.shippingStatus = :id')
                          ->setParameter('id', 4)
                          ->getResult();


Doctrine only works with properties in model class (in your case \XLite\Model\Order) and there is no property called 'shipping_status_id'. Instead you should work with 'shippingStatus' property and you can specify its value as ID (in my example) or as an entire \XLite\Model\Order\Status\Shipping object.

Please, let me know if it helps.

Tony

Yes ! It works. Thanks very much for the advice !


All times are GMT -8. The time now is 07:59 AM.

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