Skip to content

Commit edc2bed

Browse files
author
Vladyslav Shcherbyna
committed
Merge branch 'develop' of github.corp.ebay.com:magento2/magento2ce into MAGETWO-33535
2 parents 142c88a + 9523463 commit edc2bed

File tree

18 files changed

+284
-20
lines changed

18 files changed

+284
-20
lines changed

app/code/Magento/CatalogUrlRewrite/Model/ProductUrlPathGenerator.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\CatalogUrlRewrite\Model;
77

8+
use Magento\Store\Model\Store;
9+
810
class ProductUrlPathGenerator
911
{
1012
const XML_PATH_PRODUCT_URL_SUFFIX = 'catalog/seo/product_url_suffix';
@@ -25,19 +27,25 @@ class ProductUrlPathGenerator
2527
/** @var \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator */
2628
protected $categoryUrlPathGenerator;
2729

30+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface */
31+
protected $productRepository;
32+
2833
/**
2934
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
3035
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
3136
* @param CategoryUrlPathGenerator $categoryUrlPathGenerator
37+
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
3238
*/
3339
public function __construct(
3440
\Magento\Store\Model\StoreManagerInterface $storeManager,
3541
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
36-
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator
42+
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator,
43+
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
3744
) {
3845
$this->storeManager = $storeManager;
3946
$this->scopeConfig = $scopeConfig;
4047
$this->categoryUrlPathGenerator = $categoryUrlPathGenerator;
48+
$this->productRepository = $productRepository;
4149
}
4250

4351
/**
@@ -52,12 +60,28 @@ public function getUrlPath($product, $category = null)
5260
{
5361
$path = $product->getData('url_path');
5462
if ($path === null) {
55-
$path = $this->generateUrlKey($product);
63+
$path = $product->getUrlKey() === false
64+
? $this->prepareProductDefaultUrlKey($product)
65+
: $this->prepareProductUrlKey($product);
5666
}
57-
return $category === null ? $path
67+
return $category === null
68+
? $path
5869
: $this->categoryUrlPathGenerator->getUrlPath($category) . '/' . $path;
5970
}
6071

72+
/**
73+
* Prepare URL Key with stored product data (fallback for "Use Default Value" logic)
74+
*
75+
* @param \Magento\Catalog\Model\Product $product
76+
* @return string
77+
*/
78+
protected function prepareProductDefaultUrlKey(\Magento\Catalog\Model\Product $product)
79+
{
80+
$storedProduct = $this->productRepository->getById($product->getId());
81+
$storedUrlKey = $storedProduct->getUrlKey();
82+
return $storedUrlKey ?: $product->formatUrlKey($storedProduct->getName());
83+
}
84+
6185
/**
6286
* Retrieve Product Url path with suffix
6387
*
@@ -91,6 +115,17 @@ public function getCanonicalUrlPath($product, $category = null)
91115
* @return string
92116
*/
93117
public function generateUrlKey($product)
118+
{
119+
return $product->getUrlKey() === false ? false : $this->prepareProductUrlKey($product);
120+
}
121+
122+
/**
123+
* Prepare url key for product
124+
*
125+
* @param \Magento\Catalog\Model\Product $product
126+
* @return string
127+
*/
128+
protected function prepareProductUrlKey(\Magento\Catalog\Model\Product $product)
94129
{
95130
$urlKey = $product->getUrlKey();
96131
return $product->formatUrlKey($urlKey === '' || $urlKey === null ? $product->getName() : $urlKey);

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ProductUrlPathGeneratorTest.php

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
*/
66
namespace Magento\CatalogUrlRewrite\Test\Unit\Model;
77

8-
use \Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
9-
10-
use Magento\Store\Model\ScopeInterface;
8+
use Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator;
119
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10+
use Magento\Store\Model\ScopeInterface;
1211

1312
class ProductUrlPathGeneratorTest extends \PHPUnit_Framework_TestCase
1413
{
@@ -27,13 +26,26 @@ class ProductUrlPathGeneratorTest extends \PHPUnit_Framework_TestCase
2726
/** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */
2827
protected $product;
2928

29+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject */
30+
protected $productRepository;
31+
3032
/** @var \Magento\Catalog\Model\Category|\PHPUnit_Framework_MockObject_MockObject */
3133
protected $category;
3234

3335
protected function setUp()
3436
{
3537
$this->category = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false);
36-
$productMethods = ['__wakeup', 'getData', 'getUrlKey', 'getName', 'formatUrlKey', 'getId'];
38+
$productMethods = [
39+
'__wakeup',
40+
'getData',
41+
'getUrlKey',
42+
'getName',
43+
'formatUrlKey',
44+
'getId',
45+
'load',
46+
'setStoreId',
47+
];
48+
3749
$this->product = $this->getMock('Magento\Catalog\Model\Product', $productMethods, [], '', false);
3850
$this->storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface');
3951
$this->scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
@@ -44,13 +56,16 @@ protected function setUp()
4456
'',
4557
false
4658
);
59+
$this->productRepository = $this->getMock('Magento\Catalog\Api\ProductRepositoryInterface');
60+
$this->productRepository->expects($this->any())->method('getById')->willReturn($this->product);
4761

4862
$this->productUrlPathGenerator = (new ObjectManager($this))->getObject(
4963
'Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator',
5064
[
5165
'storeManager' => $this->storeManager,
5266
'scopeConfig' => $this->scopeConfig,
53-
'categoryUrlPathGenerator' => $this->categoryUrlPathGenerator
67+
'categoryUrlPathGenerator' => $this->categoryUrlPathGenerator,
68+
'productRepository' => $this->productRepository,
5469
]
5570
);
5671
}
@@ -64,6 +79,7 @@ public function getUrlPathDataProvider()
6479
'path based on url key' => ['url-key', null, 'url-key'],
6580
'path based on product name 1' => ['', 'product-name', 'product-name'],
6681
'path based on product name 2' => [null, 'product-name', 'product-name'],
82+
'path based on product name 3' => [false, 'product-name', 'product-name']
6783
];
6884
}
6985

