Skip to content

Commit ad9c8e3

Browse files
authored
Merge pull request magento#856 from magento-engcom/develop-prs
[EngCom] Public Pull Requests
2 parents e82ba2e + 011443f commit ad9c8e3

File tree

13 files changed

+442
-10
lines changed

13 files changed

+442
-10
lines changed

app/code/Magento/Catalog/Model/ProductWebsiteLinkRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function save(ProductWebsiteLinkInterface $productWebsiteLink)
3737
$product = $this->productRepository->get($productWebsiteLink->getSku());
3838
$product->setWebsiteIds(array_merge($product->getWebsiteIds(), [$productWebsiteLink->getWebsiteId()]));
3939
try {
40-
$product->save();
40+
$this->productRepository->save($product);
4141
} catch (\Exception $e) {
4242
throw new CouldNotSaveException(
4343
__(
@@ -68,7 +68,7 @@ public function deleteById($sku, $websiteId)
6868
$product->setWebsiteIds(array_diff($product->getWebsiteIds(), [$websiteId]));
6969

7070
try {
71-
$product->save();
71+
$this->productRepository->save($product);
7272
} catch (\Exception $e) {
7373
throw new CouldNotSaveException(
7474
__(

app/code/Magento/GoogleAnalytics/Block/Ga.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ public function getPageTrackingCode($accountId)
8080
$optPageURL = ", '" . $this->escapeHtmlAttr($pageName, false) . "'";
8181
}
8282

83+
$anonymizeIp = "";
84+
if ($this->_googleAnalyticsData->isAnonymizedIpActive()) {
85+
$anonymizeIp = "\nga('set', 'anonymizeIp', true);";
86+
}
87+
8388
return "\nga('create', '" . $this->escapeHtmlAttr($accountId, false)
84-
. ", 'auto');\nga('send', 'pageview'{$optPageURL});\n";
89+
. ", 'auto');{$anonymizeIp}\nga('send', 'pageview'{$optPageURL});\n";
8590
}
8691

8792
/**
@@ -105,6 +110,7 @@ public function getOrdersTrackingCode()
105110
$result = [];
106111

107112
$result[] = "ga('require', 'ec', 'ec.js');";
113+
108114
foreach ($collection as $order) {
109115
if ($order->getIsVirtual()) {
110116
$address = $order->getBillingAddress();

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
2323

2424
const XML_PATH_ACCOUNT = 'google/analytics/account';
2525

26+
const XML_PATH_ANONYMIZE = 'google/analytics/anonymize';
27+
2628
/**
2729
* Whether GA is ready to use
2830
*
@@ -34,4 +36,16 @@ public function isGoogleAnalyticsAvailable($store = null)
3436
$accountId = $this->scopeConfig->getValue(self::XML_PATH_ACCOUNT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
3537
return $accountId && $this->scopeConfig->isSetFlag(self::XML_PATH_ACTIVE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
3638
}
39+
40+
/**
41+
* Whether anonymized IPs are active
42+
*
43+
* @param null|string|bool|int|Store $store
44+
* @return bool
45+
*/
46+
public function isAnonymizedIpActive($store = null) {
47+
$anonymize = $this->scopeConfig->getValue(self::XML_PATH_ANONYMIZE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
48+
return $anonymize;
49+
}
50+
3751
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
<field id="*/*/active">1</field>
2424
</depends>
2525
</field>
26+
27+
<field id="anonymize" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
28+
<label>Anonymize IP</label>
29+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
30+
<depends>
31+
<field id="*/*/active">1</field>
32+
</depends>
33+
</field>
2634
</group>
2735
</section>
2836
</system>

app/code/Magento/PageCache/etc/varnish4.vcl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ sub vcl_recv {
2626
if (client.ip !~ purge) {
2727
return (synth(405, "Method not allowed"));
2828
}
29-
if (!req.http.X-Magento-Tags-Pattern) {
30-
return (synth(400, "X-Magento-Tags-Pattern header required"));
29+
# To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
30+
# has been added to the response in your backend server config. This is used, for example, by the
31+
# capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
32+
if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
33+
return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
34+
}
35+
if (req.http.X-Magento-Tags-Pattern) {
36+
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
37+
}
38+
if (req.http.X-Pool) {
39+
ban("obj.http.X-Pool ~ " + req.http.X-Pool);
3140
}
32-
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
3341
return (synth(200, "Purged"));
3442
}
3543

app/code/Magento/PageCache/etc/varnish5.vcl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@ sub vcl_recv {
2727
if (client.ip !~ purge) {
2828
return (synth(405, "Method not allowed"));
2929
}
30-
if (!req.http.X-Magento-Tags-Pattern) {
31-
return (synth(400, "X-Magento-Tags-Pattern header required"));
30+
# To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
31+
# has been added to the response in your backend server config. This is used, for example, by the
32+
# capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
33+
if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
34+
return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
35+
}
36+
if (req.http.X-Magento-Tags-Pattern) {
37+
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
38+
}
39+
if (req.http.X-Pool) {
40+
ban("obj.http.X-Pool ~ " + req.http.X-Pool);
3241
}
33-
ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
3442
return (synth(200, "Purged"));
3543
}
3644

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Store\Console\Command;
8+
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Command\Command;
12+
13+
/**
14+
* Class StoreListCommand
15+
*
16+
* Command for listing the configured stores
17+
*/
18+
class StoreListCommand extends Command
19+
{
20+
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
21+
private $storeManager;
22+
23+
public function __construct(
24+
\Magento\Store\Model\StoreManagerInterface $storeManager
25+
) {
26+
$this->storeManager = $storeManager;
27+
parent::__construct();
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
protected function configure()
34+
{
35+
$this->setName('store:list')
36+
->setDescription('Displays the list of stores');
37+
38+
parent::configure();
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
protected function execute(InputInterface $input, OutputInterface $output)
45+
{
46+
try {
47+
$table = $this->getHelperSet()->get('table');
48+
$table->setHeaders(['ID', 'Website ID', 'Group ID', 'Name', 'Code', 'Sort Order', 'Is Active']);
49+
50+
foreach ($this->storeManager->getStores(true, true) as $store) {
51+
$table->addRow([
52+
$store->getId(),
53+
$store->getWebsiteId(),
54+
$store->getStoreGroupId(),
55+
$store->getName(),
56+
$store->getCode(),
57+
$store->getData('sort_order'),
58+
$store->getData('is_active'),
59+
]);
60+
}
61+
62+
$table->render($output);
63+
64+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
65+
} catch (\Exception $e) {
66+
$output->writeln('<error>' . $e->getMessage() . '</error>');
67+
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
68+
$output->writeln($e->getTraceAsString());
69+
}
70+
71+
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
72+
}
73+
}
74+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Store\Console\Command;
8+
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Command\Command;
12+
13+
/**
14+
* Class WebsiteListCommand
15+
*
16+
* Command for listing the configured websites
17+
*/
18+
class WebsiteListCommand extends Command
19+
{
20+
/** @var \Magento\Store\Api\WebsiteManagementInterface $storeManager */
21+
private $manager;
22+
23+
public function __construct(
24+
\Magento\Store\Api\WebsiteRepositoryInterface $websiteManagement
25+
) {
26+
$this->manager = $websiteManagement;
27+
parent::__construct();
28+
}
29+
30+
/**
31+
* {@inheritdoc}
32+
*/
33+
protected function configure()
34+
{
35+
$this->setName('store:website:list')
36+
->setDescription('Displays the list of websites');
37+
38+
parent::configure();
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
protected function execute(InputInterface $input, OutputInterface $output)
45+
{
46+
try {
47+
$table = $this->getHelperSet()->get('table');
48+
$table->setHeaders(['ID', 'Default Group Id', 'Name', 'Code', 'Sort Order', 'Is Default']);
49+
50+
foreach ($this->manager->getList() as $website) {
51+
$table->addRow([
52+
$website->getId(),
53+
$website->getDefaultGroupId(),
54+
$website->getName(),
55+
$website->getCode(),
56+
$website->getData('sort_order'),
57+
$website->getData('is_default'),
58+
]);
59+
}
60+
61+
$table->render($output);
62+
63+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
64+
} catch (\Exception $e) {
65+
$output->writeln('<error>' . $e->getMessage() . '</error>');
66+
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
67+
$output->writeln($e->getTraceAsString());
68+
}
69+
70+
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
71+
}
72+
}
73+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Store\Test\Unit\Console\Command;
7+
8+
use Magento\Store\Console\Command\StoreListCommand;
9+
use Symfony\Component\Console\Tester\CommandTester;
10+
use Symfony\Component\Console\Helper\HelperSet;
11+
use Symfony\Component\Console\Helper\TableHelper;
12+
use Magento\Store\Model\Store;
13+
use Magento\Framework\Console\Cli;
14+
15+
/**
16+
* @package Magento\Store\Test\Unit\Console\Command
17+
*/
18+
class StoreListCommandTest extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* @var StoreListCommand
22+
*/
23+
private $command;
24+
25+
/**
26+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $storeManagerMock;
29+
30+
/**
31+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
32+
*/
33+
private $objectManager;
34+
35+
protected function setUp()
36+
{
37+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
38+
39+
$this->storeManagerMock = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);
40+
41+
$this->command = $this->objectManager->getObject(
42+
StoreListCommand::class,
43+
['storeManager' => $this->storeManagerMock]
44+
);
45+
46+
/** @var HelperSet $helperSet */
47+
$helperSet = $this->objectManager->getObject(
48+
HelperSet::class,
49+
['helpers' => [$this->objectManager->getObject(TableHelper::class)]]
50+
);
51+
52+
//Inject table helper for output
53+
$this->command->setHelperSet($helperSet);
54+
}
55+
56+
public function testExecuteExceptionNoVerbosity()
57+
{
58+
$this->storeManagerMock->expects($this->any())
59+
->method('getStores')
60+
->willThrowException(new \Exception("Dummy test exception"));
61+
62+
$tester = new CommandTester($this->command);
63+
$this->assertEquals(Cli::RETURN_FAILURE, $tester->execute([]));
64+
65+
$linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay()));
66+
$this->assertEquals('Dummy test exception', $linesOutput[0]);
67+
}
68+
69+
public function testExecute()
70+
{
71+
$storeData = [
72+
'store_id' => '999',
73+
'group_id' => '777',
74+
'website_id' => '888',
75+
'name' => 'unit test store',
76+
'code' => 'unit_test_store',
77+
'is_active' => '1',
78+
'sort_order' => '123',
79+
];
80+
81+
$stores = [
82+
$this->objectManager->getObject(Store::class)->setData($storeData),
83+
];
84+
85+
$this->storeManagerMock->expects($this->any())
86+
->method('getStores')
87+
->willReturn($stores);
88+
89+
$tester = new CommandTester($this->command);
90+
$this->assertEquals(Cli::RETURN_SUCCESS, $tester->execute([]));
91+
92+
$linesOutput = array_filter(explode(PHP_EOL, $tester->getDisplay()));
93+
$this->assertCount(5, $linesOutput, 'There should be 5 lines output. 3 Spacers, 1 header, 1 content.');
94+
95+
$this->assertEquals($linesOutput[0], $linesOutput[2], "Lines 0, 2, 4 should be spacer lines");
96+
$this->assertEquals($linesOutput[2], $linesOutput[4], "Lines 0, 2, 4 should be spacer lines");
97+
98+
$headerValues = array_values(array_filter(explode('|', $linesOutput[1])));
99+
//trim to remove the whitespace left from the exploding pipe separation
100+
$this->assertEquals('ID', trim($headerValues[0]));
101+
$this->assertEquals('Website ID', trim($headerValues[1]));
102+
$this->assertEquals('Group ID', trim($headerValues[2]));
103+
$this->assertEquals('Name', trim($headerValues[3]));
104+
$this->assertEquals('Code', trim($headerValues[4]));
105+
$this->assertEquals('Sort Order', trim($headerValues[5]));
106+
$this->assertEquals('Is Active', trim($headerValues[6]));
107+
108+
$storeValues = array_values(array_filter(explode('|', $linesOutput[3])));
109+
$this->assertEquals('999', trim($storeValues[0]));
110+
$this->assertEquals('888', trim($storeValues[1]));
111+
$this->assertEquals('777', trim($storeValues[2]));
112+
$this->assertEquals('unit test store', trim($storeValues[3]));
113+
$this->assertEquals('unit_test_store', trim($storeValues[4]));
114+
$this->assertEquals('123', trim($storeValues[5]));
115+
$this->assertEquals('1', trim($storeValues[6]));
116+
}
117+
}

0 commit comments

Comments
 (0)