0

I have two different collection one is of order payment transaction and other one is of sales order as show below:

$transactionData=Mage::getModel('sales/order_payment_transaction')->getCollection();
$orderData=Mage::getModel('sales/order')->getCollection();

I want to combine them into single collection. Also where can I find payment method cause I don`t see it under orderData or transactionData collection.

2
  • What are you trying to find you get payment method details from order Commented Jun 22, 2018 at 15:52
  • Oh Okay I could`nt see in the collection when I was printing it but I fetched it by referring to the link below: magento.stackexchange.com/questions/156933/… Now the question is how should I merge/join the collection? Commented Jun 22, 2018 at 16:59

2 Answers 2

0

You can not merge two different collection in one

you can merge two same collection in one same as below example

$collection1 = Mage::getModel('catalog/category')->load(148)->getProductCollection();
$collection2 = Mage::getModel('catalog/category')->load(149)->getProductCollection();

$merged_ids = array_merge($collection1->getAllIds(), $collection2->getAllIds());
// can sometimes use "getLoadedIds()" as well

$merged_collection = Mage::getResourceModel('catalog/product_collection')
    ->addFieldToFilter('entity_id', array('in' => $merged_ids))
    ->addAttributeToSelect('*');

You can try one work around for your solution, you can create required field array from both collection and use it.

1
  • Oh Okay I`ll give a shot! Commented Jun 25, 2018 at 16:55
0

you can try below code to merge two collection in Magento Query


$transactionData=Mage::getModel('sales/order_payment_transaction')->getCollection()->getSelect();
$orderData=Mage::getModel('sales/order')->getCollection()->getSelect();
$mergeCollection = $transactionData->union(array($orderData));

you can use unionall to prevent duplicate records.

5
  • Your solution did`nt work for me! Commented Jun 25, 2018 at 16:55
  • is it showing any error ?? or you can not get result.
    – MR.R DNATH
    Commented Jun 25, 2018 at 17:59
  • Nope it is not showing any error but I cannot see any output when I var_dump it! Commented Jun 25, 2018 at 18:13
  • try echo $mergeCollection->getSelect()
    – MR.R DNATH
    Commented Jun 25, 2018 at 19:18
  • Still the same! Commented Jun 25, 2018 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.