-
Notifications
You must be signed in to change notification settings - Fork 248
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 #23 from magento-l3/1.2-develop-pr45
[TSG-CSL3] For 1.2 develop (pr45)
- Loading branch information
Showing
9 changed files
with
290 additions
and
5 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
InventoryGroupedProduct/Plugin/InventoryCatalog/Model/UpdateParentStockStatusPlugin.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,79 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryGroupedProduct\Plugin\InventoryCatalog\Model; | ||
|
||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\Message\ManagerInterface; | ||
use Magento\InventoryCatalog\Model\UpdateInventory; | ||
use Magento\InventoryCatalog\Model\UpdateInventory\InventoryData; | ||
use Magento\GroupedProduct\Model\Inventory\ChangeParentStockStatus; | ||
use Magento\InventoryCatalogApi\Model\GetProductIdsBySkusInterface; | ||
|
||
/** | ||
* Disable Source items management for grouped product type. | ||
*/ | ||
class UpdateParentStockStatusPlugin | ||
{ | ||
/** | ||
* @var ManagerInterface | ||
*/ | ||
private $messageManager; | ||
|
||
/** | ||
* @var ChangeParentStockStatus | ||
*/ | ||
private $changeParentStockStatus; | ||
|
||
/** | ||
* @var GetProductIdsBySkusInterface | ||
*/ | ||
private $getProductIdsBySkus; | ||
|
||
/** | ||
* @param ManagerInterface $messageManager | ||
* @param ChangeParentStockStatus $changeParentStockStatus | ||
* @param GetProductIdsBySkusInterface $getProductIdsBySkus | ||
*/ | ||
public function __construct( | ||
ManagerInterface $messageManager, | ||
ChangeParentStockStatus $changeParentStockStatus, | ||
GetProductIdsBySkusInterface $getProductIdsBySkus | ||
) { | ||
$this->messageManager = $messageManager; | ||
$this->changeParentStockStatus = $changeParentStockStatus; | ||
$this->getProductIdsBySkus = $getProductIdsBySkus; | ||
} | ||
|
||
/** | ||
* After execute plugin | ||
* | ||
* @param UpdateInventory $subject | ||
* @param mixed $result | ||
* @param InventoryData $data | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterExecute(UpdateInventory $subject, $result, InventoryData $data) | ||
{ | ||
$skus = $data->getSkus(); | ||
try { | ||
$productIds = $this->getProductIdsBySkus->execute($skus); | ||
} catch (NoSuchEntityException $e) { | ||
$productIds = []; | ||
} | ||
try { | ||
foreach ($productIds as $productId) { | ||
$this->changeParentStockStatus->execute((int)$productId); | ||
} | ||
} catch (\Exception $e) { | ||
$this->messageManager->addExceptionMessage( | ||
$e, | ||
__('Something went wrong while updating the product(s) stock status.') | ||
); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
InventoryGroupedProduct/Test/Mftf/Data/QueueConsumerData.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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
|
||
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd"> | ||
<entity name="AdminInventoryMassUpdateConsumerData"> | ||
<data key="consumerName">inventory.mass.update</data> | ||
<data key="messageLimit">10</data> | ||
</entity> | ||
</entities> |
23 changes: 23 additions & 0 deletions
23
InventoryGroupedProduct/Test/Mftf/Test/UpdateStockStatusInventoryGroupedProductTest.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,23 @@ | ||
<?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="urn:magento:mftf:Test/etc/testSchema.xsd"> | ||
<test name="UpdateStockStatusGroupedProductTest"> | ||
<!--Run cron for start consumer --> | ||
<actionGroup ref="CliConsumerStartActionGroup" stepKey="startMessageQueue" after="setProductToOutOfStock"> | ||
<argument name="consumerName" value="{{AdminInventoryMassUpdateConsumerData.consumerName}}"/> | ||
<argument name="maxMessages" value="{{AdminInventoryMassUpdateConsumerData.messageLimit}}"/> | ||
</actionGroup> | ||
<!--Run cron for start consumer second--> | ||
<actionGroup ref="CliConsumerStartActionGroup" stepKey="startMessageQueueSecond" after="returnProductToInStock"> | ||
<argument name="consumerName" value="{{AdminInventoryMassUpdateConsumerData.consumerName}}"/> | ||
<argument name="maxMessages" value="{{AdminInventoryMassUpdateConsumerData.messageLimit}}"/> | ||
</actionGroup> | ||
</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
120 changes: 120 additions & 0 deletions
120
InventoryInStorePickup/Test/Unit/Model/ExtractPickupLocationAddressDataTest.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,120 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Test\Unit\Model; | ||
|
||
use Magento\Directory\Model\Region; | ||
use Magento\Directory\Model\RegionFactory; | ||
use Magento\Framework\DataObject\Copy; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\InventoryInStorePickup\Model\ExtractPickupLocationAddressData; | ||
use Magento\InventoryInStorePickup\Model\PickupLocation; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Provide tests for DataResolver | ||
*/ | ||
class ExtractPickupLocationAddressDataTest extends TestCase | ||
{ | ||
/** | ||
* @var ExtractPickupLocationAddressData | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var Copy|MockObject | ||
*/ | ||
private $objectCopyServiceMock; | ||
|
||
/** | ||
* @var Region|MockObject | ||
*/ | ||
private $regionMock; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$objectManagerHelper = new ObjectManager($this); | ||
|
||
$this->regionMock = $this->getMockBuilder(Region::class) | ||
->addMethods(['getCode']) | ||
->onlyMethods(['load', 'getName', 'loadByName']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->regionMock->method('loadByName')->willReturnSelf(); | ||
|
||
$this->objectCopyServiceMock = $this->getMockBuilder(Copy::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['getDataFromFieldset']) | ||
->getMockForAbstractClass(); | ||
|
||
$regionFactoryMock = $this->getMockBuilder(RegionFactory::class) | ||
->disableOriginalConstructor() | ||
->setMethods(['create']) | ||
->getMockForAbstractClass(); | ||
|
||
$regionFactoryMock->expects($this->any()) | ||
->method('create')->willReturn($this->regionMock); | ||
|
||
$this->model = $objectManagerHelper->getObject( | ||
ExtractPickupLocationAddressData::class, | ||
[ | ||
'objectCopyService' => $this->objectCopyServiceMock, | ||
'regionFactory' => $regionFactoryMock, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Check that region name is replacing correctly | ||
* | ||
* @param string $translatedRegionName | ||
* @param string $expectedRegionName | ||
* @dataProvider executeDataProvider | ||
* @return void | ||
*/ | ||
public function testExecute(string $translatedRegionName, string $expectedRegionName): void | ||
{ | ||
$this->objectCopyServiceMock->method('getDataFromFieldset') | ||
->willReturn(['region' => 'original_name']); | ||
$this->regionMock->method('getName')->willReturn($translatedRegionName); | ||
|
||
$pickupLocation = $this->createMock(PickupLocation::class); | ||
$pickupLocation->method('getCountryId')->willReturn('US'); | ||
$pickupLocation->method('getRegionId')->willReturn(1); | ||
$pickupLocation->method('getRegion')->willReturn('original_name'); | ||
|
||
$result = $this->model->execute($pickupLocation); | ||
|
||
$this->assertEquals( | ||
['region' => $expectedRegionName], | ||
$result | ||
); | ||
} | ||
|
||
/** | ||
* Provider for testExecute | ||
* | ||
* @return array | ||
*/ | ||
public function executeDataProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'translatedRegionName' => '', | ||
'expectedRegionName' => 'original_name', | ||
], | ||
[ | ||
'translatedRegionName' => 'region_name_translated', | ||
'expectedRegionName' => 'region_name_translated', | ||
], | ||
]; | ||
} | ||
} |
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