We will go to Magento 2.3 and need to integrate an old Module which handles the Order Exportation for our Fulfillment Service. I'm really new in Magento 2 and try to learn it step-by-step.

I have tried to integrate it in M2 but I don't get it running.

The old M1 Module contains following folder structure: Nerdzwork (Vendor) LettershopExport (Modul) Controller/ (folder with controller) etc/ (folder with config, module XML) Model/ (folder with export.php)

First of all, I have started to generate the Modul. In App/code I created folder Nerdzwork/LettershopExport/

I also created a Registration.php and a composer.json. I also created in /etc/adminhtml/ a Menu.xml and routes.xml file. The Menu shows correctly in M2 Backend. But it seems to be, that the "Action" don't routes correctly to the ExportController.php.

Can someone help me to get this Module running in M2? This Module should search for Processing Orders, create an csv file and export them and then it sets them to complete.

Here are the files which created / uploaded at /app/code/



* See LICENSE.txt for license details.



In Folder /Controller, ExportController.php


class Nerdzwork_LettershopExport_ExportController extends Mage_Core_Controller_Front_Action {

    private $completeOrderState = Mage_Sales_Model_Order::STATE_COMPLETE;

    private $uncompleteOrderState = Mage_Sales_Model_Order::STATE_PROCESSING;