@@ -77,13 +93,34 @@ public function testGenerateUrlPath($urlKey, $productName, $result)
7793
{
7894
$this->product->expects($this->once())->method('getData')->with('url_path')
7995
->will($this->returnValue(null));
80-
$this->product->expects($this->once())->method('getUrlKey')->will($this->returnValue($urlKey));
96+
$this->product->expects($this->any())->method('getUrlKey')->will($this->returnValue($urlKey));
8197
$this->product->expects($this->any())->method('getName')->will($this->returnValue($productName));
8298
$this->product->expects($this->once())->method('formatUrlKey')->will($this->returnArgument(0));
8399

84100
$this->assertEquals($result, $this->productUrlPathGenerator->getUrlPath($this->product, null));
85101
}
86102

103+
/**
104+
* @param $productUrlKey
105+
* @param $expectedUrlKey
106+
*
107+
* @dataProvider generateUrlKeyDataProvider
108+
*/
109+
public function testGenerateUrlKey($productUrlKey, $expectedUrlKey)
110+
{
111+
$this->product->expects($this->any())->method('getUrlKey')->will($this->returnValue($productUrlKey));
112+
$this->product->expects($this->any())->method('formatUrlKey')->will($this->returnValue($productUrlKey));
113+
$this->assertEquals($expectedUrlKey, $this->productUrlPathGenerator->generateUrlKey($this->product));
114+
}
115+
116+
public function generateUrlKeyDataProvider()
117+
{
118+
return [
119+
'URL Key use default' => [false, false],
120+
'URL Key empty' => ['product-url', 'product-url'],
121+
];
122+
}
123+
87124
public function testGetUrlPath()
88125
{
89126
$this->product->expects($this->once())->method('getData')->with('url_path')
@@ -93,6 +130,29 @@ public function testGetUrlPath()
93130
$this->assertEquals('url-path', $this->productUrlPathGenerator->getUrlPath($this->product, null));
94131
}
95132

