-
Notifications
You must be signed in to change notification settings - Fork 3
First iteration tasks
Base information: https://github.com/magento-engcom/bulk-api/wiki
This document describes main concepts of new functionality on lower level
The main idea is creating working solution on first iteration. It helps us to:
- possibility to immediately start implementation of base part;
- discover new issues;
- unblock work for more sophisticated cases.
- Introduce new interface
RequestProcessorInterface
use Magento\Framework\Webapi\Rest\Request;
use Magento\Framework\Webapi\Rest\Response;
interface RequestProcessorInterface
{
public function process(Request $request, Response $responce): Response;
}
- Inject this interface to `\Magento\Webapi\Controller\Rest
$responce = $this->requestProcessor->process($request, $responce);
- Base implementation of RequestProcessorInterface
private $processors;
public function process(Request $request, Response $responce)
{
if (!isset($this->processors[$request->getPathInfo()])) {
throw new NotFoundException(__('Specified request does not match any route.'));
}
$processor = $this->objectmanager->get($this->processors[$request->getPathInfo()]);
$processor->process($request, $responce);
}
- Update di.xml Something like
<item key="scheme" type="string">SchemeProcessor</item>
<item key="V1" type="string">SyncProcessor</item>
Pay attention: this task was partial finished in https://github.com/magento/bulk-api-ce/pull/1/files
- Request processor should set proper Status Code
202 ACCEPTED The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place.
-
Processor should set into response UID
-
Register processor in DI
<item key="async" type="string">AsyncProcessor</item>
- Create WebaApi routing declaration
<route url="/async/V1/products" method="POST">
<service class="Magento\Catalog\Model\SaveProductPublisherInterface" method="execute"/>
<resources>
<resource ref="Magento_Catalog::products" />
</resources>
</route>
Know issue: Now current declaration will be used We will have separate files for sync and async routing configuration, but generally is good to reuse current declaration (xsd scheme) This way reduces the complexity and threshold of occurrence
-
Describe configuration on
communication.xml
Generally, maybe we will expand this declaration. Know we use current declaration. -
Implement
Magento\Catalog\Model\SaveProductPublisherInterface
(interface name is preliminary)
- Generate UID
$bulkUID = $this->identityService->generateId(); // \Magento\Framework\DataObject\IdentityGeneratorInterface
- Create factory for operations (personal factory for each entity) and encapsulate logic of operation creating
- Schedule bulk
$result = $this->bulkManagement->scheduleBulk($bulkUID, $operations, $bulkDescription, $userId); // \Magento\Framework\Bulk\BulkManagementInterface::scheduleBulk
- Should return bulk UID
At this state, we can hardcode topic name in implementation
- Cover functionality with API functional tests (for checking result we can use some temporal new object in test namespace)
- Consumer implementation
interface Magento\Catalog\Model\ProductConsumerInterface
public function processOperations(\Magento\AsynchronousOperations\Api\Data\OperationListInterface $operationList)
- Cover functionality with API functional tests
- Why do we need external_id for products? Product has SKU (system independent identifier)
- Investigate possibility to remove
async
prefix in url (maybe use some HTTP header)