4

I'm working on one module. module does read CSV file from var/import and making a call to Magmi to import.

RunQuickImport.php

namespace Test\Import\Controller\Adminhtml\Customimport;
class RunQuickImport extends \Magento\Backend\App\Action
{
public function execute()
    {
    $csv_data =readcsv file ;
    foreach($csv_data as $row){
       $dp = Magmi_DataPumpFactory::getDataPumpInstance("productimport");
       $dp->beginImportSession("default", "xcreate");
       $item = "product field array";
       $run = $dp->ingest($item);
       $dp->endImportSession();
         }
     }
}

Question is How to include Magmi file in controller ?

I had tried using following.

require_once '/public_html/magmi/inc/magmi_defs.php';
require_once '/public_html/magmi/integration/inc/magmi_datapump.php';

but not working

2
  • 1
    Did you have any solution? Dec 26 '18 at 9:50
  • 1
    yes you can add same code in top of module's registration.php file. Dec 26 '18 at 9:51
1

You can include magmi file in your controller like Below:

require_once(dirname(__FILE__) . "/../../../../../magmi/inc/magmi_defs.php");
require_once(dirname(__FILE__) . "/../../../../../magmi/integration/inc/magmi_datapump.php");
1

-> If Your magmi folder on magentoRoot/pub then

registration.php

<?php
require_once BP . "/pub/magmi/plugins/inc/magmi_datasource.php";
require_once BP . "/pub/magmi/integration/inc/productimport_datapump.php";

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'VendoreName_ModuleName',
    __DIR__
);

-> If your magmi folder On Magento Root Then

registration.php

<?php
require_once BP . "/magmi/plugins/inc/magmi_datasource.php";
require_once BP . "/magmi/integration/inc/productimport_datapump.php";

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'VendoreName_ModuleName',
    __DIR__
);

Try This Code

public function execute()
{
    $csv_data =readcsv file ;
    foreach($csv_data as $row){
        $configProduct = new \Magmi_ProductImport_DataPump();
        $item = "product field array"; = "product field array";;
        $configProduct->beginImportSession("default", "xcreate");// Mode: xcreate, create, update
        $run = $configProduct->ingest($item);
        $configProduct->endImportSession();
    }
}
0

Below Code use in top of module's registration.php file.

require_once BP . "/magmi/plugins/inc/magmi_datasource.php";
require_once BP . "/magmi/integration/inc/productimport_datapump.php";

In Class file.

 $dp = new \Magmi_ProductImport_DataPump();
 $dp->beginImportSession("default", 'magmi mode');

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.