View Single Post
  #2  
Old 03-12-2018, 03:23 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default 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
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote