-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3254 from magento-tsg/2.2-develop-pr48
[TSG] Backporting for 2.2 (pr48) (2.2.8)
- Loading branch information
Showing
12 changed files
with
282 additions
and
2 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
app/code/Magento/CatalogUrlRewrite/Model/WebapiProductUrlPathGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogUrlRewrite\Model; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection; | ||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory; | ||
|
||
/** | ||
* Class for creating product url through web-api. | ||
*/ | ||
class WebapiProductUrlPathGenerator extends ProductUrlPathGenerator | ||
{ | ||
/** | ||
* @var CollectionFactory | ||
*/ | ||
private $collectionFactory; | ||
|
||
/** | ||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | ||
* @param \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator | ||
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository | ||
* @param CollectionFactory $collectionFactory | ||
*/ | ||
public function __construct( | ||
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, | ||
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository, | ||
CollectionFactory $collectionFactory | ||
) { | ||
parent::__construct($storeManager, $scopeConfig, $categoryUrlPathGenerator, $productRepository); | ||
$this->collectionFactory = $collectionFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function prepareProductUrlKey(\Magento\Catalog\Model\Product $product) | ||
{ | ||
$urlKey = $product->getUrlKey(); | ||
if ($urlKey === '' || $urlKey === null) { | ||
$urlKey = $this->prepareUrlKey($product->formatUrlKey($product->getName())); | ||
} | ||
|
||
return $product->formatUrlKey($urlKey); | ||
} | ||
|
||
/** | ||
* Crete url key if it does not exist yet. | ||
* | ||
* @param string $urlKey | ||
* @return string | ||
*/ | ||
private function prepareUrlKey(string $urlKey) : string | ||
{ | ||
/** @var ProductCollection $collection */ | ||
$collection = $this->collectionFactory->create(); | ||
$collection->addFieldToFilter('url_key', ['like' => $urlKey]); | ||
if ($collection->getSize() !== 0) { | ||
$urlKey = $urlKey . '-1'; | ||
$urlKey = $this->prepareUrlKey($urlKey); | ||
} | ||
|
||
return $urlKey; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Magento\CatalogUrlRewrite\Model\WebapiProductUrlPathGenerator"/> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Magento\CatalogUrlRewrite\Model\WebapiProductUrlPathGenerator"/> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...Plugin/Catalog/Controller/Adminhtml/Product/Initialization/Helper/ProcessTaxAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper; | ||
|
||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper; | ||
use Magento\Framework\App\RequestInterface; | ||
|
||
/** | ||
* Handles product tax attributes data initialization. | ||
*/ | ||
class ProcessTaxAttribute | ||
{ | ||
/** | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @param RequestInterface $request | ||
*/ | ||
public function __construct(RequestInterface $request) | ||
{ | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* @param Helper $subject | ||
* @param Product $result | ||
* @param Product $product | ||
* @param array $productData | ||
* @return Product | ||
* | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterInitializeFromData( | ||
Helper $subject, | ||
Product $result, | ||
Product $product, | ||
array $productData | ||
): Product { | ||
$attributes = $result->getAttributes(); | ||
if (!empty($attributes)) { | ||
foreach ($attributes as $attribute) { | ||
if ($attribute->getFrontendInput() == 'weee' && !isset($productData[$attribute->getAttributeCode()])) { | ||
$result->setData($attribute->getAttributeCode(), []); | ||
} | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/code/Magento/Weee/Test/Mftf/Test/AdminRemoveProductWeeeAttributeOptionTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd"> | ||
<test name="AdminRemoveProductWeeeAttributeOptionTest"> | ||
<annotations> | ||
<features value="Weee attribute options can be removed in product page"/> | ||
<title value="Weee attribute options can be removed in product page"/> | ||
<description value="Weee attribute options can be removed in product page"/> | ||
<severity value="CRITICAL"/> | ||
<testCaseId value="MAGETWO-94817"/> | ||
<group value="weee"/> | ||
</annotations> | ||
<before> | ||
<createData entity="productFPTAttribute" stepKey="createProductFPTAttribute"/> | ||
<createData entity="AddToDefaultSet" stepKey="addFPTToAttributeSet"> | ||
<requiredEntity createDataKey="createProductFPTAttribute"/> | ||
</createData> | ||
<createData entity="SimpleOne" stepKey="createSimpleProduct"/> | ||
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/> | ||
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProductInitial"> | ||
<argument name="product" value="$$createSimpleProduct$$"/> | ||
</actionGroup> | ||
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProductInitial"> | ||
<argument name="product" value="$$createSimpleProduct$$"/> | ||
</actionGroup> | ||
<actionGroup ref="AdminProductAddFPTValueActionGroup" stepKey="addWeeeAttributeValue"> | ||
<argument name="FPTAttributeCode" value="$$createProductFPTAttribute.attribute_code$$"/> | ||
<argument name="stateForFPT" value="California"/> | ||
<argument name="valueForFPT" value="10"/> | ||
</actionGroup> | ||
<actionGroup ref="SaveProductOnProductPageOnAdmin" stepKey="saveProductInitial"/> | ||
</before> | ||
<after> | ||
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductListing"/> | ||
<waitForPageLoad stepKey="waitForProductListingPageLoad"/> | ||
<actionGroup ref="AdminResetProductGridToDefaultViewActionGroup" stepKey="resetGridToDefaultKeywordSearch"/> | ||
<actionGroup ref="logout" stepKey="logout"/> | ||
<deleteData createDataKey="createProductFPTAttribute" stepKey="deleteProductFPTAttribute"/> | ||
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/> | ||
</after> | ||
<!-- Test Steps --> | ||
<!-- Step 1: Open created product edit page --> | ||
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProduct"> | ||
<argument name="product" value="$$createSimpleProduct$$"/> | ||
</actionGroup> | ||
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct"> | ||
<argument name="product" value="$$createSimpleProduct$$"/> | ||
</actionGroup> | ||
<!-- Step 2: Remove weee attribute options --> | ||
<click selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="removeAttributeOption"/> | ||
<actionGroup ref="SaveProductOnProductPageOnAdmin" stepKey="saveProduct"/> | ||
<!-- Assert weee attribute options are empty --> | ||
<dontSeeElement selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="dontSeeOptions"/> | ||
</test> | ||
</tests> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters