2

I've try to resolve this issue many hours but end up with no luck.

Here is the senario:

I have a store locator and have 2 types of dealers. Master and General. I need to list Master dealer first and General Dealers 2nd. Best solution is to use UNION in collection

 $cloneSelect = clone( $collection1->getSelect() ); $collection1->getSelect()->reset()->union( array( "( ". $cloneSelect ." )", "( ". $collection2->getSelect() ." )", ) ); 

When I view $collection->getSelect()->__toString() this generate ( $collection1 ) UNION ( $collectio2 )

but when I apply $collection1->getSize() or any method it generate following error.

No table has been specified for the FROM clause

I know it generate this error becouse $collection need to have from clause, If that's the case dose anyone have IDEA how to do union and get collection

Thanks

1
  • Show the whole SQL please. Commented Jul 24, 2014 at 14:55

3 Answers 3

2

May be you can resolve it by sorting results? Like order by if(master_condition, 1, 0)

2

Did you try:

$select = $collection1->getSelect()->union($collection2->getSelect()); 
1

I was having this problem when using union in the Widget_Grid block "_prepareCollection()" method, that in the process calls the getSize() method you mentioned.

I solved it by using a third auxiliary collection (of which I only selected one key field), and then joining it with my "united" collections on that same key.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.