Skip to content

Instantly share code, notes, and snippets.

@ppassmannpriv
Created September 29, 2015 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppassmannpriv/8277488800efa7948431 to your computer and use it in GitHub Desktop.
Save ppassmannpriv/8277488800efa7948431 to your computer and use it in GitHub Desktop.
Small php script which will reassign orders to the correct customers
<?php
require_once('../../app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('max_execution_time', 3000);
echo '<pre>';
$fromDate = date('Y-m-d H:i:s', 1420070400);
$toDate = date('Y-m-d H:i:s', 1443526700);
$_filename = 'check.log';
$_orders = Mage::getModel('sales/order')->getCollection()
->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));
$_customerModel = Mage::getModel("customer/customer");
$_customer = false;
foreach($_orders as $_order):
$_check = 'false';
if($_order->getCustomerId() !== NULL):
$_customer = $_customerModel->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->load($_order->getCustomerId());
$_logstring = 'Orderid: '.$_order->getIncrementId().' - OrderEmail: '.$_order->getCustomerEmail().' - CustomerEmail: '.$_customer->getEmail();
if($_customer->getEmail() == $_order->getCustomerEmail()):
$_check = 'true';
else:
$_orderCustomer = $_customerModel->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($_order->getCustomerEmail());
if($_orderCustomer && $_orderCustomer->getEntityId()):
$_order->setCustomerId($_orderCustomer->getEntityId());
$_order->save();
endif;
$_logstring .= ' - CustomerID: '.$_customer->getEntityId().' - OrderCustomerID: '.$_orderCustomer->getEntityId();
$_check = 'ERROR';
endif;
else:
$_customer = false;
$_logstring = 'Orderid: '.$_order->getIncrementId().' - OrderEmail: '.$_order->getCustomerEmail().' - CustomerEmail: no Customer';
endif;
Mage::log($_logstring, null, $_filename);
Mage::log($_check, null, $_filename);
Mage::log('------------------------', null, $_filename);
endforeach;
echo 'finish';
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment