I'm in a serious need of help as I need to alter the lifetime sales figure on my store's backend. It's for taxation purpose and I'm clueless about how I can reduce the digits mentioned in the stats. Please help me.


To alter the lifetime sales, you can do this :


/**** Database Connection ****/
$servername = "localhost";
$username = "your_db_user";
$password = "Your_Db_Pass";
$dbname = "your_db_name";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password, array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
    // set the PDO error mode to exception
    echo "Connected successfully<br/>";
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage() . "<br/>";
/**** End Database Connection ****/

$getQuery = "SELECT qty_ordered, product_id FROM sales_flat_order_item";

$result = $conn->query($getQuery);

foreach ($result as $row) {
    // To reduce by 10%, for example
    $newQty = ceil($row['qty_ordered'] * .90);
    echo "ID = " . $row['product_id'] . " Original Qty = " . $row['qty_ordered'] . "<br/>";
    echo "New Qty = $newQty<br/>";
    $setQuery = "UPDATE sales_flat_order_item SET qty_ordered = $newQty WHERE product_id = " . $row['product_id'];

Put that into a script in your magento root and navigate to it in your browser. After you run, in the Magento backend go to Reports->Refresh Statistics and reindex all reports. I'm not sure how much you want to reduce the figures by, but if you manipulate this line $newQty = ceil($row['qty_ordered'] * .90); you should be able to get the result you are looking for.

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.