UB Data migration stuck on step 7

 Hello,
I’ve installed the UB Data migration tool successfully and everything run good when it reach the step 7 it import the sales but it is not moving to step 8.
with no error.  
please help….
Regards,
 

20 answers

Profile photo of Mall Staff 111140.00 $tone March 21, 2016
Public

Hi Ahmad Darwish,
Thank you working around with this tool.
Seem you did not “Select all” objects data in step 7?
Can you provide me some screenshot about your working?
Regards,
Mall.

#1
Profile photo of Mall Staff 111140.00 $tone March 21, 2016
Public

Hi Ahmad Darwish,
Let’s press the “Reset” button and then click to “Select all” check box and click to the “Start” button to try again this step.
And let’s me know how it goes.
Regards,
Mall.

#5
Profile photo of Mall Staff 111140.00 $tone March 21, 2016
Public

Hi Ahmad Darwish,

Let’s press the “Reset” button and then click to “Select all” check box and click to the “Start” button to try again this step.

Did you do as i suggest?
If yes, let’s provide me a file “dump.sql” of your Magento 1 database, we will check further to detect the root of issue as you said and tell you how to solve that.
Regards,
Mall.

#7
Profile photo of Mall Staff 111140.00 $tone March 22, 2016
Public

 Hi Ahmad Darwish,
Yes, i have tested this tool with your database, for this case we have to tuning some work flow in step 7.
So, let’s open the PHP file at path: /pub/ub-tool/protected/controllers/MigrateController.php
and find to the function with function name ‘actionStep7
and paste replace below function to solve the issue as you said:

