Skip to content

Commit 323187a

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-53342' into MAGETWO-53850
2 parents 5375ec1 + 8eb2152 commit 323187a

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Magento\ImportExport\Model\Import;
1717
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
1818
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
19-
use Magento\Catalog\Api\Data\ProductInterface;
2019
use Magento\ImportExport\Model\Import\Entity\AbstractEntity;
2120

2221
/**
@@ -104,6 +103,16 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
104103
*/
105104
const COL_CATEGORY = 'categories';
106105

106+
/**
107+
* Column product visibility.
108+
*/
109+
const COL_VISIBILITY = 'visibility';
110+
111+
/**
112+
* Column product visibility value.
113+
*/
114+
const COL_VALUE_VISIBILITY_NON_VISIBLE = 'Not Visible Individually';
115+
107116
/**
108117
* Column product sku.
109118
*/
@@ -2286,7 +2295,8 @@ public function validateRow(array $rowData, $rowNum)
22862295
}
22872296
// validate custom options
22882297
$this->getOptionEntity()->validateRow($rowData, $rowNum);
2289-
if (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME])) {
2298+
2299+
if ($this->isNeedToValidateUrlKey($rowData)) {
22902300
$urlKey = $this->getUrlKey($rowData);
22912301
$storeCodes = empty($rowData[self::COL_STORE_VIEW_CODE])
22922302
? array_flip($this->storeResolver->getStoreCodeToId())
@@ -2308,6 +2318,17 @@ public function validateRow(array $rowData, $rowNum)
23082318
return !$this->getErrorAggregator()->isRowInvalid($rowNum);
23092319
}
23102320

2321+
/**
2322+
* @param array $rowData
2323+
* @return bool
2324+
*/
2325+
private function isNeedToValidateUrlKey($rowData)
2326+
{
2327+
return (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME]))
2328+
&& (empty($rowData[self::COL_VISIBILITY])
2329+
|| $rowData[self::COL_VISIBILITY] !== self::COL_VALUE_VISIBILITY_NON_VISIBLE);
2330+
}
2331+
23112332
/**
23122333
* Prepare new SKU data
23132334
*

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/Group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected function generateProductUrls($websiteId, $originWebsiteId)
113113
$collection = $this->productFactory->create()
114114
->getCollection()
115115
->addCategoryIds()
116-
->addAttributeToSelect(['name', 'url_path', 'url_key'])
116+
->addAttributeToSelect(['name', 'url_path', 'url_key', 'visibility'])
117117
->addWebsiteFilter($websiteIds);
118118
foreach ($collection as $product) {
119119
/** @var \Magento\Catalog\Model\Product $product */

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected function generateProductUrls($websiteId, $originWebsiteId, $storeId)
100100
$collection = $this->productFactory->create()
101101
->getCollection()
102102
->addCategoryIds()
103-
->addAttributeToSelect(['name', 'url_path', 'url_key'])
103+
->addAttributeToSelect(['name', 'url_path', 'url_key', 'visibility'])
104104
->addWebsiteFilter($websiteIds);
105105
foreach ($collection as $product) {
106106
$product->setStoreId($storeId);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\CatalogUrlRewrite\Model\Product\AnchorUrlRewriteGenerator;
1313
use Magento\CatalogUrlRewrite\Service\V1\StoreViewService;
1414
use Magento\Store\Model\Store;
15+
use Magento\Catalog\Model\Product\Visibility;
1516

1617
/**
1718
* Class ProductUrlRewriteGenerator
@@ -98,6 +99,10 @@ private function getAnchorUrlRewriteGenerator()
9899
*/
99100
public function generate(Product $product)
100101
{
102+
if ($product->getVisibility() == Visibility::VISIBILITY_NOT_VISIBLE) {
103+
return [];
104+
}
105+
101106
$this->product = $product;
102107
$storeId = $this->product->getStoreId();
103108

app/code/Magento/CatalogUrlRewrite/Observer/AfterImportDataObserver.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class AfterImportDataObserver implements ObserverInterface
9393
'url_key',
9494
'url_path',
9595
'name',
96+
'visibility',
9697
];
9798

9899
/**
@@ -221,6 +222,9 @@ protected function setStoreToProduct(\Magento\Catalog\Model\Product $product, ar
221222
*/
222223
protected function addProductToImport($product, $storeId)
223224
{
225+
if ($product->getVisibility() == ImportProduct::COL_VALUE_VISIBILITY_NON_VISIBLE) {
226+
return $this;
227+
}
224228
if (!isset($this->products[$product->getId()])) {
225229
$this->products[$product->getId()] = [];
226230
}
@@ -321,6 +325,9 @@ protected function categoriesUrlRewriteGenerate()
321325
foreach ($productsByStores as $storeId => $product) {
322326
foreach ($this->categoryCache[$productId] as $categoryId) {
323327
$category = $this->import->getCategoryProcessor()->getCategoryById($categoryId);
328+
if ($category->getParentId() == Category::TREE_ROOT_ID) {
329+
continue;
330+
}
324331
$requestPath = $this->productUrlPathGenerator->getUrlPathWithSuffix($product, $storeId, $category);
325332
$urls[] = $this->urlRewriteFactory->create()
326333
->setEntityType(ProductUrlRewriteGenerator::ENTITY_TYPE)

app/code/Magento/CatalogUrlRewrite/Observer/ProductProcessUrlRewriteSavingObserver.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
4747
$product = $observer->getEvent()->getProduct();
4848

4949
$isChangedWebsites = $product->getIsChangedWebsites();
50-
if ($product->dataHasChangedFor('url_key') || $product->getIsChangedCategories() || $isChangedWebsites) {
50+
if ($product->dataHasChangedFor('url_key') || $product->getIsChangedCategories() || $isChangedWebsites
51+
|| $product->dataHasChangedFor('visibility')) {
5152
if ($isChangedWebsites) {
5253
$this->urlPersist->deleteByData([
5354
UrlRewrite::ENTITY_ID => $product->getId(),
5455
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
5556
]);
5657
}
57-
if ($product->getVisibility() != Visibility::VISIBILITY_NOT_VISIBLE) {
58+
if (!in_array($product->getOrigData('visibility'), $product->getVisibleInSiteVisibilities())) {
5859
$this->urlPersist->replace($this->productUrlRewriteGenerator->generate($product));
5960
}
6061
}

app/code/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function generateProductUrlRewrites(Category $category)
7070
$collection = $this->productCollectionFactory->create()
7171
->setStoreId($storeId)
7272
->addIdFilter($category->getAffectedProductIds())
73+
->addAttributeToSelect('visibility')
7374
->addAttributeToSelect('name')
7475
->addAttributeToSelect('url_key')
7576
->addAttributeToSelect('url_path');
@@ -104,6 +105,7 @@ public function getCategoryProductsUrlRewrites(Category $category, $storeId, $sa
104105
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
105106
$productCollection = $category->getProductCollection()
106107
->addAttributeToSelect('name')
108+
->addAttributeToSelect('visibility')
107109
->addAttributeToSelect('url_key')
108110
->addAttributeToSelect('url_path');
109111
$productUrls = [];

0 commit comments

Comments
 (0)