Skip to content

Commit cf6dd9b

Browse files
committed
#10558: Option to send currency in Google Adwords when using dynamic value
- Fixes per failed tests
1 parent fd1b971 commit cf6dd9b

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

app/code/Magento/GoogleAdwords/Observer/SetConversionValueObserver.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5858
return $this;
5959
}
6060
$this->_collection->addFieldToFilter('entity_id', ['in' => $orderIds]);
61-
$conversionValue = 0;
62-
/** @var $order \Magento\Sales\Model\Order */
6361

62+
$conversionValue = 0;
63+
$conversionCurrency = false;
64+
$orderHasSendCurrency = $this->_helper->hasSendCurrency();
6465
foreach ($this->_collection as $order) {
65-
$conversionValue += ($this->_helper->hasSendCurrency()) ? $order->getGrandTotal() : $order->getBaseGrandTotal();
66-
$conversionCurrency = ($this->_helper->hasSendCurrency()) ? $order->getOrderCurrencyCode() : false;
66+
/** @var $order \Magento\Sales\Model\Order */
67+
$conversionValue += $orderHasSendCurrency ? $order->getGrandTotal() : $order->getBaseGrandTotal();
68+
$conversionCurrency = $orderHasSendCurrency ? $order->getOrderCurrencyCode() : false;
6769
}
6870
$this->_registry->register(
6971
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME,

app/code/Magento/GoogleAdwords/Test/Unit/Helper/DataTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public function dataProviderForTestStoreConfig()
172172
['getConversionLabel', \Magento\GoogleAdwords\Helper\Data::XML_PATH_CONVERSION_LABEL, 'Label'],
173173
['getConversionValueType', \Magento\GoogleAdwords\Helper\Data::XML_PATH_CONVERSION_VALUE_TYPE, '1'],
174174
['getConversionValueConstant', \Magento\GoogleAdwords\Helper\Data::XML_PATH_CONVERSION_VALUE, '0'],
175-
['hasSendCurrency', \Magento\GoogleAdwords\Helper\Data::XML_PATH_SEND_CURRENCY, '1']
176175
];
177176
}
178177

@@ -197,10 +196,16 @@ public function testGetStoreConfigValue($method, $xmlPath, $returnValue)
197196
$this->assertEquals($returnValue, $this->_helper->{$method}());
198197
}
199198

199+
public function testHasSendCurrency()
200+
{
201+
$this->_scopeConfigMock->expects($this->once())->method('isSetFlag')->willReturn(true);
202+
203+
$this->assertTrue($this->_helper->hasSendCurrency());
204+
}
205+
200206
public function testGetConversionValueDynamic()
201207
{
202208
$returnValue = 4.1;
203-
$returnValueCurrency = 'USD';
204209
$this->_scopeConfigMock->expects(
205210
$this->any()
206211
)->method(
@@ -219,6 +224,16 @@ public function testGetConversionValueDynamic()
219224
)->will(
220225
$this->returnValue($returnValue)
221226
);
227+
228+
229+
$this->assertEquals($returnValue, $this->_helper->getConversionValue());
230+
231+
}
232+
233+
public function testGetConversionValueCurrency()
234+
{
235+
$returnValueCurrency = 'USD';
236+
$this->_scopeConfigMock->expects($this->once())->method('isSetFlag')->willReturn(true);
222237
$this->_registryMock->expects(
223238
$this->once()
224239
)->method(
@@ -229,7 +244,6 @@ public function testGetConversionValueDynamic()
229244
$this->returnValue($returnValueCurrency)
230245
);
231246

232-
$this->assertEquals($returnValue, $this->_helper->getConversionValue());
233247
$this->assertEquals($returnValueCurrency, $this->_helper->getConversionValueCurrency());
234248
}
235249

app/code/Magento/GoogleAdwords/Test/Unit/Observer/SetConversionValueObserverTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\GoogleAdwords\Test\Unit\Observer;
77

8+
use Magento\GoogleAdwords\Helper\Data;
9+
810
class SetConversionValueObserverTest extends \PHPUnit\Framework\TestCase
911
{
1012
/**
@@ -135,7 +137,10 @@ public function testSetConversionValueWhenAdwordsActiveWithOrdersIds()
135137
$this->returnValue($this->_eventMock)
136138
);
137139

138-
$iteratorMock = $this->createMock(\Iterator::class);
140+
$orderMock = $this->createMock(\Magento\Sales\Api\Data\OrderInterface::class);
141+
$orderMock->expects($this->once())->method('getOrderCurrencyCode')->willReturn($conversionCurrency);
142+
143+
$iteratorMock = new \ArrayIterator([$orderMock]);
139144
$this->_collectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iteratorMock));
140145
$this->_collectionMock->expects(
141146
$this->once()
@@ -146,20 +151,18 @@ public function testSetConversionValueWhenAdwordsActiveWithOrdersIds()
146151
['in' => $ordersIds]
147152
);
148153
$this->_registryMock->expects(
149-
$this->once()
154+
$this->atLeastOnce()
150155
)->method(
151156
'register'
152-
)->with(
153-
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_REGISTRY_NAME,
154-
$conversionValue
155-
);
156-
$this->_registryMock->expects(
157-
$this->once()
158-
)->method(
159-
'register'
160-
)->with(
161-
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME,
162-
$conversionCurrency
157+
)->withConsecutive(
158+
[
159+
Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME,
160+
$conversionCurrency
161+
],
162+
[
163+
Data::CONVERSION_VALUE_REGISTRY_NAME,
164+
$conversionValue,
165+
]
163166
);
164167

165168
$this->assertSame($this->_model, $this->_model->execute($this->_eventObserverMock));

0 commit comments

Comments
 (0)