1

I would like to migrate products from magento 1 to magento 2 using core models instead of the migration toolkit provided by magento.

The reason is that the products need A LOT of modification in the process.

What i'd like to do is write a custom script that handles the models from both stores. So my idea was to do this:

<?php
use Magento\Framework\App\Bootstrap;

require __DIR__ . '/../app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$conn = $resource->getConnection();

// pointing to Mage.php from magento 1
require_once('../../www/app/Mage.php');
$app = Mage::app(Mage_Core_Model_App::ADMIN_STORE_ID);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$products = Mage::getModel('catalog/product')->getCollection();

foreach ($products as $product) {
    echo $product->getId() . "\n";
}

This fails because the BP constant has already been defined in magento 2.

PHP Notice:  Constant BP already defined in /path/to/old/store/app/Mage.php on line 29

Is there a way to use the model api of both magento 1 and magento 2 within one script?

Your Answer

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

Browse other questions tagged or ask your own question.