Prevent Default Source/Stock to be deleted#126
Conversation
| throw new CouldNotDeleteException(__('Default Stock could not be deleted.')); | ||
| } | ||
|
|
||
| return null; |
There was a problem hiding this comment.
Pls remove this return
We should return nothing (void)
| public function beforeDeleteById(StockRepositoryInterface $subject, int $stockId) | ||
| { | ||
| if ($stockId === $this->defaultStockProvider->getId()) { | ||
| throw new CouldNotDeleteException(__('Default Stock could not be deleted.')); |
There was a problem hiding this comment.
Need to cover this check with web-api test
Example of negative scenarios you could find in MSI web-api tests
| * @param StockRepositoryInterface $subject | ||
| * @param int $stockId | ||
| * | ||
| * @return null |
There was a problem hiding this comment.
it is from http://devdocs.magento.com/guides/v2.2/extension-dev-guide/plugins.html "If the method does not change the argument for the observed method, it should return null" but maybe my thinking was wrong in this case.
| <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
| <preference for="Magento\InventoryCatalog\Api\DefaultStockProviderInterface" type="Magento\InventoryCatalog\Model\DefaultStockProvider"/> | ||
| <preference for="Magento\InventoryCatalog\Api\DefaultSourceProviderInterface" type="Magento\InventoryCatalog\Model\DefaultSourceProvider"/> | ||
| <type name="Magento\Inventory\Model\StockRepository"> |
There was a problem hiding this comment.
We need to add this plugin not on implementation Magento\Inventory\Model\StockRepository but on interface \Magento\InventoryApi\Api\StockRepositoryInterface
If somebody will replace StockRepository on own implementation our check will be work
| <preference for="Magento\InventoryCatalog\Api\DefaultStockProviderInterface" type="Magento\InventoryCatalog\Model\DefaultStockProvider"/> | ||
| <preference for="Magento\InventoryCatalog\Api\DefaultSourceProviderInterface" type="Magento\InventoryCatalog\Model\DefaultSourceProvider"/> | ||
| <type name="Magento\Inventory\Model\StockRepository"> | ||
| <plugin name="prevent-default-stock-deletion" type="Magento\InventoryCatalog\Plugin\Model\StockRepositoryPlugin" sortOrder="1"/> |
There was a problem hiding this comment.
As I see in Magento generally used underscore for keys (but not dashe)
There was a problem hiding this comment.
got it, again like in magento2 original code but of course I will fix that
| <preference for="Magento\InventoryCatalog\Api\DefaultSourceProviderInterface" type="Magento\InventoryCatalog\Model\DefaultSourceProvider"/> | ||
| <type name="Magento\Inventory\Model\StockRepository"> | ||
| <plugin name="prevent-default-stock-deletion" type="Magento\InventoryCatalog\Plugin\Model\StockRepositoryPlugin" sortOrder="1"/> | ||
| </type> |
There was a problem hiding this comment.
Also, I think we could expand Delete button object.
We do not need show delete button in admin panel if it is default Stock or Source
| * @param StockRepositoryInterface $subject | ||
| * @param int $stockId | ||
| * | ||
| * @return null |
There was a problem hiding this comment.
why null return void is enough
| use Magento\InventoryCatalog\Api\DefaultStockProviderInterface; | ||
|
|
||
| /** | ||
| * Plugin Stock Repository |
| <preference for="Magento\InventoryCatalog\Api\DefaultStockProviderInterface" type="Magento\InventoryCatalog\Model\DefaultStockProvider"/> | ||
| <preference for="Magento\InventoryCatalog\Api\DefaultSourceProviderInterface" type="Magento\InventoryCatalog\Model\DefaultSourceProvider"/> | ||
| <type name="Magento\Inventory\Model\StockRepository"> | ||
| <plugin name="prevent-default-stock-deletion" type="Magento\InventoryCatalog\Plugin\Model\StockRepositoryPlugin" sortOrder="1"/> |
There was a problem hiding this comment.
pls use prevent_default_stock_deletion as name
…lete-default-stock
Description
Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist