Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 0a499bc8 authored by Nicolas's avatar Nicolas
Browse files

Création du plugin

parent e0ebb5fb
No related branches found
No related tags found
No related merge requests found
<?php
namespace NicolasBejean\Sales\Plugin;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Api\Data\OrderInterface;
use NicolasBejean\Sales\Api\OrderExporterRepositoryInterface;
use NicolasBejean\Sales\Model\OrderExporter;
use NicolasBejean\Sales\Model\OrderExporterFactory;
use Psr\Log\LoggerInterface;
use Magento\Framework\Exception\LocalizedException;
class OrderRepository
{
/**
* @var OrderExporterFactory
*/
protected $orderExporterFactory;
/**
* @var OrderExporterRepositoryInterface
*/
protected $orderExportedRepository;
/**
* @var LoggerInterface
*/
protected $logger;
/**
* OrderRepository constructor.
*
* @param OrderExporterFactory $orderExporterFactory
* @param OrderExporterRepositoryInterface $orderExportedRepository
* @param LoggerInterface $logger
*/
public function __construct(
OrderExporterFactory $orderExporterFactory,
OrderExporterRepositoryInterface $orderExportedRepository,
LoggerInterface $logger
) {
$this->orderExporterFactory = $orderExporterFactory;
$this->orderExportedRepository = $orderExportedRepository;
$this->logger = $logger;
}
/**
* @param OrderRepositoryInterface $orderRepository
* @param OrderInterface $order
* @return OrderInterface
*/
public function afterSave(OrderRepositoryInterface $orderRepository, OrderInterface $order)
{
/** @var OrderExporter $model */
$model = $this->orderExporterFactory->create();
$model->setOrderId($order->getEntityId());
$model->setIsExported(0);
try {
$this->orderExportedRepository->save($model);
} catch (LocalizedException $e) {
$this->logger->error('NicolasBejean/Sales/Plugin/OrderRepository', ['method' => 'afterSave', 'message' => $e->getMessage()]);
}
return $order;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment