Skip to content

Commit

Permalink
MAGETWO-69808: Merge branch 'develop' of github.com:magento/magento2c…
Browse files Browse the repository at this point in the history
…e into MAGETWO-69808-PR-9905
  • Loading branch information
ishakhsuvarov committed Jun 13, 2017
2 parents 13bfcd2 + 8545fd8 commit 980bd1f
Show file tree
Hide file tree
Showing 46 changed files with 741 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
data-validate="{required:true}"
value=""
placeholder="<?php /* @escapeNotVerified */ echo __('password') ?>"
autocomplete="off"
autocomplete="new-password"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<fieldset class="admin__fieldset password-box-container">
<div class="admin__field field _required">
<label for="password" class="admin__field-label"><span><?php /* @escapeNotVerified */ echo __('User Password')?></span></label>
<div class="admin__field-control"><input type="password" name="password" id="password" class="admin__control-text required-entry" autocomplete="off"></div>
<div class="admin__field-control"><input type="password" name="password" id="password" class="admin__control-text required-entry" autocomplete="new-password"></div>
</div>

<div class="admin__field field maintenance-checkbox-container">
Expand Down Expand Up @@ -119,7 +119,7 @@
<span><?php /* @escapeNotVerified */ echo __('FTP Password') ?></span>
</label>
<div class="admin__field-control">
<input type="password" class="admin__control-text" name="ftp_pass" id="ftp_pass" autocomplete="off">
<input type="password" class="admin__control-text" name="ftp_pass" id="ftp_pass" autocomplete="new-password">
</div>
</div>
<div class="admin__field field">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<formElements>
<fileUploader>
<settings>
<allowedExtensions>jpg jpeg gif png svg</allowedExtensions>
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
<maxFileSize>2097152</maxFileSize>
<uploaderConfig>
<param xsi:type="string" name="url">theme/design_config_fileUploader/save</param>
Expand Down Expand Up @@ -87,7 +87,7 @@
<formElements>
<fileUploader>
<settings>
<allowedExtensions>jpg jpeg gif png svg</allowedExtensions>
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
<maxFileSize>2097152</maxFileSize>
<uploaderConfig>
<param xsi:type="string" name="url">theme/design_config_fileUploader/save</param>
Expand Down Expand Up @@ -147,7 +147,7 @@
<formElements>
<fileUploader>
<settings>
<allowedExtensions>jpg jpeg gif png svg</allowedExtensions>
<allowedExtensions>jpg jpeg gif png</allowedExtensions>
<maxFileSize>2097152</maxFileSize>
<uploaderConfig>
<param xsi:type="string" name="url">theme/design_config_fileUploader/save</param>
Expand Down
16 changes: 8 additions & 8 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,15 +1228,15 @@ protected function _saveLinks()
'linked_product_id' => $linkedId,
'link_type_id' => $linkId,
];
if (!empty($linkPositions[$linkedKey])) {
$positionRows[] = [
'link_id' => $productLinkKeys[$linkKey],
'product_link_attribute_id' => $positionAttrId[$linkId],
'value' => $linkPositions[$linkedKey],
];
}
$nextLinkId++;
}
if (!empty($linkPositions[$linkedKey])) {
$positionRows[] = [
'link_id' => $productLinkKeys[$linkKey],
'product_link_attribute_id' => $positionAttrId[$linkId],
'value' => $linkPositions[$linkedKey],
];
}
$nextLinkId++;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
}

/**
* Generate list based on categories
* Generate product rewrites for anchor categories
*
* @param int $storeId
* @param Product $product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(ProductUrlPathGenerator $productUrlPathGenerator, Ur
}

/**
* Generate list based on store view
* Generate product rewrites without categories
*
* @param int $storeId
* @param Product $product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(ProductUrlPathGenerator $productUrlPathGenerator, Ur
}

/**
* Generate list based on categories
* Generate product rewrites with categories
*
* @param int $storeId
* @param Product $product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\CatalogUrlRewrite\Model\Product;

use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\CategoryRepository;
use Magento\Catalog\Model\Product;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
use Magento\UrlRewrite\Model\OptionProvider;
Expand Down Expand Up @@ -56,19 +57,24 @@ class CurrentUrlRewritesRegenerator
/** @var \Magento\UrlRewrite\Model\MergeDataProvider */
private $mergeDataProviderPrototype;

/** @var CategoryRepository */
private $categoryRepository;

