Skip to content
Snippets Groups Projects
Commit 2f684042 authored by Vadim Justus's avatar Vadim Justus
Browse files

Initial commit

parents
Branches master
No related tags found
No related merge requests found
<?php
/**
* Copyright (c) 2020 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
declare(strict_types=1);
namespace TechDivision\OrderWorkflowCustomExportFormat\Model;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\Io\File;
use Magento\Sales\Api\OrderRepositoryInterface;
use TechDivision\PacemakerImportBase\Model\AbsolutePathResolver;
use TechDivision\ProcessPipelines\Api\ExecutorLoggerInterface;
use TechDivision\ProcessPipelines\Api\StepInterface;
use TechDivision\ProcessPipelines\Model\Executor\AbstractExecutor;
/**
* @copyright Copyright (c) 2020 TechDivision GmbH (http://www.techdivision.com)
* @link http://www.techdivision.com/
* @author Vadim Justus <v.justus@techdivision.com>
*/
class CustomOrderFormatExecutor extends AbstractExecutor
{
/**
* @var OrderRepositoryInterface
*/
private $orderRepository;
/**
* @var File
*/
private $file;
/**
* @var AbsolutePathResolver
*/
private $absolutePathResolver;
/**
* @var MyFormatRenderer
*/
private $myFormatRenderer;
/**
* @param ExecutorLoggerInterface $logger
* @param OrderRepositoryInterface $orderRepository
* @param File $file
* @param AbsolutePathResolver $absolutePathResolver
* @param MyFormatRenderer $myFormatRenderer
*/
public function __construct(
ExecutorLoggerInterface $logger,
OrderRepositoryInterface $orderRepository,
File $file,
AbsolutePathResolver $absolutePathResolver,
MyFormatRenderer $myFormatRenderer
) {
parent::__construct($logger);
$this->orderRepository = $orderRepository;
$this->file = $file;
$this->absolutePathResolver = $absolutePathResolver;
$this->myFormatRenderer = $myFormatRenderer;
}
/**
* @param StepInterface $step
* @return void
* @throws LocalizedException
*/
public function process(StepInterface $step)
{
// Load the order with the order_id given in step arguments
$order = $this->orderRepository->get((int)$step->getArgumentValueByKey('order_id'));
// It's recommended to use logger to have better monitoring
$this->getLogger()->info(
sprintf(
'Order %s (%s) was loaded!',
$order->getIncrementId(),
$order->getEntityId()
)
);
// Generate the target order format
$result = $this->myFormatRenderer->execute($order, $this->getLogger());
// retrieve absolute working directory path
$workingDirectory = $this->absolutePathResolver->get($step->getWorkingDirectory());
// define the file path to persist your results
// the default local file system transporter will check for
// the file order-export.body within the working dir
$bodyFile = $workingDirectory . '/order-export.body';
$this->file->write($bodyFile, $result);
// Do not forget to log the process ;)
$this->getLogger()->info(sprintf('Persist transformed order in file "%s"', $bodyFile));
}
}
<?php
/**
* Copyright (c) 2020 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
declare(strict_types=1);
namespace TechDivision\OrderWorkflowCustomExportFormat\Model;
use Magento\Sales\Api\Data\OrderInterface;
use Psr\Log\LoggerInterface;
/**
* @copyright Copyright (c) 2020 TechDivision GmbH (http://www.techdivision.com)
* @link http://www.techdivision.com/
* @author Vadim Justus <v.justus@techdivision.com>
*/
class MyFormatRenderer
{
/**
* @param OrderInterface $order
* @param LoggerInterface $logger
* @return string
*/
public function execute(OrderInterface $order, LoggerInterface $logger): string
{
$logger->info(sprintf('Format order "%s" into my custom format ;)', $order->getIncrementId()));
$value = <<<EOF
Some fancy file format
Increment ID: {$order->getIncrementId()}
Customer E-Mail: {$order->getCustomerEmail()}
...
EOF;
return $value;
}
}
# Pacemaker customization example
This example demonstrates
- how to register a custom order export format
- how to add it to the dropdown selection in `Order Workflow` configuration
Please refer to [Pacemaker documentation](https://docs.met.tdintern.de/pacemaker/1.2/how-to-extend/order-workflow/add-custom-export-format.html) for details.
{
"name": "techdivision/order-workflow-custom-export-format",
"description": "Example module for Pacemaker customizations",
"license": "proprietary",
"require": {
"magento/framework": "^101.0.9 | ^102.0.0 | ^103.0.0",
"techdivision/pacemaker-order-export": "*",
"techdivision/process-pipelines": "*"
},
"type": "magento2-module",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"TechDivision\\OrderWorkflowCustomExportFormat\\": ""
}
},
"repositories": [
{
"type": "composer",
"url": "https://repo.met.tdintern.de/"
},
{
"type": "composer",
"url": "https://repo.magento.com/"
}
]
}
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2019 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*
* @copyright Copyright (c) 2019 TechDivision GmbH (http://www.techdivision.com)
* @author Vadim Justus <v.justus@techdivision.com>
* @link http://www.techdivision.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="TechDivision\PacemakerOrderExport\Model\ExportFormatProvider">
<arguments>
<argument name="formatList" xsi:type="array">
<item name="my_custom_format" xsi:type="array">
<item name="code" xsi:type="string">my_custom_format</item>
<item name="label" xsi:type="string">My Custom Format</item>
<item name="type" xsi:type="string">TechDivision\OrderWorkflowCustomExportFormat\Model\CustomOrderFormatExecutor</item>
</item>
</argument>
</arguments>
</type>
</config>
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2020 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*
* @copyright Copyright (c) 2020 TechDivision GmbH (http://www.techdivision.com)
* @author Vadim Justus <v.justus@techdivision.com>
* @link http://www.techdivision.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="TechDivision_OrderWorkflowCustomExportFormat" setup_version="1.0.0">
<sequence>
<module name="TechDivision_PacemakerOrderExport"/>
</sequence>
</module>
</config>
<?php
/**
* Copyright (c) 2020 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'TechDivision_OrderWorkflowCustomExportFormat',
__DIR__
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment