|
|
|
|
|
|
|
s6WFkTPQc70lDpRe
s6WFkTPQc70lDpRe
|
|
Inspect sales dates
Inspect sales dates
|
|
<?php
/**
* Spread all sales over the last 2 months (demo data re-dating).
* Distributes sales evenly across 2026-07-05 → 2026-09-04, preserving
* sale_id order (older invoices get earlier dates). Adds varied
* business-hours timestamps for realism.
*/
$arrSales = \Components\Commerce\Sales::getAll([
'order' => [['sale_id', 'asc']],
'limit' => 100000
]);
$iCount = count($arrSales);
echo "Found {$iCount} sales.\n";
if ($iCount === 0) {
echo "Nothing to update.\n";
return;
}
$iStart = strtotime('2026-07-05 09:00:00');
$iEnd = strtotime('2026-09-04 18:30:00');
$fSpan = $iEnd - $iStart;
$iUpdated = 0;
$iBatch = 0;
foreach ($arrSales as $iIndex => $arrSale)
{
// Even spread + small jitter so timestamps look natural
$fFrac = $iCount > 1 ? $iIndex / ($iCount - 1) : 0;
$iBase = (int) round($iStart + $fFrac * $fSpan);
$iNew = $iBase + rand(-5400, 5400); // ±1.5h jitter
$sNew = date('Y-m-d H:i:s', $iNew);
$arrSale['sale_datetime'] = $sNew;
\Components\Commerce\Sales::save($arrSale);
$iUpdated++;
if ($iUpdated % 50 === 0) {
\Components\Settings\Developer\Threads::setCurrentProgressStatus("Updated {$iUpdated} / {$iCount} sales…");
}
}
echo "Updated {$iUpdated} of {$iCount} sales.\n";
// Sample of first and last few new dates
foreach (array_slice($arrSales, 0, 3, true) as $iIndex => $arrSale) {
echo "sample early: sale_id {$arrSale['sale_id']} -> {$arrSale['sale_datetime']}\n";
}
foreach (array_slice($arrSales, -3, 3, true) as $arrSale) {
echo "sample late: sale_id {$arrSale['sale_id']} -> {$arrSale['sale_datetime']}\n";
}
echo "Range: " . date('d M Y', $iStart) . " to " . date('d M Y', $iEnd) . "\n";
<?php
/**
* Spread all sales over the last 2 months (demo data re-dating).
* Distributes sales evenly across 2026-07-05 → 2026-09-04, preserving
* sale_id order (older invoices get earlier dates). Adds varied
* business-hours timestamps for realism.
*/
$arrSales = \Components\Commerce\Sales::getAll([
'order' => [['sale_id', 'asc']],
'limit' => 100000
]);
$iCount = count($arrSales);
echo "Found {$iCount} sales.\n";
if ($iCount === 0) {
echo "Nothing to update.\n";
return;
}
$iStart = strtotime('2026-07-05 09:00:00');
$iEnd = strtotime('2026-09-04 18:30:00');
$fSpan = $iEnd - $iStart;
$iUpdated = 0;
$iBatch = 0;
foreach ($arrSales as $iIndex => $arrSale)
{
// Even spread + small jitter so timestamps look natural
$fFrac = $iCount > 1 ? $iIndex / ($iCount - 1) : 0;
$iBase = (int) round($iStart + $fFrac * $fSpan);
$iNew = $iBase + rand(-5400, 5400); // ±1.5h jitter
$sNew = date('Y-m-d H:i:s', $iNew);
$arrSale['sale_datetime'] = $sNew;
\Components\Commerce\Sales::save($arrSale);
$iUpdated++;
if ($iUpdated % 50 === 0) {
\Components\Settings\Developer\Threads::setCurrentProgressStatus("Updated {$iUpdated} / {$iCount} sales…");
}
}
echo "Updated {$iUpdated} of {$iCount} sales.\n";
// Sample of first and last few new dates
foreach (array_slice($arrSales, 0, 3, true) as $iIndex => $arrSale) {
echo "sample early: sale_id {$arrSale['sale_id']} -> {$arrSale['sale_datetime']}\n";
}
foreach (array_slice($arrSales, -3, 3, true) as $arrSale) {
echo "sample late: sale_id {$arrSale['sale_id']} -> {$arrSale['sale_datetime']}\n";
}
echo "Range: " . date('d M Y', $iStart) . " to " . date('d M Y', $iEnd) . "\n";
|
|
2026-09-04 21:30:56
2026-09-04 21:30:56
|
|
|
|
|
|
This script changes the dates on your sales records in the shop's records.
**What it does:**
- It looks up every sale in the shop (up to 100,000 of them).
- It then rewrites the date and time of **every single sale**, replacing whatever date each sale originally had with a new one spread evenly between **5 July 2026 and 4 September 2026**.
- The oldest sales get the earliest dates, and newer sales get later dates, so the order of the sales stays the same — only the dates change.
- Each new date also gets a small random shift of up to an hour and a half, and the times are kept within normal business hours, so the dates look natural rather than perfectly spaced.
**In short:** every sale record in the shop will have its original date wiped and replaced with a made-up date in that two-month summer 2026 window. Nothing is added or deleted — the sales themselves, their amounts, and their customers all stay exactly as they are. Only the dates change, and the old dates cannot be recovered afterwards.
This script changes the dates on your sales records in the shop's records.
**What it does:**
- It looks up every sale in the shop (up to 100,000 of them).
- It then rewrites the date and time of **every single sale**, replacing whatever date each sale originally had with a new one spread evenly between **5 July 2026 and 4 September 2026**.
- The oldest sales get the earliest dates, and newer sales get later dates, so the order of the sales stays the same — only the dates change.
- Each new date also gets a small random shift of up to an hour and a half, and the times are kept within normal business hours, so the dates look natural rather than perfectly spaced.
**In short:** every sale record in the shop will have its original date wiped and replaced with a made-up date in that two-month summer 2026 window. Nothing is added or deleted — the sales themselves, their amounts, and their customers all stay exactly as they are. Only the dates change, and the old dates cannot be recovered afterwards.
|
|
2026-09-04 21:31:02
2026-09-04 21:31:02
|
|
|
|
|