/**
* @param UrlFinderInterface $urlFinder
* @param ProductUrlPathGenerator $productUrlPathGenerator
* @param UrlRewriteFactory $urlRewriteFactory
* @param UrlRewriteFinder|null $urlRewriteFinder
* @param \Magento\UrlRewrite\Model\MergeDataProviderFactory|null $mergeDataProviderFactory
* @param CategoryRepository|null $categoryRepository
*/
public function __construct(
UrlFinderInterface $urlFinder,
ProductUrlPathGenerator $productUrlPathGenerator,
UrlRewriteFactory $urlRewriteFactory,
UrlRewriteFinder $urlRewriteFinder = null,
MergeDataProviderFactory $mergeDataProviderFactory = null
MergeDataProviderFactory $mergeDataProviderFactory = null,
CategoryRepository $categoryRepository = null
) {
$this->urlFinder = $urlFinder;
$this->productUrlPathGenerator = $productUrlPathGenerator;
Expand All @@ -78,11 +84,12 @@ public function __construct(
if (!isset($mergeDataProviderFactory)) {
$mergeDataProviderFactory = ObjectManager::getInstance()->get(MergeDataProviderFactory::class);
}
$this->categoryRepository = $categoryRepository ?: ObjectManager::getInstance()->get(CategoryRepository::class);
$this->mergeDataProviderPrototype = $mergeDataProviderFactory->create();
}

/**
* Generate list based on current rewrites
* Generate product rewrites based on current rewrites without anchor categories
*
* @param int $storeId
* @param Product $product
Expand Down Expand Up @@ -115,6 +122,52 @@ public function generate($storeId, Product $product, ObjectRegistry $productCate
return $mergeDataProvider->getData();
}

/**
* Generate product rewrites for anchor categories based on current rewrites
*
* @param int $storeId
* @param Product $product
* @param ObjectRegistry $productCategories
* @param int|null $rootCategoryId
* @return UrlRewrite[]
*/
public function generateAnchor(
$storeId,
Product $product,
ObjectRegistry $productCategories,
$rootCategoryId = null
) {
$anchorCategoryIds = [];
$mergeDataProvider = clone $this->mergeDataProviderPrototype;

$currentUrlRewrites = $this->urlRewriteFinder->findAllByData(
$product->getEntityId(),
$storeId,
ProductUrlRewriteGenerator::ENTITY_TYPE,
$rootCategoryId
);

foreach ($productCategories->getList() as $productCategory) {
$anchorCategoryIds = array_merge($productCategory->getAnchorsAbove(), $anchorCategoryIds);
}

foreach ($currentUrlRewrites as $currentUrlRewrite) {
$metadata = $currentUrlRewrite->getMetadata();
if (isset($metadata['category_id']) && $metadata['category_id'] > 0) {
$category = $this->categoryRepository->get($metadata['category_id'], $storeId);
if (in_array($category->getId(), $anchorCategoryIds)) {
$mergeDataProvider->merge(
$currentUrlRewrite->getIsAutogenerated()
? $this->generateForAutogenerated($currentUrlRewrite, $storeId, $category, $product)
: $this->generateForCustom($currentUrlRewrite, $storeId, $category, $product)
);
}
}
}

return $mergeDataProvider->getData();
}

/**
* @param UrlRewrite $url
* @param int $storeId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ public function generateForSpecificStoreView($storeId, $productCategories, Produ
$mergeDataProvider->merge(
$this->anchorUrlRewriteGenerator->generate($storeId, $product, $productCategories)
);

$mergeDataProvider->merge(
$this->currentUrlRewritesRegenerator->generateAnchor(
$storeId,
$product,
$productCategories,
$rootCategoryId
)
);
return $mergeDataProvider->getData();
}

Expand Down
18 changes: 13 additions & 5 deletions app/code/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public function __construct(
public function generateProductUrlRewrites(\Magento\Catalog\Model\Category $category)
{
$mergeDataProvider = clone $this->mergeDataProviderPrototype;
$this->isSkippedProduct = [];
$this->isSkippedProduct[$category->getEntityId()] = [];
$saveRewriteHistory = $category->getData('save_rewrites_history');
$storeId = $category->getStoreId();
if ($category->getAffectedProductIds()) {
$this->isSkippedProduct = $category->getAffectedProductIds();
$this->isSkippedProduct[$category->getEntityId()] = $category->getAffectedProductIds();
$collection = $this->productCollectionFactory->create()
->setStoreId($storeId)
->addIdFilter($category->getAffectedProductIds())
Expand Down Expand Up @@ -137,17 +137,25 @@ public function getCategoryProductsUrlRewrites(
$rootCategoryId = null
) {
$mergeDataProvider = clone $this->mergeDataProviderPrototype;

/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection */
$productCollection = $category->getProductCollection()
$productCollection = $this->productCollectionFactory->create();

$productCollection->addCategoriesFilter(['eq' => [$category->getEntityId()]])
->setStoreId($storeId)
->addAttributeToSelect('name')
->addAttributeToSelect('visibility')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url_path');

foreach ($productCollection as $product) {
if (in_array($product->getId(), $this->isSkippedProduct)) {
if (
isset($this->isSkippedProduct[$category->getEntityId()]) &&
in_array($product->getId(), $this->isSkippedProduct[$category->getEntityId()])
) {
continue;
}
$this->isSkippedProduct[] = $product->getId();
$this->isSkippedProduct[$category->getEntityId()][] = $product->getId();
$product->setStoreId($storeId);
$product->setData('save_rewrites_history', $saveRewriteHistory);
$mergeDataProvider->merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ public function testGenerationForGlobalScope()
->setStoreId(3);
$this->currentUrlRewritesRegenerator->expects($this->any())->method('generate')
->will($this->returnValue([$current]));
$this->currentUrlRewritesRegenerator->expects($this->any())->method('generateAnchor')
->will($this->returnValue([$current]));
$anchorCategories = new \Magento\UrlRewrite\Service\V1\Data\UrlRewrite([], $this->serializer);
$anchorCategories->setRequestPath('category-4')
->setStoreId(4);
Expand Down Expand Up @@ -178,6 +180,8 @@ public function testGenerationForSpecificStore()
->will($this->returnValue([]));
$this->currentUrlRewritesRegenerator->expects($this->any())->method('generate')
->will($this->returnValue([]));
$this->currentUrlRewritesRegenerator->expects($this->any())->method('generateAnchor')
->will($this->returnValue([]));
$this->anchorUrlRewriteGenerator->expects($this->any())->method('generate')
->will($this->returnValue([]));

Expand Down
Loading

0 comments on commit 980bd1f

Please sign in to comment.