Skip to content

Commit be87ff8

Browse files
author
Vladyslav Shcherbyna
committed
MAGETWO-44710: Billing Agreement view page is empty on separate DBs
1 parent e3593ae commit be87ff8

File tree

3 files changed

+123
-8
lines changed

3 files changed

+123
-8
lines changed

app/code/Magento/Paypal/Model/ResourceModel/Billing/Agreement.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ public function addOrderRelation($agreementId, $orderId)
4646
public function addOrdersFilter(\Magento\Framework\Data\Collection\AbstractDb $orderCollection, $agreementIds)
4747
{
4848
$agreementIds = is_array($agreementIds) ? $agreementIds : [$agreementIds];
49-
$orderCollection->getSelect()->joinInner(
50-
['pbao' => $this->getTable('paypal_billing_agreement_order')],
51-
'main_table.entity_id = pbao.order_id',
52-
[]
53-
)->where(
54-
'pbao.agreement_id IN(?)',
55-
$agreementIds
49+
$orderIds = $this->getConnection()->fetchCol(
50+
$this->getConnection()->select()
51+
->from(['pbao' => $this->getTable('paypal_billing_agreement_order')], ['order_id'])
52+
->where(
53+
'pbao.agreement_id IN(?)',
54+
$agreementIds
55+
)
5656
);
57+
$orderCollection->getSelect()
58+
->where('main_table.entity_id IN (?)', $orderIds);
5759
return $this;
5860
}
5961
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Paypal\Test\Unit\Model\ResourceModel;
8+
9+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
10+
11+
/**
12+
* Class AgreementTest
13+
*/
14+
class AgreementTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement
18+
*/
19+
protected $agreementResource;
20+
21+
/**
22+
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
protected $connectionMock;
25+
26+
/**
27+
* @var \Magento\Framework\Data\Collection\AbstractDb|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $collectionMock;
30+
31+
/**
32+
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
protected $selectMock;
35+
36+
/**
37+
* @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
protected $resourceConnectionMock;
40+
41+
public function setUp()
42+
{
43+
$objectManager = new ObjectManagerHelper($this);
44+
$contextMock = $this->getMockBuilder('Magento\Framework\Model\ResourceModel\Db\Context')
45+
->disableOriginalConstructor()
46+
->getMock();
47+
$this->resourceConnectionMock = $this->getMock(
48+
'Magento\Framework\App\ResourceConnection',
49+
[
50+
'getConnection',
51+
'getTableName'
52+
],
53+
[],
54+
'',
55+
false
56+
);
57+
$this->collectionMock = $this->getMockBuilder('Magento\Framework\Data\Collection\AbstractDb')
58+
->disableOriginalConstructor()
59+
->setMethods(['getSelect'])
60+
->getMockForAbstractClass();
61+
$this->connectionMock = $this->getMock(
62+
'Magento\Framework\DB\Adapter\Pdo\Mysql',
63+
[],
64+
[],
65+
'',
66+
false
67+
);
68+
$this->selectMock = $this->getMock('Magento\Framework\DB\Select', [], [], '', false);
69+
$contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceConnectionMock);
70+
$this->agreementResource = $objectManager->getObject(
71+
'Magento\Paypal\Model\ResourceModel\Billing\Agreement',
72+
[
73+
'context' => $contextMock,
74+
]
75+
);
76+
}
77+
78+
public function testAddOrdersFilter()
79+
{
80+
$this->resourceConnectionMock->expects($this->exactly(2))
81+
->method('getConnection')
82+
->willReturn($this->connectionMock);
83+
$this->resourceConnectionMock->expects($this->once())
84+
->method('getTableName')
85+
->with('paypal_billing_agreement_order')
86+
->willReturn('pref_paypal_billing_agreement_order');
87+
$this->connectionMock->expects($this->once())
88+
->method('select')
89+
->willReturn($this->selectMock);
90+
$this->selectMock->expects($this->once())
91+
->method('from')
92+
->with(['pbao' => 'pref_paypal_billing_agreement_order'], ['order_id'], null)
93+
->willReturnSelf();
94+
$this->selectMock->expects($this->exactly(2))
95+
->method('where')
96+
->withConsecutive(
97+
['pbao.agreement_id IN(?)', [100]],
98+
['main_table.entity_id IN (?)', [500]]
99+
)
100+
->willReturnSelf();
101+
$this->connectionMock->expects($this->once())
102+
->method('fetchCol')
103+
->with($this->selectMock, [])
104+
->willReturn([500]);
105+
$this->collectionMock->expects($this->once())
106+
->method('getSelect')
107+
->willReturn($this->selectMock);
108+
$this->assertEquals(
109+
$this->agreementResource,
110+
$this->agreementResource->addOrdersFilter($this->collectionMock, 100)
111+
);
112+
}
113+
}

app/code/Magento/SalesSequence/Observer/SequenceCreatorObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function execute(EventObserver $observer)
5656
{
5757
$storeId = $observer->getData('store')->getId();
5858
foreach ($this->entityPool->getEntities() as $entityType) {
59-
$this->sequenceBuilder->setPrefix($this->sequenceConfig->get('prefix'))
59+
$this->sequenceBuilder->setPrefix($storeId)
6060
->setSuffix($this->sequenceConfig->get('suffix'))
6161
->setStartValue($this->sequenceConfig->get('startValue'))
6262
->setStoreId($storeId)

0 commit comments

Comments
 (0)