public function actionStep7()
{
$step = MigrateSteps::model()->find("sorder = 7");
$result = MigrateSteps::checkStep($step->sorder);
if ($result['allowed']){
//declare objects to migrate
$sales_objects = array(
'order' => Yii::t('frontend', 'Sales Orders'),
'quote' => Yii::t('frontend', 'Sales Quote'),
'payment' => Yii::t('frontend', 'Sales Payments'),
'invoice' => Yii::t('frontend', 'Sales Invoices'),
'shipment' => Yii::t('frontend', 'Sales Shipments'),
'credit' => Yii::t('frontend', 'Sales Credit Memo'),
'bestseller' => Yii::t('frontend', 'Sales Bestsellers'),
'rule_coupon' => Yii::t('frontend', 'Sales Rules & Coupons')
);

//variables to log
$errors = array();
$migrated_sales_object_ids = isset(Yii::app()->session['migrated_sales_object_ids']) ? Yii::app()->session['migrated_sales_object_ids'] : array();
$migrated_order_ids = isset(Yii::app()->session['migrated_sales_order_ids']) ? Yii::app()->session['migrated_sales_order_ids'] : array();
$migrated_quote_ids = isset(Yii::app()->session['migrated_sales_quote_ids']) ? Yii::app()->session['migrated_sales_quote_ids'] : array();
$migrated_payment_ids = isset(Yii::app()->session['migrated_sales_payment_ids']) ? Yii::app()->session['migrated_sales_payment_ids'] : array();
$migrated_invoice_ids = isset(Yii::app()->session['migrated_sales_invoice_ids']) ? Yii::app()->session['migrated_sales_invoice_ids'] : array();
$migrated_shipment_ids = isset(Yii::app()->session['migrated_sales_shipment_ids']) ? Yii::app()->session['migrated_sales_shipment_ids'] : array();
$migrated_credit_ids = isset(Yii::app()->session['migrated_sales_credit_ids']) ? Yii::app()->session['migrated_sales_credit_ids'] : array();
$migrated_order_statuses = isset(Yii::app()->session['migrated_order_statuses']) ? Yii::app()->session['migrated_order_statuses'] : array();
$migrated_sales_rule_ids = isset(Yii::app()->session['migrated_sales_rule_ids']) ? Yii::app()->session['migrated_sales_rule_ids'] : array();
$migrated_sales_coupon_ids = isset(Yii::app()->session['migrated_sales_coupon_ids']) ? Yii::app()->session['migrated_sales_coupon_ids'] : array();

if (Yii::app()->request->isPostRequest && $step->status == MigrateSteps::STATUS_NOT_DONE){

//uncheck foreign key
Yii::app()->mage2->createCommand("SET FOREIGN_KEY_CHECKS=0")->execute();

$selected_objects = Yii::app()->request->getPost('selected_objects', array());
$selected_objects[] = 'bestseller';

if ($selected_objects){
//get migrated data from first step in session
$migrated_website_ids = isset(Yii::app()->session['migrated_website_ids']) ? Yii::app()->session['migrated_website_ids'] : array();
$str_website_ids = implode(',', $migrated_website_ids);

$migrated_store_ids = isset(Yii::app()->session['migrated_store_ids']) ? Yii::app()->session['migrated_store_ids'] : array();
$str_store_ids = implode(',', $migrated_store_ids);

$migrated_customer_ids = isset(Yii::app()->session['migrated_customer_ids']) ? Yii::app()->session['migrated_customer_ids'] : array();
$str_customer_ids = implode(',', $migrated_customer_ids);

$migrated_product_ids = isset(Yii::app()->session['migrated_product_ids']) ? Yii::app()->session['migrated_product_ids'] : array();
$str_product_ids = implode(',', $migrated_product_ids);

//Sales orders
if (in_array('order', $selected_objects) && !in_array('order', $migrated_sales_object_ids)){
//sales_order_status
$models = Mage1SalesOrderStatus::model()->findAll();
if ($models) {
foreach ($models as $model){
$model2 = Mage2SalesOrderStatus::model()->find("status = '{$model->status}'");
if (!$model2){
$model2 = new Mage2SalesOrderStatus();
$model2->status = $model->status;
}
$model2->label = $model->label;

if ($model2->save()){
$migrated_order_statuses[] = $model->status;

//sales_order_status_label
$condition = "status = '{$model->status}'";
if ($str_store_ids) {
$condition .= " AND store_id IN ({$str_store_ids})";
}
$models = Mage1SalesOrderStatusLabel::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesOrderStatusLabel();
$model2->attributes = $model->attributes;
$model2->store_id = $model->store_id;

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_order_status_state
$condition = "status = '{$model->status}'";
$models = Mage1SalesOrderStatusState::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = Mage2SalesOrderStatusState::model()->find("status = '{$model->status}' AND state = '{$model->state}'");
if (!$model2){
$model2 = new Mage2SalesOrderStatusState();
$model2->status = $model->status;
$model2->state = $model->state;
//this field not exists in Magento1
$model2->visible_on_front = 0;
}
$model2->is_default = $model->is_default;

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
}
}
}

//sales_order
$condition = "( store_id IN ({$str_store_ids}) OR store_id IS NULL )";
if ($str_customer_ids){
$condition .= " AND ( customer_id IN ({$str_customer_ids}) OR customer_id IS NULL )";
}
$sales_orders = Mage1SalesOrder::model()->findAll($condition);
if ($sales_orders) {
foreach ($sales_orders as $sales_order) {
$sales_order2 = new Mage2SalesOrder();
foreach ($sales_order2->attributes as $key => $value){
if (isset($sales_order->$key)){
/**
* Magento 2 only accept max length of store_name = 32 chars
* So we have to check length of store name here to split
*/
$val = $sales_order->$key;
if ( in_array($key, array('store_name', 'shipping_method', 'x_forwarded_for')) && strlen($val) > 32) {
$val = substr($val, 0, 32);
}
if ( in_array($key, array('applied_rule_ids')) && strlen($val) > 128) {
$val = substr($val, 0, 128);
}
$sales_order2->$key = $val;
}
}

if ($sales_order2->save()) {
$migrated_order_ids[] = $sales_order->entity_id;

//sales_order_address
$models = Mage1SalesOrderAddress::model()->findAll("parent_id = {$sales_order->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesOrderAddress();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_order_grid
$models = Mage1SalesOrderGrid::model()->findAll("entity_id = {$sales_order->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesOrderGrid();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_order_item
$models = Mage1SalesOrderItem::model()->findAll("order_id = {$sales_order->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesOrderItem();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$val = $model->$key;
/**
* Because Magento2 was change method to save weee_tax_applied to database:
* So we have to make convert this
*/
if ($key == 'weee_tax_applied'){
$val = json_encode(unserialize($val));
}
$model2->$key = $val;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_order_status_history
$models = Mage1SalesOrderStatusHistory::model()->findAll("parent_id = {$sales_order->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesOrderStatusHistory();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_order_tax
$models = Mage1SalesOrderTax::model()->findAll("order_id = {$sales_order->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesOrderTax();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}
if ($model2->save()){
//sales_order_tax_item
$items = Mage1SalesOrderTaxItem::model()->findAll("tax_id = {$model->tax_id}");
if ($items){
foreach ($items as $item){
$item2 = new Mage2SalesOrderTaxItem();
foreach ($item2->attributes as $key => $value){
if (isset($item->$key)){
$item2->$key = $item->$key;
}
}
//bellow fields was not exists in Magento1 -> note
$item2->amount = 0;
$item2->base_amount = 0;
$item2->real_amount = 0;
$item2->real_base_amount = 0;
$item2->associated_item_id = null;
$item2->taxable_item_type = '';

if (!$item2->save()) {
$errors[] = get_class($item2).": ".MigrateSteps::getStringErrors($item2->getErrors());
}
}
}
} else {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
} else {
$errors = MigrateSteps::getStringErrors($sales_order2->getErrors());
Yii::app()->user->setFlash('error', $errors);
} //end save a sales order
}
}

//sales_order_aggregated_created
$condition = "store_id IN ({$str_store_ids}) OR store_id is NULL";
$models = Mage1SalesOrderAggregatedCreated::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesOrderAggregatedCreated();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_order_aggregated_updated
$condition = "store_id IN ({$str_store_ids}) OR store_id is NULL";
$models = Mage1SalesOrderAggregatedUpdated::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesOrderAggregatedUpdated();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}

$migrated_sales_object_ids[] = 'order';
}//end migrate orders

//Sales quote
if (in_array('quote', $selected_objects) && !in_array('quote', $migrated_sales_object_ids)){
//quote
//$condition = "( store_id IN ({$str_store_ids}) OR store_id IS NULL ) AND ( customer_id IN ({$str_customer_ids}) OR customer_id IS NULL )";
$condition = "( store_id IN ({$str_store_ids}) OR store_id IS NULL )";
$quotes = Mage1SalesQuote::model()->findAll($condition);
if ($quotes){
foreach ($quotes as $quote){
$quote2 = new Mage2SalesQuote();
foreach ($quote2->attributes as $key => $value){
if (isset($quote->$key)){
$quote2->$key = $quote->$key;
}
}
$quote2->store_id = $quote->store_id;
if ($quote2->save()){
$migrated_quote_ids[] = $quote->entity_id;

//quote_item
$models = Mage1SalesQuoteItem::model()->findAll("quote_id = {$quote->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesQuoteItem();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if ($model2->save()){
//quote_item_option
$item_options = Mage1SalesQuoteItemOption::model()->findAll("item_id = {$model->item_id}");
if ($item_options){
foreach ($item_options as $item_option){
$item_option2 = new Mage2SalesQuoteItemOption();
foreach ($item_option2->attributes as $key => $value){
if (isset($item_option->$key)){
$item_option2->$key = $item_option->$key;
}
}

if (!$item_option2->save()) {
$errors[] = get_class($item_option2).": ".MigrateSteps::getStringErrors($item_option2->getErrors());
}
}
}
} else {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//quote_payment
$models = Mage1SalesQuotePayment::model()->findAll("quote_id = {$quote->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesQuotePayment();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}

//quote_address
$models = Mage1SalesQuoteAddress::model()->findAll("quote_id = {$quote->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesQuoteAddress();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
/**
* Have some new max length rule in Magento 2
* So we have to check length to split here
*/
$val = $model->$key;
if ( in_array($key, array('street', 'region', 'shipping_method', 'city')) && strlen($val) > 40) {
$val = substr($val, 0, 40);
} else if (in_array($key, array('firstname', 'lastname', 'postcode', 'telephone', 'fax')) && strlen($val) > 20) {
$val = substr($val, 0, 20);
} else if (in_array($key, array('country_id')) && strlen($val) > 30) {
$val = substr($val, 0, 30);
}

$model2->$key = $val;
}
}
if ($model2->save()){
//quote_address_item
$address_items = Mage1SalesQuoteAddressItem::model()->findAll("quote_address_id = {$model->address_id}");
if ($address_items){
foreach ($address_items as $address_item){
$address_item2 = new Mage2SalesQuoteAddressItem();
foreach ($address_item2->attributes as $key => $value){
if (isset($address_item->$key)){
$address_item2->$key = $address_item->$key;
}
}

if (!$address_item2->save()) {
$errors[] = get_class($address_item2).": ".MigrateSteps::getStringErrors($address_item2->getErrors());
}
}
}
//quote_shipping_rate
$shipping_rates = Mage1SalesQuoteShippingRate::model()->findAll("address_id = {$model->address_id}");
if ($shipping_rates){
foreach ($shipping_rates as $shipping_rate){
$shipping_rate2 = new Mage2SalesQuoteShippingRate();
foreach ($shipping_rate2->attributes as $key => $value){
if (isset($shipping_rate->$key)){
$shipping_rate2->$key = $shipping_rate->$key;
}
}

if (!$shipping_rate2->save()) {
$errors[] = get_class($shipping_rate2).": ".MigrateSteps::getStringErrors($shipping_rate2->getErrors());
}
}
}
} else {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
} else {
$errors[] = get_class($quote2).": ".MigrateSteps::getStringErrors($quote2->getErrors());
}
}
}

$migrated_sales_object_ids[] = 'quote';
}//end sales quote

//Sales payment
if (in_array('payment', $selected_objects) && !in_array('payment', $migrated_sales_object_ids)){
if (in_array('order', $migrated_sales_object_ids)){
if ($migrated_order_ids) {
$str_order_ids = implode(',', $migrated_order_ids);
$condition = "parent_id IN ({$str_order_ids})";
//sales_order_payment
$sales_payments = Mage1SalesOrderPayment::model()->findAll($condition);
if ($sales_payments){
foreach ($sales_payments as $sales_payment){
$sales_payment2 = new Mage2SalesOrderPayment();
foreach($sales_payment2->attributes as $key => $value){
if (isset($sales_payment->$key)){
/**
* Have some new max length rule in Magento 2
* So we have to check length to split here
*/
$val = $sales_payment->$key;
if ( in_array($key, array('po_number', 'cc_number_enc')) && strlen($val) > 32) {
$val = substr($val, 0, 32);
}

$sales_payment2->$key = $val;
}
}
//because the this field name was changed in Magento 2
$sales_payment2->cc_last_4 = isset($sales_payment->cc_last4) ? $sales_payment->cc_last4 : null;
if ($sales_payment2->save()){
//sales_payment_transaction
$models = Mage1SalesPaymentTransaction::model()->findAll("payment_id = {$sales_payment->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesPaymentTransaction();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
} else {
$errors[] = get_class($sales_payment2).": ".MigrateSteps::getStringErrors($sales_payment2->getErrors());
}
}
}

//sales_refunded_aggregated
$condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
$models = Mage1SalesRefundedAggregated::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesRefundedAggregated();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_refunded_aggregated_order
$condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
$models = Mage1SalesRefundedAggregatedOrder::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesRefundedAggregatedOrder();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
}

$migrated_sales_object_ids[] = 'payment';
} else {
Yii::app()->user->setFlash('note', Yii::t('frontend', "Before migrate the Sales Payments, you have to migrate the Sales Orders first."));
}
}//end sales payment

//Sales invoice
if (in_array('invoice', $selected_objects) && !in_array('invoice', $migrated_sales_object_ids)){
if (in_array('order', $migrated_sales_object_ids)){
if ($migrated_order_ids) {
$condition = "( store_id IN ({$str_store_ids}) OR store_id IS NULL )";
$str_order_ids = implode(',', $migrated_order_ids);
$condition .= " AND order_id IN ({$str_order_ids})";

//sales_invoice
$sales_invoices = Mage1SalesInvoice::model()->findAll($condition);
if ($sales_invoices){
foreach ($sales_invoices as $sales_invoice){
$sales_invoice2 = new Mage2SalesInvoice();
foreach ($sales_invoice2->attributes as $key => $value){
if (isset($sales_invoice->$key)){
$sales_invoice2->$key = $sales_invoice->$key;
}
}

if ($sales_invoice2->save()){
$migrated_invoice_ids[] = $sales_invoice->entity_id;

//sales_invoice_grid
$condition = "entity_id = {$sales_invoice->entity_id}";
$models = Mage1SalesInvoiceGrid::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesInvoiceGrid();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

//this field was not exists in Magento1
$model2->updated_at = null;
if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_invoice_item
$condition = "parent_id = {$sales_invoice->entity_id}";
$models = Mage1SalesInvoiceItem::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesInvoiceItem();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$val = $model->$key;
/**
* Because Magento2 was change method to save weee_tax_applied to database:
* So we have to make convert this
*/
if ($key == 'weee_tax_applied'){
$val = json_encode(unserialize($val));
}
$model2->$key = $val;
}
}
//this field was not exists in Magento1
$model2->tax_ratio = null;

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_invoice_comment
$condition = "parent_id = {$sales_invoice->entity_id}";
$models = Mage1SalesInvoiceComment::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesInvoiceComment();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
}
}

//sales_invoiced_aggregated
$condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
$models = Mage1SalesInvoicedAggregated::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesInvoicedAggregated();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_invoiced_aggregated_order
$condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
$models = Mage1SalesInvoicedAggregatedOrder::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesInvoicedAggregatedOrder();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
}
}

$migrated_sales_object_ids[] = 'invoice';
} else {
Yii::app()->user->setFlash('note', Yii::t('frontend', "Before migrate the Sales Invoices, you have to migrate the Sales Orders first."));
}
}//end sales invoice migration

//Sales shipment
if (in_array('shipment', $selected_objects) && !in_array('shipment', $migrated_sales_object_ids)){
if (in_array('order', $migrated_sales_object_ids)){
if ($migrated_order_ids) {
$condition = "( store_id IN ({$str_store_ids}) OR store_id IS NULL )";
$str_order_ids = implode(',', $migrated_order_ids);
$condition .= " AND order_id IN ({$str_order_ids})";

//sales_shipment
$sales_shipments = Mage1SalesShipment::model()->findAll($condition);
if ($sales_shipments){
foreach($sales_shipments as $sales_shipment){
$sales_shipment2 = new Mage2SalesShipment();
foreach ($sales_shipment2->attributes as $key => $value){
if (isset($sales_shipment->$key)){
$sales_shipment2->$key = $sales_shipment->$key;
}
}

if ($sales_shipment2->save()){
$migrated_shipment_ids[] = $sales_shipment->entity_id;

//sales_shipment_grid
$models = Mage1SalesShipmentGrid::model()->findAll("entity_id = {$sales_shipment->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesShipmentGrid();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}
$model2->store_id = $model->store_id;
//some new fields and required in Magento 2
$model2->updated_at = null;
$model2->customer_name = $model->shipping_name;
if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_shipment_item
$models = Mage1SalesShipmentItem::model()->findAll("parent_id = {$sales_shipment->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesShipmentItem();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}
if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_shipment_track
$models = Mage1SalesShipmentTrack::model()->findAll("parent_id = {$sales_shipment->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesShipmentTrack();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}
if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_shipment_comment
$models = Mage1SalesShipmentComment::model()->findAll("parent_id = {$sales_shipment->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesShipmentComment();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}
if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
}
}
}
//sales_shipping_aggregated
$condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
$models = Mage1SalesShippingAggregated::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesShippingAggregated();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_shipping_aggregated_order
$condition = "store_id IN ({$str_store_ids}) OR store_id IS NULL";
$models = Mage1SalesShippingAggregatedOrder::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesShippingAggregatedOrder();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
}
$migrated_sales_object_ids[] = 'shipment';
}else {
Yii::app()->user->setFlash('note', Yii::t('frontend', "Before migrate the Sales Shipments, you have to migrate the Sales Orders first."));
}
}//end sales shipment migration

//Sales credit memo
if (in_array('credit', $selected_objects) && !in_array('credit', $migrated_sales_object_ids)){
if (in_array('order', $migrated_sales_object_ids)){
if ($migrated_order_ids) {
$condition = "( store_id IN ({$str_store_ids}) OR store_id IS NULL )";
$str_order_ids = implode(',', $migrated_order_ids);
$condition .= " AND order_id IN ({$str_order_ids})";

//sales_creditmemo
$sales_credits = Mage1SalesCreditmemo::model()->findAll($condition);
if ($sales_credits){
foreach ($sales_credits as $sales_credit){
$sales_credit2 = new Mage2SalesCreditmemo();
foreach ($sales_credit2->attributes as $key => $value){
if (isset($sales_credit->$key)){
$sales_credit2->$key = $sales_credit->$key;
}
}

if ($sales_credit2->save()){
//this for log
$migrated_credit_ids[] = $sales_credit->store_id;

//sales_creditmemo_grid
$models = Mage1SalesCreditmemoGrid::model()->findAll("entity_id = {$sales_credit->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesCreditmemoGrid();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}
//some new fields and required in Magento 2
$model2->updated_at = null;
$model2->customer_name = $model->billing_name;
if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_creditmemo_item
$models = Mage1SalesCreditmemoItem::model()->findAll("parent_id = {$sales_credit->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesCreditmemoItem();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$val = $model->$key;
/**
* Because Magento2 was change method to save weee_tax_applied to database:
* So we have to make convert this
*/
if ($key == 'weee_tax_applied'){
$val = json_encode(unserialize($val));
}
$model2->$key = $val;
}
}
//this field was not exists in Magento1
$model2->tax_ratio = null;
if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
//sales_creditmemo_comment
$models = Mage1SalesCreditmemoComment::model()->findAll("parent_id = {$sales_credit->entity_id}");
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesCreditmemoComment();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}
if (!$model2->save()){
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
}
}
}
}

$migrated_sales_object_ids[] = 'credit';
} else {
Yii::app()->user->setFlash('note', Yii::t('frontend', "Before migrate the Sales Credit Memo, you have to migrate the Sales Orders first."));
}
}//End Sales credit memo migration

//Sales bestsellers
if (in_array('bestseller', $selected_objects) && !in_array('bestseller', $migrated_sales_object_ids)){
if ($migrated_store_ids && $migrated_product_ids){
$condition = "store_id IN ({$str_store_ids}) AND product_id IN ({$str_product_ids})";

//sales_bestsellers_aggregated_daily
$models = Mage1SalesBestsellersDaily::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesBestsellersDaily();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}

//sales_bestsellers_aggregated_monthly
$models = Mage1SalesBestsellersMonthly::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesBestsellersMonthly();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}

//sales_bestsellers_aggregated_yearly
$models = Mage1SalesBestsellersYearly::model()->findAll($condition);
if ($models){
foreach ($models as $model){
$model2 = new Mage2SalesBestsellersYearly();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}

if (!$model2->save()) {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}
$migrated_sales_object_ids[] = 'bestseller';
}
}//end sales bestsellers

//Sales rules & coupons
if (in_array('rule_coupon', $selected_objects) && !in_array('rule_coupon', $migrated_sales_object_ids)){
if ($migrated_store_ids && $migrated_product_ids){
//salesrule
$models = Mage1Salesrule::model()->findAll();
if ($models) {
foreach ($models as $model){
$model2 = new Mage2Salesrule();
foreach ($model2->attributes as $key => $value){
if (isset($model->$key)){
$model2->$key = $model->$key;
}
}
//replace model names because it was changed in magento 2
$model2->conditions_serialized = MigrateSteps::replaceSalesRuleModels($model2->conditions_serialized);
$model2->actions_serialized = MigrateSteps::replaceSalesRuleModels($model2->actions_serialized);

if ($model2->save()) {
$migrated_sales_rule_ids[] = $model2->rule_id;

//salesrule_coupon
$coupons = Mage1SalesruleCoupon::model()->findAll("rule_id = {$model2->rule_id}");
if ($coupons){
foreach ($coupons as $coupon){
$coupon2 = new Mage2SalesruleCoupon();
foreach ($coupon2->attributes as $key => $value){
if (isset($coupon->$key)){
$coupon2->$key = $coupon->$key;
}
}
if ($coupon2->save()){
$migrated_sales_coupon_ids[] = $coupon2->coupon_id;

//salesrule_coupon_usage
$coupon_usages = Mage1SalesruleCouponUsage::model()->findAll("coupon_id = {$coupon2->coupon_id}");
if ($coupon_usages){
foreach($coupon_usages as $coupon_usage){
$coupon_usage2 = new Mage2SalesruleCouponUsage();
foreach ($coupon_usage2->attributes as $key => $value){
if (isset($coupon_usage->$key)){
$coupon_usage2->$key = $coupon_usage->$key;
}
}
if (!$coupon_usage2->save()) {
$errors[] = get_class($coupon_usage2).": ".MigrateSteps::getStringErrors($coupon_usage2->getErrors());
}
}
}
}
}
}
//salesrule_label
$labels = Mage1SalesruleLabel::model()->findAll("rule_id = {$model2->rule_id}");
if ($labels){
foreach ($labels as $label){
$label2 = new Mage2SalesruleLabel();
foreach ($label2->attributes as $key => $value){
if (isset($label->$key)){
$label2->$key = $label->$key;
}
}

$label2->save();

if (!$label2->save()) {
$errors[] = get_class($label2).": ".MigrateSteps::getStringErrors($label2->getErrors());
}
}
}
//salesrule_product_attribute
$condition = "rule_id = {$model2->rule_id}";
if ($migrated_website_ids){
$condition .= " AND website_id IN ({$str_website_ids})";
}
$product_attributes = Mage1SalesruleProductAttribute::model()->findAll($condition);
if ($product_attributes){
foreach ($product_attributes as $product_attribute) {
$attrId2 = MigrateSteps::getMage2AttributeId($product_attribute->attribute_id, 4);
$strCon = "rule_id = $product_attribute->rule_id AND website_id = $product_attribute->website_id AND customer_group_id = $product_attribute->customer_group_id AND attribute_id = $attrId2";
if ( !Mage2SalesruleProductAttribute::model()->find($strCon) ) {
$product_attribute2 = new Mage2SalesruleProductAttribute();
foreach ($product_attribute2->attributes as $key => $value){
if (isset($product_attribute->$key)){
$product_attribute2->$key = $product_attribute->$key;
}
}
$product_attribute2->attribute_id = $attrId2;

if (!$product_attribute2->save()) {
$errors[] = get_class($product_attribute2).": ".MigrateSteps::getStringErrors($product_attribute2->getErrors());
}
}
}
}
//salesrule_website
$r_websites = Mage1SalesruleWebsite::model()->findAll($condition);
if ($r_websites){
foreach ($r_websites as $r_website){
$r_website2 = new Mage2SalesruleWebsite();
foreach ($r_website2->attributes as $key => $value){
if (isset($r_website->$key)){
$r_website2->$key = $r_website->$key;
}
}
if (!$r_website2->save()) {
$errors[] = get_class($r_website2).": ".MigrateSteps::getStringErrors($r_website2->getErrors());
}
}
}
//salesrule_customer
$r_customers = Mage1SalesruleCustomer::model()->findAll("rule_id = {$model2->rule_id}");
if ($r_customers){
foreach ($r_customers as $r_customer){
$r_customer2 = new Mage2SalesruleCustomer();
foreach ($r_customer2->attributes as $key => $value){
if (isset($r_customer->$key)){
$r_customer2->$key = $r_customer->$key;
}
}
if (!$r_customer2->save()) {
$errors[] = get_class($r_customer2).": ".MigrateSteps::getStringErrors($r_customer2->getErrors());
}
}
}
//salesrule_customer_group
$r_customer_groups = Mage1SalesruleCustomerGroup::model()->findAll("rule_id = {$model2->rule_id}");
if ($r_customer_groups){
foreach ($r_customer_groups as $r_customer_group){
$r_customer_group2 = new Mage2SalesruleCustomerGroup();
foreach ($r_customer_group2->attributes as $key => $value){
if (isset($r_customer_group->$key)){
$r_customer_group2->$key = $r_customer_group->$key;
}
}
if (!$r_customer_group2->save()) {
$errors[] = get_class($r_customer_group2).": ".MigrateSteps::getStringErrors($r_customer_group2->getErrors());
}
}
}
} else {
$errors[] = get_class($model2).": ".MigrateSteps::getStringErrors($model2->getErrors());
}
}
}

$migrated_sales_object_ids[] = 'rule_coupon';
}
}//end sales rules & coupons

} else {
Yii::app()->user->setFlash('note', Yii::t('frontend', 'You have not selected any Object yet.'));
}

//Update step status
if (sizeof($migrated_sales_object_ids) > sizeof(Yii::app()->session['migrated_sales_object_ids'])) {
if (sizeof($migrated_sales_object_ids) == sizeof($sales_objects)){
$step->status = MigrateSteps::STATUS_DONE;
} else {
$step->status = MigrateSteps::STATUS_NOT_DONE;
}

$step->migrated_data = json_encode(array(
'order_statuses' => $migrated_order_statuses,
'sales_object_ids' => $migrated_sales_object_ids,
'sales_order_ids' => $migrated_order_ids,
'sales_quote_ids' => $migrated_quote_ids,
'sales_payment_ids' => $migrated_payment_ids,
'sales_invoice_ids' => $migrated_invoice_ids,
'sales_shipment_ids' => $migrated_shipment_ids,
'sales_credit_ids' => $migrated_credit_ids,
'sales_rule_ids' => $migrated_sales_rule_ids,
'sales_coupon_ids' => $migrated_sales_coupon_ids
));
if ($step->update()) {

//check foreign key
Yii::app()->mage2->createCommand("SET FOREIGN_KEY_CHECKS=1")->execute();

//update session
Yii::app()->session['migrated_order_statuses'] = $migrated_order_statuses;
Yii::app()->session['migrated_sales_object_ids'] = $migrated_sales_object_ids;
Yii::app()->session['migrated_sales_order_ids'] = $migrated_order_ids;
Yii::app()->session['migrated_sales_quote_ids'] = $migrated_quote_ids;
Yii::app()->session['migrated_sales_payment_ids'] = $migrated_payment_ids;
Yii::app()->session['migrated_sales_invoice_ids'] = $migrated_invoice_ids;
Yii::app()->session['migrated_sales_shipment_ids'] = $migrated_shipment_ids;
Yii::app()->session['migrated_sales_credit_ids'] = $migrated_credit_ids;
Yii::app()->session['migrated_sales_rule_ids'] = $migrated_sales_rule_ids;
Yii::app()->session['migrated_sales_coupon_ids'] = $migrated_sales_coupon_ids;

$message = '<ul>';
$message .= '<li>'.Yii::t('frontend', 'Migrated successfully.').'</li>';
if ($migrated_order_statuses)
$message .= '<li>'. Yii::t('frontend', "Total Orders Statuses migrated: %s2.", array('%s2' => sizeof($migrated_order_statuses))).'</li>';
if ($migrated_order_ids)
$message .= '<li>'. Yii::t('frontend', "Total Sales Orders migrated: %s1.", array('%s1' => sizeof($migrated_order_ids))).'</li>';
if ($migrated_quote_ids)
$message .= '<li>'. Yii::t('frontend', "Total Sales Quote migrated: %s3.", array('%s3' => sizeof($migrated_quote_ids))).'</li>';
if ($migrated_invoice_ids)
$message .= '<li>'. Yii::t('frontend', "Total Sales Invoices migrated: %s4.", array('%s4' => sizeof($migrated_invoice_ids))).'</li>';
if ($migrated_shipment_ids)
$message .= '<li>'. Yii::t('frontend', "Total Sales Shipments migrated: %s5.", array('%s5' => sizeof($migrated_shipment_ids))).'</li>';
if ($migrated_credit_ids)
$message .= '<li>'. Yii::t('frontend', "Total Sales Credit Memo migrated: %s6.", array('%s6' => sizeof($migrated_credit_ids))).'</li>';
if ($migrated_sales_rule_ids)
$message .= '<li>'. Yii::t('frontend', "Total Sales Rules migrated: %s7.", array('%s7' => sizeof($migrated_sales_rule_ids))).'</li>';
if ($migrated_sales_coupon_ids)
$message .= '<li>'. Yii::t('frontend', "Total Sales Coupons migrated: %s8.", array('%s8' => sizeof($migrated_sales_coupon_ids))).'</li>';
$message .= '</ul>';

Yii::app()->user->setFlash('success', $message);
}
}

//alert errors if exists
if ($errors){
$strErrors = implode('<br/>', $errors);
Yii::app()->user->setFlash('error', $strErrors);
}
}//end post request
else{
if ($step->status == MigrateSteps::STATUS_DONE){
Yii::app()->user->setFlash('note', Yii::t('frontend', "This step was finished. If you want to update data of this step, the first you have to click to 'Reset' button."));
}
}

$this->render("step{$step->sorder}", array('step' => $step, 'sale_objects' => $sales_objects));
}else{
Yii::app()->user->setFlash('note', Yii::t('frontend', "The first you need to finish the %s.", array("%s" => ucfirst($result['back_step']))));
$this->redirect(array($result['back_step']));
}
}

and press the “Reset” button and restart the data migration in step 7 after your changing.
And let’s me know how it goes.
Regards,
Mall.

#10
Profile photo of Earl Augustine Elnar 100.00 $tone April 21, 2016
Public

Hi Mall,
 
After I successfully finished step 7 and whenever i click next button this is the error message that it will display. The system is unable to find the requested action “step8”.
 
Thank you,
Earl

#14
Profile photo of jaya prakash 20.00 $tone April 5, 2018
Public

Hi Mall,
Sales Orders (172296)
Sales Quote (63475)
Sales Payments (172366)
Sales Invoices (3273)
Sales Shipments (17053)
Sales Credit Memo (24)
migrate/step7 am replace the function after i got not server error .
if am the script “clear-test-orders” run success.
Regards,
Jayaprakash.K

#17
Profile photo of ubdev Staff 39740.00 $tone April 6, 2018
Public

Hi Jayaprakash, 
We wonder if you’re using our old migration script on Github? If that’s the case, it’s pity that we no longer maintain such outdated script. Please consider using our Pro version here.
Meanwhile, we could not keep track of your purchase. Our technical support requires active subscription though.
Regards,
Ubertheme team

#18
Profile photo of hasaa hasnaa 20.00 $tone August 6, 2018
Public

Hi Mall,
Thank you for your question, but even I’ve replaced the function step7()  by the code above I still can’t move to the step 8, because of :
sales Rules & Coupons (0 rules, 0 coupons);
Please could help me?

#19
Profile photo of Mall Staff 111140.00 $tone August 6, 2018
Public

Hi hasnaa,
Please submit a new ticket for your issues and provide me information about your instance:
+ Admin credentials and URL to back-end
+ SSH credentials and path to Magento folder
I will help to check further and reply you more later.
Regards,
Mall.
 
 

#20

Please login or Register to Submit Answer

Written By

Comments