Skip to content

Commit e7d2f8f

Browse files
Merge pull request #1428 from magento-engcom/develop-prs
[EngCom] Public Pull Requests - MAGETWO-71744: Fix issue 10032 #10593 - MAGETWO-71642: Option to send currency in Google Adwords when using dynamic value #10558 - MAGETWO-70866: Enabling the use of looping (for in ..) into Template.php #9401
2 parents d48faba + 3465b94 commit e7d2f8f

File tree

12 files changed

+561
-58
lines changed

12 files changed

+561
-58
lines changed

app/code/Magento/Backup/Model/BackupFactory.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,20 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan
3838
*/
3939
public function create($timestamp, $type)
4040
{
41-
$backupId = $timestamp . '_' . $type;
4241
$fsCollection = $this->_objectManager->get(\Magento\Backup\Model\Fs\Collection::class);
4342
$backupInstance = $this->_objectManager->get(\Magento\Backup\Model\Backup::class);
43+
4444
foreach ($fsCollection as $backup) {
45-
if ($backup->getId() == $backupId) {
46-
$backupInstance->setType(
47-
$backup->getType()
48-
)->setTime(
49-
$backup->getTime()
50-
)->setName(
51-
$backup->getName()
52-
)->setPath(
53-
$backup->getPath()
54-
);
45+
if ($backup->getTime() === (int) $timestamp && $backup->getType() === $type) {
46+
$backupInstance->setData(['id' => $backup->getId()])
47+
->setType($backup->getType())
48+
->setTime($backup->getTime())
49+
->setName($backup->getName())
50+
->setPath($backup->getPath());
5551
break;
5652
}
5753
}
54+
5855
return $backupInstance;
5956
}
6057
}

app/code/Magento/Backup/Test/Unit/Model/BackupFactoryTest.php

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,42 +77,29 @@ protected function setUp()
7777

7878
public function testCreate()
7979
{
80-
$this->_backupModel->expects(
81-
$this->once()
82-
)->method(
83-
'setType'
84-
)->with(
85-
$this->_data['type']
86-
)->will(
87-
$this->returnSelf()
88-
);
89-
$this->_backupModel->expects(
90-
$this->once()
91-
)->method(
92-
'setTime'
93-
)->with(
94-
$this->_data['time']
95-
)->will(
96-
$this->returnSelf()
97-
);
98-
$this->_backupModel->expects(
99-
$this->once()
100-
)->method(
101-
'setName'
102-
)->with(
103-
$this->_data['name']
104-
)->will(
105-
$this->returnSelf()
106-
);
107-
$this->_backupModel->expects(
108-
$this->once()
109-
)->method(
110-
'setPath'
111-
)->with(
112-
$this->_data['path']
113-
)->will(
114-
$this->returnSelf()
115-
);
80+
$this->_backupModel->expects($this->once())
81+
->method('setType')
82+
->with($this->_data['type'])
83+
->will($this->returnSelf());
84+
85+
$this->_backupModel->expects($this->once())
86+
->method('setTime')
87+
->with($this->_data['time'])
88+
->will($this->returnSelf());
89+
90+
$this->_backupModel->expects($this->once())
91+
->method('setName')
92+
->with($this->_data['name'])
93+
->will($this->returnSelf());
94+
95+
$this->_backupModel->expects($this->once())
96+
->method('setPath')
97+
->with($this->_data['path'])
98+
->will($this->returnSelf());
99+
100+
$this->_backupModel->expects($this->once())
101+
->method('setData')
102+
->will($this->returnSelf());
116103

117104
$this->_instance->create('1385661590', 'snapshot');
118105
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
3535
*/
3636
const CONVERSION_VALUE_REGISTRY_NAME = 'google_adwords_conversion_value';
3737

38+
/**
39+
* Google AdWords registry name for conversion value currency
40+
*/
41+
const CONVERSION_VALUE_CURRENCY_REGISTRY_NAME = 'google_adwords_conversion_value_currency';
42+
3843
/**
3944
* Default value for conversion value
4045
*/
@@ -59,6 +64,11 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
5964

6065
const XML_PATH_CONVERSION_VALUE = 'google/adwords/conversion_value';
6166

67+
/**
68+
* Google Adwords send order conversion value currency when using dynamic value
69+
*/
70+
const XML_PATH_SEND_CURRENCY = 'google/adwords/send_currency';
71+
6272
/**#@-*/
6373

6474
/**#@+
@@ -264,4 +274,30 @@ public function getConversionValue()
264274
}
265275
return empty($conversionValue) ? self::CONVERSION_VALUE_DEFAULT : $conversionValue;
266276
}
277+
278+
/**
279+
* Get send order currency to Google Adwords
280+
*
281+
* @return boolean
282+
*/
283+
public function hasSendConversionValueCurrency()
284+
{
285+
return $this->scopeConfig->isSetFlag(
286+
self::XML_PATH_SEND_CURRENCY,
287+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
288+
);
289+
}
290+
291+
/**
292+
* Get Google AdWords conversion value currency
293+
*
294+
* @return string|false
295+
*/
296+
public function getConversionValueCurrency()
297+
{
298+
if ($this->hasSendConversionValueCurrency()) {
299+
return (string) $this->_registry->registry(self::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME);
300+
}
301+
return false;
302+
}
267303
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,19 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5858
return $this;
5959
}
6060
$this->_collection->addFieldToFilter('entity_id', ['in' => $orderIds]);
61+
6162
$conversionValue = 0;
62-
/** @var $order \Magento\Sales\Model\Order */
63+
$conversionCurrency = false;
64+
$sendOrderCurrency = $this->_helper->hasSendConversionValueCurrency();
6365
foreach ($this->_collection as $order) {
64-
$conversionValue += $order->getBaseGrandTotal();
66+
/** @var $order \Magento\Sales\Api\Data\OrderInterface */
67+
$conversionValue += $sendOrderCurrency ? $order->getGrandTotal() : $order->getBaseGrandTotal();
68+
$conversionCurrency = $sendOrderCurrency ? $order->getOrderCurrencyCode() : false;
6569
}
70+
$this->_registry->register(
71+
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME,
72+
$conversionCurrency
73+
);
6674
$this->_registry->register(
6775
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_REGISTRY_NAME,
6876
$conversionValue

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ 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'],
175175
];
176176
}
177177

@@ -196,6 +196,13 @@ public function testGetStoreConfigValue($method, $xmlPath, $returnValue)
196196
$this->assertEquals($returnValue, $this->_helper->{$method}());
197197
}
198198

199+
public function testHasSendConversionValueCurrency()
200+
{
201+
$this->_scopeConfigMock->expects($this->once())->method('isSetFlag')->willReturn(true);
202+
203+
$this->assertTrue($this->_helper->hasSendConversionValueCurrency());
204+
}
205+
199206
public function testGetConversionValueDynamic()
200207
{
201208
$returnValue = 4.1;
@@ -221,6 +228,23 @@ public function testGetConversionValueDynamic()
221228
$this->assertEquals($returnValue, $this->_helper->getConversionValue());
222229
}
223230

231+
public function testGetConversionValueCurrency()
232+
{
233+
$returnValueCurrency = 'USD';
234+
$this->_scopeConfigMock->expects($this->once())->method('isSetFlag')->willReturn(true);
235+
$this->_registryMock->expects(
236+
$this->once()
237+
)->method(
238+
'registry'
239+
)->with(
240+
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME
241+
)->will(
242+
$this->returnValue($returnValueCurrency)
243+
);
244+
245+
$this->assertEquals($returnValueCurrency, $this->_helper->getConversionValueCurrency());
246+
}
247+
224248
/**
225249
* @return array
226250
*/

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

Lines changed: 19 additions & 5 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
/**
@@ -122,8 +124,11 @@ public function testSetConversionValueWhenAdwordsActiveWithOrdersIds()
122124
{
123125
$ordersIds = [1, 2, 3];
124126
$conversionValue = 0;
127+
$conversionCurrency = 'USD';
125128
$this->_helperMock->expects($this->once())->method('isGoogleAdwordsActive')->will($this->returnValue(true));
126129
$this->_helperMock->expects($this->once())->method('isDynamicConversionValue')->will($this->returnValue(true));
130+
$this->_helperMock->expects($this->once())->method('hasSendConversionValueCurrency')
131+
->will($this->returnValue(true));
127132
$this->_eventMock->expects($this->once())->method('getOrderIds')->will($this->returnValue($ordersIds));
128133
$this->_eventObserverMock->expects(
129134
$this->once()
@@ -133,7 +138,10 @@ public function testSetConversionValueWhenAdwordsActiveWithOrdersIds()
133138
$this->returnValue($this->_eventMock)
134139
);
135140

136-
$iteratorMock = $this->createMock(\Iterator::class);
141+
$orderMock = $this->createMock(\Magento\Sales\Api\Data\OrderInterface::class);
142+
$orderMock->expects($this->once())->method('getOrderCurrencyCode')->willReturn($conversionCurrency);
143+
144+
$iteratorMock = new \ArrayIterator([$orderMock]);
137145
$this->_collectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iteratorMock));
138146
$this->_collectionMock->expects(
139147
$this->once()
@@ -144,12 +152,18 @@ public function testSetConversionValueWhenAdwordsActiveWithOrdersIds()
144152
['in' => $ordersIds]
145153
);
146154
$this->_registryMock->expects(
147-
$this->once()
155+
$this->atLeastOnce()
148156
)->method(
149157
'register'
150-
)->with(
151-
\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_REGISTRY_NAME,
152-
$conversionValue
158+
)->withConsecutive(
159+
[
160+
Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME,
161+
$conversionCurrency
162+
],
163+
[
164+
Data::CONVERSION_VALUE_REGISTRY_NAME,
165+
$conversionValue,
166+
]
153167
);
154168

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

app/code/Magento/GoogleAdwords/etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
<field id="*/*/conversion_value_type">0</field>
6262
</depends>
6363
</field>
64+
<field id="send_currency" translate="label" type="select" sortOrder="18" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
65+
<label>Send Order Currency</label>
66+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
67+
<depends>
68+
<field id="*/*/active">1</field>
69+
<field id="*/*/conversion_value_type">1</field>
70+
</depends>
71+
</field>
6472
</group>
6573
</section>
6674
</system>

app/code/Magento/GoogleAdwords/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<conversion_color>FFFFFF</conversion_color>
1616
<conversion_value_type>1</conversion_value_type>
1717
<conversion_value>0</conversion_value>
18+
<send_currency>0</send_currency>
1819
<languages>
1920
<ar>ar</ar>
2021
<bg>bg</bg>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
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()->hasSendConversionValueCurrency() && $block->getHelper()->getConversionValueCurrency()): ?>
22+
var google_conversion_currency = "<?= /* @escapeNotVerified */ $block->getHelper()->getConversionValueCurrency() ?>";
23+
<?php endif; ?>
2124
/* ]]> */
2225
</script>
2326
<script src="<?= /* @escapeNotVerified */ $block->getHelper()->getConversionJsSrc() ?>"></script>

0 commit comments

Comments
 (0)