133+
/**
134+
*
135+
* @dataProvider getUrlPathDefaultUrlKeyDataProvider
136+
*/
137+
public function testGetUrlPathDefaultUrlKey($storedUrlKey, $productName, $expectedUrlKey)
138+
{
139+
$this->product->expects($this->once())->method('getData')->with('url_path')
140+
->will($this->returnValue(null));
141+
$this->product->expects($this->any())->method('getUrlKey')->willReturnOnConsecutiveCalls(false, $storedUrlKey);
142+
$this->product->expects($this->any())->method('getName')->will($this->returnValue($productName));
143+
$this->product->expects($this->any())->method('formatUrlKey')->will($this->returnArgument(0));
144+
$this->assertEquals($expectedUrlKey, $this->productUrlPathGenerator->getUrlPath($this->product, null));
145+
}
146+
147+
public function getUrlPathDefaultUrlKeyDataProvider()
148+
{
149+
return [
150+
['default-store-view-url-key', null, 'default-store-view-url-key'],
151+
[false, 'default-store-view-product-name', 'default-store-view-product-name']
152+
];
153+
154+
}
155+
96156
public function testGetUrlPathWithCategory()
97157
{
98158
$this->product->expects($this->once())->method('getData')->with('url_path')
@@ -124,7 +184,7 @@ public function testGetUrlPathWithSuffix()
124184
);
125185
}
126186

127-
public function testGetUrlPathWithSuffixAndCategoryAnsStore()
187+
public function testGetUrlPathWithSuffixAndCategoryAndStore()
128188
{
129189
$storeId = 1;
130190
$this->product->expects($this->once())->method('getData')->with('url_path')

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend;
1414
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
1515
use Magento\Framework\App\Config\Element;
16-
use Magento\Framework\Model\AbstractModel;
1716
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Framework\Model\AbstractModel;
1818
use Magento\Framework\Model\Resource\Db\ObjectRelationProcessor;
1919
use Magento\Framework\Model\Resource\Db\TransactionManagerInterface;
2020

setup/pub/magento/setup/customize-your-store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ angular.module('customize-your-store', ['ngStorage', 'ngSanitize'])
1111
currency: 'USD',
1212
language: 'en_US',
1313
useSampleData: false,
14+
cleanUpDatabase: false,
1415
loadedAllModules: false,
1516
showModulesControl: false,
1617
selectAll: true,

setup/pub/magento/setup/install.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ angular.module('install', ['ngStorage'])
1010
$scope.isInProgress = false;
1111
$scope.isConsole = false;
1212
$scope.isDisabled = false;
13+
$scope.isSampleDataError = false;
14+
$scope.isShowCleanUpBox = false;
1315
$scope.toggleConsole = function () {
1416
$scope.isConsole = $scope.isConsole === false;
1517
};
@@ -34,6 +36,9 @@ angular.module('install', ['ngStorage'])
3436
$scope.progressText = response.data.progress + '%';
3537
} else {
3638
$scope.displayFailure();
39+
if (response.data.isSampleDataError) {
40+
$scope.isSampleDataError = true;
41+
}
3742
}
3843
if ($scope.isInProgress) {
3944
$timeout(function() {
@@ -43,7 +48,24 @@ angular.module('install', ['ngStorage'])
4348
});
4449
};
4550

