Skip to content

Commit fd1b971

Browse files
committed
changes in response to unit and static tests
1 parent 07b88ce commit fd1b971

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

app/code/Magento/GoogleAdwords/Helper/Data.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ public function getConversionValue()
277277
*
278278
* @return boolean
279279
*/
280-
public function getSendCurrency() {
280+
public function hasSendCurrency()
281+
{
281282
return $this->scopeConfig->isSetFlag(
282283
self::XML_PATH_SEND_CURRENCY,
283284
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
@@ -291,9 +292,9 @@ public function getSendCurrency() {
291292
*/
292293
public function getConversionValueCurrency()
293294
{
294-
if ($this->getSendCurrency()) {
295+
if ($this->hasSendCurrency()) {
295296
return (string) $this->_registry->registry(self::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME);
296-
}
297+
}
297298
return false;
298299
}
299300
}

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,14 @@ public function execute(\Magento\Framework\Event\Observer $observer)
6161
$conversionValue = 0;
6262
/** @var $order \Magento\Sales\Model\Order */
6363

64-
if($this->_helper->getSendCurrency()) {
65-
foreach ($this->_collection as $order) {
66-
$conversionValue += $order->getGrandTotal();
67-
$conversionCurrency = $order->getOrderCurrencyCode();
68-
}
69-
$this->_registry->register(
70-
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME,
71-
$conversionCurrency
72-
);
73-
} else {
74-
foreach ($this->_collection as $order) {
75-
$conversionValue += $order->getBaseGrandTotal();
76-
}
64+
foreach ($this->_collection as $order) {
65+
$conversionValue += ($this->_helper->hasSendCurrency()) ? $order->getGrandTotal() : $order->getBaseGrandTotal();
66+
$conversionCurrency = ($this->_helper->hasSendCurrency()) ? $order->getOrderCurrencyCode() : false;
7767
}
68+
$this->_registry->register(
69+
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME,
70+
$conversionCurrency
71+
);
7872
$this->_registry->register(
7973
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_REGISTRY_NAME,
8074
$conversionValue

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public function dataProviderForTestStoreConfig()
171171
['getConversionColor', \Magento\GoogleAdwords\Helper\Data::XML_PATH_CONVERSION_COLOR, 'ffffff'],
172172
['getConversionLabel', \Magento\GoogleAdwords\Helper\Data::XML_PATH_CONVERSION_LABEL, 'Label'],
173173
['getConversionValueType', \Magento\GoogleAdwords\Helper\Data::XML_PATH_CONVERSION_VALUE_TYPE, '1'],
174-
['getConversionValueConstant', \Magento\GoogleAdwords\Helper\Data::XML_PATH_CONVERSION_VALUE, '0']
174+
['getConversionValueConstant', \Magento\GoogleAdwords\Helper\Data::XML_PATH_CONVERSION_VALUE, '0'],
175+
['hasSendCurrency', \Magento\GoogleAdwords\Helper\Data::XML_PATH_SEND_CURRENCY, '1']
175176
];
176177
}
177178

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ public function testSetConversionValueWhenAdwordsActiveWithOrdersIds()
122122
{
123123
$ordersIds = [1, 2, 3];
124124
$conversionValue = 0;
125-
$conversionValueCurrency = 'USD';
125+
$conversionCurrency = 'USD';
126126
$this->_helperMock->expects($this->once())->method('isGoogleAdwordsActive')->will($this->returnValue(true));
127127
$this->_helperMock->expects($this->once())->method('isDynamicConversionValue')->will($this->returnValue(true));
128+
$this->_helperMock->expects($this->once())->method('hasSendCurrency')->will($this->returnValue(true));
128129
$this->_eventMock->expects($this->once())->method('getOrderIds')->will($this->returnValue($ordersIds));
129130
$this->_eventObserverMock->expects(
130131
$this->once()
@@ -158,7 +159,7 @@ public function testSetConversionValueWhenAdwordsActiveWithOrdersIds()
158159
'register'
159160
)->with(
160161
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME,
161-
$conversionValueCurrency
162+
$conversionCurrency
162163
);
163164

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

app/code/Magento/GoogleAdwords/view/frontend/templates/code.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var google_conversion_color = "<?= /* @escapeNotVerified */ $block->getHelper()->getConversionColor() ?>";
1919
var google_conversion_label = "<?= /* @escapeNotVerified */ $block->getHelper()->getConversionLabel() ?>";
2020
var google_conversion_value = <?= /* @escapeNotVerified */ $block->getHelper()->getConversionValue() ?>;
21-
<?php if($block->getHelper()->getSendCurrency() && $block->getHelper()->getConversionValueCurrency()): ?>
21+
<?php if($block->getHelper()->hasSendCurrency() && $block->getHelper()->getConversionValueCurrency()): ?>
2222
var google_conversion_currency = "<?= /* @escapeNotVerified */ $block->getHelper()->getConversionValueCurrency() ?>";
2323
<?php endif; ?>
2424
/* ]]> */

0 commit comments

Comments
 (0)