πŸš€ Hostinger Optimized
πŸ–₯️ Server: LiteSpeed
πŸ’» System: Linux s20058.bom1.stableserver.net 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64
πŸ‘€ User: skhata (1324)
🐘 PHP: 8.4.20
🚫 Disabled: ✨ NONE

πŸ’» Terminal

πŸ“ /home/skhata/chandrasons.com/public
$

πŸ“„ RevertChandraPharmaPricesToInrCommand.php

πŸ“ Path: /home/skhata/new.chandrapharma.com/app/Console/Commands/RevertChandraPharmaPricesToInrCommand.php
πŸ“Š Size: 4.01 KB
πŸ”’ Perm: 0600
πŸ“ MIME: text/x-php
<?php

namespace App\Console\Commands;

use App\Modules\Catalog\Models\Product;
use App\Modules\Vendor\Models\Vendor;
use Illuminate\Console\Command;

/**
 * One-time fix: divides price/compare_price/mrp back by the 1.6 INR→NPR
 * factor ImportChandraPharmaProductsCommand applied, so the Chandra Pharma
 * catalog shows the same numbers it did on the old site (chandrapharma.com,
 * priced in INR) instead of the NPR-converted values β€” per the client's
 * decision to revert to INR display instead of wiring NPR everywhere.
 *
 * Scoped to the "Chandra Pharma" vendor only (matched by slug) β€” never
 * touches any other vendor's products, even if they also happen to be
 * priced in NPR.
 *
 * Safe to re-run: every reverted product also has its `currency` column
 * flipped from 'NPR' to 'INR' as it goes, and the query only ever selects
 * products still marked 'NPR' β€” so a second run finds nothing left to do
 * instead of halving prices again.
 *
 * Usage:
 *   php artisan chandra-products:revert-to-inr
 *   php artisan chandra-products:revert-to-inr --dry-run
 *
 * After running, set Admin β†’ General Settings β†’ Currency to
 * "INR β€” Indian Rupee" and Save β€” the storefront/admin price prefix now
 * reads that setting (see app/helpers.php's currency_symbol()/format_price()).
 */
class RevertChandraPharmaPricesToInrCommand extends Command
{
    protected $signature = 'chandra-products:revert-to-inr {--dry-run : Preview the change without saving}';

    protected $description = 'Divide Chandra Pharma product prices back by 1.6, from NPR to the original INR values';

    private const NPR_TO_INR = 1 / 1.6;

    public function handle(): int
    {
        $dryRun = (bool) $this->option('dry-run');
        if ($dryRun) {
            $this->warn('--dry-run: previewing only, nothing will be saved.');
        }

        $vendor = Vendor::where('slug', 'chandra-pharma')->first();
        if (! $vendor) {
            $this->error('No "Chandra Pharma" vendor found (slug: chandra-pharma) β€” nothing to revert.');

            return self::FAILURE;
        }

        $query = Product::where('vendor_id', $vendor->id)->where('currency', '!=', 'INR');
        $total = $query->count();

        if ($total === 0) {
            $this->info('Nothing to do β€” every Chandra Pharma product is already priced in INR.');

            return self::SUCCESS;
        }

        $this->info(($dryRun ? 'Would revert' : 'Reverting') . " {$total} product(s) from NPR back to INR (Γ· 1.6)...");
        $bar = $this->output->createProgressBar($total);
        $bar->start();

        $updated = 0;
        $query->chunkById(200, function ($products) use (&$updated, $dryRun, $bar) {
            foreach ($products as $product) {
                $newPrice   = $product->price         !== null ? round((float) $product->price         * self::NPR_TO_INR, 2) : null;
                $newCompare = $product->compare_price !== null ? round((float) $product->compare_price * self::NPR_TO_INR, 2) : null;
                $newMrp     = $product->mrp           !== null ? round((float) $product->mrp           * self::NPR_TO_INR, 2) : null;

                if (! $dryRun) {
                    Product::withoutSyncingToSearch(function () use ($product, $newPrice, $newCompare, $newMrp) {
                        $product->update([
                            'price'         => $newPrice,
                            'compare_price' => $newCompare,
                            'mrp'           => $newMrp,
                            'currency'      => 'INR',
                        ]);
                    });
                }

                $updated++;
                $bar->advance();
            }
        });

        $bar->finish();
        $this->newLine(2);
        $this->info(($dryRun ? 'Would update' : 'Updated') . " {$updated} product(s).");

        if (! $dryRun) {
            $this->warn('Next: Admin β†’ General Settings β†’ Currency β†’ set to "INR β€” Indian Rupee" and Save, so the displayed symbol matches these values.');
        }

        return self::SUCCESS;
    }
}
← BackπŸ“₯ Raw✏️ EditπŸ”’ Chmod
✨ File Manager Magic ✨