-
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 #3480 from magento-tango/PR-2311
[tango] PR
- Loading branch information
Showing
11 changed files
with
307 additions
and
54 deletions.
There are no files selected for viewing
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
88 changes: 88 additions & 0 deletions
88
app/code/Magento/CatalogUrlRewrite/Plugin/Webapi/Controller/Rest/InputParamsResolver.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,88 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest; | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Framework\Webapi\Rest\Request as RestRequest; | ||
|
||
/** | ||
* Plugin for InputParamsResolver | ||
* | ||
* Used to modify product data with save_rewrites_history flag | ||
*/ | ||
class InputParamsResolver | ||
{ | ||
/** | ||
* @var RestRequest | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @param RestRequest $request | ||
*/ | ||
public function __construct(RestRequest $request) | ||
{ | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* Add 'save_rewrites_history' param to the product data | ||
* | ||
* @see \Magento\CatalogUrlRewrite\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper | ||
* @param \Magento\Webapi\Controller\Rest\InputParamsResolver $subject | ||
* @param array $result | ||
* @return array | ||
*/ | ||
public function afterResolve(\Magento\Webapi\Controller\Rest\InputParamsResolver $subject, array $result): array | ||
{ | ||
$route = $subject->getRoute(); | ||
$serviceMethodName = $route->getServiceMethod(); | ||
$serviceClassName = $route->getServiceClass(); | ||
$requestBodyParams = $this->request->getBodyParams(); | ||
|
||
if ($this->isProductSaveCalled($serviceClassName, $serviceMethodName) | ||
&& $this->isCustomAttributesExists($requestBodyParams)) { | ||
foreach ($requestBodyParams['product']['custom_attributes'] as $attribute) { | ||
if ($attribute['attribute_code'] === 'save_rewrites_history') { | ||
foreach ($result as $resultItem) { | ||
if ($resultItem instanceof \Magento\Catalog\Model\Product) { | ||
$resultItem->setData('save_rewrites_history', (bool)$attribute['value']); | ||
break 2; | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Check that product save method called | ||
* | ||
* @param string $serviceClassName | ||
* @param string $serviceMethodName | ||
* @return bool | ||
*/ | ||
private function isProductSaveCalled(string $serviceClassName, string $serviceMethodName): bool | ||
{ | ||
return $serviceClassName === ProductRepositoryInterface::class && $serviceMethodName === 'save'; | ||
} | ||
|
||
/** | ||
* Check is any custom options exists in product data | ||
* | ||
* @param array $requestBodyParams | ||
* @return bool | ||
*/ | ||
private function isCustomAttributesExists(array $requestBodyParams): bool | ||
{ | ||
return !empty($requestBodyParams['product']['custom_attributes']); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
...nto/CatalogUrlRewrite/Test/Unit/Plugin/Webapi/Controller/Rest/InputParamsResolverTest.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,116 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogUrlRewrite\Test\Unit\Plugin\Webapi\Controller\Rest; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Webapi\Controller\Rest\InputParamsResolver; | ||
use Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest\InputParamsResolver as InputParamsResolverPlugin; | ||
use Magento\Framework\Webapi\Rest\Request as RestRequest; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Webapi\Controller\Rest\Router\Route; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
|
||
/** | ||
* Unit test for InputParamsResolver plugin | ||
*/ | ||
class InputParamsResolverTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $saveRewritesHistory; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $requestBodyParams; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $result; | ||
|
||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var InputParamsResolver|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $subject; | ||
|
||
/** | ||
* @var RestRequest|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @var Product|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $product; | ||
|
||
/** | ||
* @var Route|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $route; | ||
|
||
/** | ||
* @var InputParamsResolverPlugin | ||
*/ | ||
private $plugin; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->saveRewritesHistory = 'save_rewrites_history'; | ||
$this->requestBodyParams = [ | ||
'product' => [ | ||
'sku' => 'test', | ||
'custom_attributes' => [ | ||
['attribute_code' => $this->saveRewritesHistory, 'value' => 1] | ||
] | ||
] | ||
]; | ||
|
||
$this->route = $this->createPartialMock(Route::class, ['getServiceMethod', 'getServiceClass']); | ||
$this->request = $this->createPartialMock(RestRequest::class, ['getBodyParams']); | ||
$this->request->expects($this->any())->method('getBodyParams')->willReturn($this->requestBodyParams); | ||
$this->subject = $this->createPartialMock(InputParamsResolver::class, ['getRoute']); | ||
$this->subject->expects($this->any())->method('getRoute')->willReturn($this->route); | ||
$this->product = $this->createPartialMock(Product::class, ['setData']); | ||
|
||
$this->result = [false, $this->product, 'test']; | ||
|
||
$this->objectManager = new ObjectManager($this); | ||
$this->plugin = $this->objectManager->getObject( | ||
InputParamsResolverPlugin::class, | ||
[ | ||
'request' => $this->request | ||
] | ||
); | ||
} | ||
|
||
public function testAfterResolve() | ||
{ | ||
$this->route->expects($this->once()) | ||
->method('getServiceClass') | ||
->willReturn(ProductRepositoryInterface::class); | ||
$this->route->expects($this->once()) | ||
->method('getServiceMethod') | ||
->willReturn('save'); | ||
$this->product->expects($this->once()) | ||
->method('setData') | ||
->with($this->saveRewritesHistory, true); | ||
|
||
$this->plugin->afterResolve($this->subject, $this->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
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
33 changes: 0 additions & 33 deletions
33
...de/Magento/Quote/Test/Mftf/ActionGroup/ChangeStatusProductUsingProductGridActionGroup.xml
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
app/code/Magento/Quote/Test/Mftf/Section/AdminProductGridSection.xml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.