commerce_amws-8.x-1.x-dev/modules/shipping/src/EntitySync/FeedPostOrderFulfillmentDataRunner.php
modules/shipping/src/EntitySync/FeedPostOrderFulfillmentDataRunner.php
<?php
namespace Drupal\commerce_amws_shipping\EntitySync;
use Drupal\entity_sync\MachineName\Field\Operation as OperationField;
use Drupal\entity_sync\Entity\OperationInterface;
use Drupal\entity_sync\Entity\Runner\RunnerInterface;
use Drupal\entity_sync\Export\EntityManagerInterface as ExportManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Psr\Log\LoggerInterface;
/**
* Runner for CSV file upload configurator plugins.
*/
class FeedPostOrderFulfillmentDataRunner implements RunnerInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The Entity Synchronization entity export manager.
*
* @var \Drupal\entityCore\File\FileSystemInterface
*/
protected $exportManager;
/**
* The module's logger channel.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Constructs a new FeedPostOrderFulfillmentDataRunner object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\entity_sync\Export\EntityManagerInterface $export_manager
* The Entity Synchronization entity export manager.
* @param \Psr\Log\LoggerInterface $logger
* The module's logger channel.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
ExportManagerInterface $export_manager,
LoggerInterface $logger
) {
$this->entityTypeManager = $entity_type_manager;
$this->exportManager = $export_manager;
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public function run(OperationInterface $operation, array $context = []) {
$transition_id = 'complete_submission';
try {
$this->exportManager->exportLocalEntity(
$operation->bundle(),
$operation->get(OperationField::ENTITY)->entity,
[
'context' => [
'operation_entity' => $operation,
],
]
);
}
// phpcs:disable
// @I We could have errors raised after the feed has been submitted
// type : bug
// priority : normal
// labels : entity-sync, feed
// phpcs:enable
catch (\Throwable $throwable) {
$transition_id = 'fail_submission';
$this->logger->error(
'The operation with ID "@operation_id" failed to be submitted to Amazon MWS Feeds API: @throwable @message',
[
'@operation_id' => $operation->id(),
'@throwable' => get_class($throwable),
'@message' => $throwable->getMessage(),
]
);
}
$operation
->get(OperationField::STATE)
->first()
->applyTransitionById($transition_id);
$this->entityTypeManager
->getStorage('entity_sync_operation')
->save($operation);
}
}
