Magento JOIN between two filtered user collections

I have two custom models ("myorder" and "myarticle") . Each " myarticle " has a foreign key " rif_ord_app " that points to the corresponding field " myorder " " rif_ordine_vsp ". I need to filter both collections and then CONNECT them using the two fields β€œ rif_ord_app ” and β€œ rif_ordine_vsp ”.

For instance:

I am filtering the "Myorders" collection:

 $collection_orders = Mage::getModel('mycomp_logistic/myorder')->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('customer_id', array('in' => array_values($arrayCustomersId))) ->addAttributeToFilter('payment_done_online', array('eq' => ($filter['is_from_where'] == 'from_web'))) ->addAttributeToFilter('pdv_ritiro_id', array('eq' => $filter['pdv_ritiro_code'])) ->addAttributeToFilter('pdv_ordinante_id', array('eq' => $filter['pdv_ordinante_code'])) ->addAttributeToFilter('rif_ordine_vsp', array('eq' => $filter['num_ord'])) ->addAttributeToFilter('data_ordine', array('from' => $daydate)); 

... then I filter the "myarticle" collection:

 $collection_articles = Mage::getModel('mycomp_logistic/myarticle')->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('num_bolla', array('eq' => $filter['cod_bolla'])) ->addAttributeToFilter('sscc', array('eq' => $filter['sscc'])) ->addAttributeToFilter('stato', array('eq' => $filter['st_art'])); 

... and finally ... I was not able to join the two collections.

I tried something like this:

 $tbl_order = Mage::getSingleton('core/resource')->getTableName('mycomp_logistic/myorder'); $collection_articles = $collection_articles->getSelect()->join(array('t2' => $tbl_order), 'main_table.rif_ord_app = t2.rif_ordine_vsp', 't2.rif_ordine_vsp'); 

..but I'm sure this is the wrong way.

Any help?

+5
source share
1 answer

If you still want to use DDL, you must do Join and apply filters after that ... You cannot join 2 filtered collections to create 1 collection

0
source

Source: https://habr.com/ru/post/1484655/


All Articles