    public function getCompleteOrderState() {

        return $this->completeOrderState;


    public function setCompleteOrderState($completeOrderState) {

        $this->completeOrderState = $completeOrderState;


    public function getUncompleteOrderStates() {

        return $this->uncompleteOrderState;


    public function setUncompleteOrderStates($uncompleteOrderStates) {

        $this->uncompleteOrderState = $uncompleteOrderStates;


    public function exportLetterShopAction() {

        $lettershopExportModel = Mage::getModel('lettershopExport/Export');

        $lettershopExportModel->iterateOrders($this->uncompleteOrderState, $this->completeOrderState);



In Folder /etc Config.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Nerdzwork_LettershopExport" setup_version="0.1.8">

In Folder /etc Module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <module name="Nerdzwork_LettershopExport" setup_version="0.1.8">
            <module name="Snmportal_Pdfbase"/>

In Folder /etc/adminhtml routes.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="admin">
        <route frontName="Nerdzwork_LettershopExport" id="Nerdzwork_LettershopExport">
            <module name="Nerdzwork_LettershopExport"/>

In Folder /etc/adminhtml menu.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
        <add id="Nerdzwork_LettershopExport::LettershopExport" title="LettershopExport" module="Nerdzwork_LettershopExport" sortOrder="1" resource="Nerdzwork_LettershopExport::LettershopExport" />
        <add id="Nerdzwork_LettershopExport::Run" title="LettershopExport Ausführen" module="Nerdzwork_LettershopExport" sortOrder="10" action="Nerdzwork/LettershopExport/Controller/ExportController" resource="Nerdzwork_LettershopExport::LettershopExport" parent="Nerdzwork_LettershopExport::LettershopExport" />

In Folder /Model Export.php


class Nerdzwork_LettershopExport_Model_Export extends Mage_Core_Model_Abstract {

    public function iterateOrders($uncompleteOrderstate, $completeOrderstate) {

        echo "<html><head><style>body{font-family:arial;font-size:12px}</style></head><body>";

        $uncompleteOrderstate = array(Mage_Sales_Model_Order::STATE_PROCESSING,'ogone_processed');
        $orders = Mage::getModel('sales/order')->getCollection()
                ->addFieldToFilter('status', array('in' => $uncompleteOrderstate));

        $returnOrderArray = array();
        $returnItemsArray = array();
        $countItems = 0;

        if (!count($orders)) {
            echo "keine neuen Bestellungen vorhanden";

        // create head Data
        foreach ($orders as $order) {

            $name1 = NULL;
            $name2 = NULL;
            $street = NULL;
            $street2 = NULL;
            $street3 = NULL;

            $billingAddress = $order->getBillingAddress();
            $shippingAddress = $order->getShippingAddress();

            $address = '';

            if (!is_object($shippingAddress)) {
                $address = $billingAddress;
            } else {
                $address = $shippingAddress;

            if ($address->hasCompany()) {
                    $name1 = $address->getCompany();

            if (!empty($name1)) {
                $name2 = $address->getName();
            } else {
                $name1 = $address->getName();

            $street = $address->getStreet1();
            $street2 = $address->getStreet2();
            $street3 = $address->getStreet3();

            if (!empty($street2)) {
                $street .= '|' . $street2;
            if (!empty($street3)) {
                $street .= '|' . $street3;

            $returnOrderArray[$order->getIncrementId()]['KONTONR'] = '15089';
            $returnOrderArray[$order->getIncrementId()]['FFNR'] = '381';
            $returnOrderArray[$order->getIncrementId()]['NUMMER'] = $order->getIncrementId();
            $returnOrderArray[$order->getIncrementId()]['NAME1'] = $name1;
            $returnOrderArray[$order->getIncrementId()]['NAME2'] = $name2;
            $returnOrderArray[$order->getIncrementId()]['NAME3'] = $address->getAdditionalInformation();
            $returnOrderArray[$order->getIncrementId()]['NAME4'] = '';
            $returnOrderArray[$order->getIncrementId()]['NAME5'] = '';
            $returnOrderArray[$order->getIncrementId()]['LK'] = $address->getCountryId();
            $returnOrderArray[$order->getIncrementId()]['PLZ'] = $address->getPostcode();
            $returnOrderArray[$order->getIncrementId()]['STRASSE'] = $street;
            $returnOrderArray[$order->getIncrementId()]['ORT'] = $address->getCity();
            $returnOrderArray[$order->getIncrementId()]['MAILADR'] = ''; 
            $returnOrderArray[$order->getIncrementId()]['VCODE'] = '';
            $returnOrderArray[$order->getIncrementId()]['NNAHME'] = '';
            $returnOrderArray[$order->getIncrementId()]['REFERENZ'] = '';
            $returnOrderArray[$order->getIncrementId()]['KDAUFNR'] = $order->getBestNr();
            $returnOrderArray[$order->getIncrementId()]['AUFDAT'] = date('d.m.Y', strtotime($order->getCreatedAt()));
            $returnOrderArray[$order->getIncrementId()]['KOSTENST'] = '';
            $returnOrderArray[$order->getIncrementId()]['TERMIN'] = '';
            $returnOrderArray[$order->getIncrementId()]['BEMERKUNG1'] = ''; 
            $returnOrderArray[$order->getIncrementId()]['BEMERKUNG2'] = $order->getWeight();
            $returnOrderArray[$order->getIncrementId()]['BEMERKUNG3'] = ''; //$address->getTelephone(); 
            $returnOrderArray[$order->getIncrementId()]['SORTFELD1'] = '';
            $returnOrderArray[$order->getIncrementId()]['RESERVE0'] = '';
            $returnOrderArray[$order->getIncrementId()]['RESERVE'] = $order->getIncrementId();

            // create order items
            $items = $order->getAllItems();

            foreach ($items as $item) {
                $returnItemsArray[$countItems]['NUMMER'] = $order->getIncrementId();
                $returnItemsArray[$countItems]['ARTNR'] = $item->getSku();
                $returnItemsArray[$countItems]['MENGE'] = (int) $item->getQtyOrdered();

        echo "<table cellpadding=5 cellspcaing=5 border=1>";

        if ($this->writeOrderCsv($returnOrderArray, 'head') !== true) {
            echo "can't write CSV";
        } elseif ($this->writeOrderCsv($returnItemsArray, 'items') !== true) {

        } else {

            echo "<tr><td>Bestellung</td><td>Rechnung</td><td>Lieferschein</td></tr>";
            foreach ($orders as $order) {
                try {
                    if ( !$order->hasShipments() )
                        $shipment = $order->prepareShipment();
                        if ($shipment) {
                            $transactionSave = Mage::getModel('core/resource_transaction')
                            $order = Mage::getModel('sales/order')->load($order->getId());
                    echo "<tr><td>".$order->getIncrementId().'</td>';

                    foreach ( $order->getInvoiceCollection() as $invoice )

                        echo "<td>";
                        $url = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/sales_order_invoice/print', array(
                            'invoice_id' => $invoice->getId()) );
                        echo "<a target='pdf' href='$url'>PDF ".$invoice->getIncrementId()."</a>";
                        echo '</td>';
                    foreach ( $order->getShipmentsCollection() as $shipment )
                        echo "<td>";
                        $url = Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/sales_order_shipment/print', array(
                                'invoice_id' => $shipment->getId()) );
                        echo "<a target='pdf' href='$url'>PDF ".$shipment->getIncrementId()."</a>";
                        echo '</td>';
                    echo "</tr>";
                    $order->_setState($completeOrderstate, true, "Lettershop Export")->save();
                }catch ( Exception $e )
        echo "</table>";
        echo "</body></html>";

    private function writeOrderCsv(array $orderArray, $filename) {

        if (is_dir(Mage::getBaseDir() . '/lettershopexport/')) {
            $path = Mage::getBaseDir() . '/lettershopexport/';
            $filename = $filename . '_' . date("Y_m_d_H_i_s") . '.csv';
            $completePath = $path . $filename;
            $completeWebPath = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB) . '/lettershopexport/' . $filename;
        } else {
            return false;

        $d ='';
        foreach ($orderArray as $fields) {
            foreach ($fields as $field ) {
                $d .= str_replace(array("\n","\r")," ",$field).";";
            $d .="\r\n";
        file_put_contents($completePath,utf8_decode($d) );
        echo "<tr><td colspan='3'>";
        echo "<a href='" . $completeWebPath . "'>" . $filename . "</a><br />";
        echo "</td></tr>";
        return true;


So thats it. Expected Result: After clicking "LettershopExport Run" this Module should get all process orders, generates head csv (it contains all Customer Adress data) and also item csv (it contains the sku and qty) and paste them in a new Tab as Table and then complete them (generates shipment for all process orders).

Actually Result: by Clicking "LettershopExport Run" it routes to


So I think there is an error or some files missing which needs to set up in M2? I hope someone can help me to get this work.

Thanks for every help!

  • Do you have the original m1 files? if so would be better to go to an developer and have them upgrade it for you – Dava Gordon Aug 19 '19 at 13:48
  • Yes i got the original Files but i want to try it by myself. If all solutions dont work i can still contact a developer to do it. Thanks. – Beendeluxe Aug 19 '19 at 14:05
  • 1
    A lot of the functionality from magento 1 is not avaible first thing i can see wrong is your trying to access Mage::getModel which is valid on this version of magento you can include the module via the object manager or place in via the construct – Dava Gordon Aug 19 '19 at 14:09
  • Can you show me an exemaple code how it should looks like? – Beendeluxe Aug 19 '19 at 15:17

Most likely the problem is in adminhtml/routes.xml. Give this a try:

<route frontName="Nerdzwork_LettershopExport" id="Nerdzwork_LettershopExport">


<route id="adminhtml">

Unless this module needs frontend routing, but I'm assuming not.

| improve this answer | |
  • Dont work. If i change it to Adminhtml the route ends with: <host>/b4ckend/Nerdzwork/LettershopExport/Controller/key/<key>/Nerdzwork/LettershopExport/Controller/Nerdzwork/LettershopExport/Controller/Nerdzwork/LettershopExport/Controller – Beendeluxe Aug 19 '19 at 14:41
  • Was this module created with a automatic conversion tool like github.com/magento/code-migration ? – B00MER Aug 19 '19 at 15:15
  • It was edited by myself. I will test the Code-Migration Toolkit tomorrow and give a feedback. – Beendeluxe Aug 19 '19 at 15:27

Thanks for the Code-Migration toolkit. It does not really work, getting errors while running this:

bin/migrate.php: line 1: ?php: No such file or directory
bin/migrate.php: line 2: /bin: Is a directory
bin/migrate.php: line 3: app: command not found
bin/migrate.php: line 4: app: command not found
bin/migrate.php: line 5: app/: Is a directory
bin/migrate.php: line 7: require: command not found
bin/migrate.php: line 8: require: command not found
bin/migrate.php: line 10: use: command not found
bin/migrate.php: line 11: use: command not found
bin/migrate.php: line 13: /bin: Is a directory
bin/migrate.php: line 14: syntax error near unexpected token `('
bin/migrate.php: line 14: `$application = $bootstrap->getObjectManager()->create('Symfony\Component\Console\Application');'

Has someone the toolkit and may can convert our extension to M2? This would be awesome.

Thank you all for your help!

| improve this answer | |
  • The code migration tool will not migrate the full code of the module. You need to change it manually after the code migration. – Sumit Aug 22 '19 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.