51+
$scope.showCleanUpBox = function() {
52+
$scope.isShowCleanUpBox = true;
53+
};
54+
$scope.hideCleanUpBox = function() {
55+
$scope.isShowCleanUpBox = false;
56+
};
57+
$scope.startCleanup = function(performClenup) {
58+
$scope.hideCleanUpBox();
59+
$scope.isSampleDataError = false;
60+
$localStorage.store.cleanUpDatabase = performClenup;
61+
$scope.start();
62+
};
63+
4664
$scope.start = function () {
65+
if ($scope.isSampleDataError) {
66+
$scope.showCleanUpBox();
67+
return;
68+
}
4769
var data = {
4870
'db': $localStorage.db,
4971
'admin': $localStorage.admin,
@@ -60,6 +82,9 @@ angular.module('install', ['ngStorage'])
6082
$scope.nextState();
6183
} else {
6284
$scope.displayFailure();
85+
if (response.isSampleDataError) {
86+
$scope.isSampleDataError = true;
87+
}
6388
}
6489
});
6590
progress.get(function () {

setup/pub/styles/setup.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

setup/src/Magento/Setup/Controller/CustomizeYourStore.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public function indexAction()
4343
'currency' => $this->list->getCurrencyList(),
4444
'language' => $this->list->getLocaleList(),
4545
'isSampledataEnabled' => $this->sampleData->isDeployed(),
46+
'isSampleDataInstalled' => $this->sampleData->isInstalledSuccessfully(),
47+
'isSampleDataErrorInstallation' => $this->sampleData->isInstallationError()
4648
]);
4749
$view->setTerminal(true);
4850
return $view;

setup/src/Magento/Setup/Controller/Install.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public function startAction()
9494
} catch (\Exception $e) {
9595
$this->log->logError($e);
9696
$json->setVariable('success', false);
97+
if ($e instanceof \Magento\Setup\SampleDataException) {
98+
$json->setVariable('isSampleDataError', true);
99+
}
97100
}
98101
return $json;
99102
}
@@ -107,15 +110,19 @@ public function progressAction()
107110
{
108111
$percent = 0;
109112
$success = false;
113+
$json = new JsonModel();
110114
try {
111115
$progress = $this->progressFactory->createFromLog($this->log);
112116
$percent = sprintf('%d', $progress->getRatio() * 100);
113117
$success = true;
114118
$contents = $this->log->get();
115119
} catch (\Exception $e) {
116120
$contents = [(string)$e];
121+
if ($e instanceof \Magento\Setup\SampleDataException) {
122+
$json->setVariable('isSampleDataError', true);
123+
}
117124
}
118-
return new JsonModel(['progress' => $percent, 'success' => $success, 'console' => $contents]);
125+
return $json->setVariables(['progress' => $percent, 'success' => $success, 'console' => $contents]);
119126
}
120127

121128
/**
@@ -178,6 +185,8 @@ private function importUserConfigForm()
178185
? $source['store']['currency'] : '';
179186
$result[InstallCommand::INPUT_KEY_USE_SAMPLE_DATA] = isset($source['store']['useSampleData'])
180187
? $source['store']['useSampleData'] : '';
188+
$result[InstallCommand::INPUT_KEY_CLEANUP_DB] = isset($source['store']['cleanUpDatabase'])
189+
? $source['store']['cleanUpDatabase'] : '';
181190
return $result;
182191
}
183192

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,14 +1102,22 @@ private function assertDbAccessible()
11021102
*
11031103
* @param array $request
11041104
* @return void
1105+
* @throws \Magento\Setup\SampleDataException
11051106
*
11061107
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback.
11071108
*/
11081109
private function installSampleData($request)
11091110
{
1110-
$userName = isset($request[AdminAccount::KEY_USER]) ? $request[AdminAccount::KEY_USER] : '';
1111-
$this->objectManagerProvider->reset();
1112-
$this->sampleData->install($this->objectManagerProvider->get(), $this->log, $userName);
1111+
try {
1112+
$userName = isset($request[AdminAccount::KEY_USER]) ? $request[AdminAccount::KEY_USER] : '';
1113+
$this->objectManagerProvider->reset();
1114+
$this->sampleData->install($this->objectManagerProvider->get(), $this->log, $userName);
1115+
} catch (\Exception $e) {
1116+
throw new \Magento\Setup\SampleDataException(
1117+
"Error during sample data installation: {$e->getMessage()}",
1118+
$e->getCode()
1119+
);
1120+
}
11131121
}
11141122

11151123
/**

0 commit comments

Comments
 (0)