Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Query Builder in Xcart

 
Reply
   X-Cart forums > X-Cart 5 > General questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 03-12-2018, 02:48 AM
 
Soptareanu Alex Soptareanu Alex is offline
 

Member
  
Join Date: Sep 2016
Posts: 24
 

Question 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 ?
__________________
alex
Reply With Quote
  #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

The following user thanks tony_sologubov for this useful post:
Soptareanu Alex (03-12-2018)
  #3  
Old 03-12-2018, 04:43 AM
 
Soptareanu Alex Soptareanu Alex is offline
 

Member
  
Join Date: Sep 2016
Posts: 24
 

Default 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 !
__________________
alex
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > General questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:21 PM.

   

 
X-Cart forums © 2001-2020