Website : phonehp.ir
backdoor
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Home
Console
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Warning
: Undefined variable $backdoor in
/home/nehpir/public_html/goods.php
on line
326
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
nehpir
/
public_html
/
wp-content
/
plugins
/
woocommersa
/
includes
/
Services
/
Filename :
ImportService.php
back
Warning
: Undefined variable $file in
/home/nehpir/public_html/goods.php
on line
545
Copy
<?php namespace WooCommersa\Services; if (!defined('ABSPATH')) exit; class ImportService { public function parse_columns($file_path) { $handle = fopen($file_path, 'r'); if (!$handle) return false; // Skip BOM if exists $bom = fread($handle, 3); if ($bom !== chr(0xEF) . chr(0xBB) . chr(0xBF)) rewind($handle); $header = fgetcsv($handle, 0, ","); if (count($header) <= 1) { rewind($handle); if ($bom === chr(0xEF) . chr(0xBB) . chr(0xBF)) fread($handle, 3); $header = fgetcsv($handle, 0, "\t"); } fclose($handle); return array_filter($header); } public function process_import($file_path, $mapping) { // This should probably be handled in background for large files // But for now, let's implement the logic $handle = fopen($file_path, 'r'); if (!$handle) return false; $bom = fread($handle, 3); if ($bom !== chr(0xEF) . chr(0xBB) . chr(0xBF)) rewind($handle); $header = fgetcsv($handle, 0, ","); $delimiter = ","; if (count($header) <= 1) { rewind($handle); $header = fgetcsv($handle, 0, "\t"); $delimiter = "\t"; } $results = ['updated' => 0, 'skipped' => 0]; $bulk_service = new BulkEditService(); while (($row = fgetcsv($handle, 0, $delimiter)) !== false) { // Robustly handle column count mismatches to prevent crashes $row_count = count($row); $header_count = count($header); if ($row_count !== $header_count) { if ($row_count < $header_count) { $row = array_pad($row, $header_count, ''); } else { $row = array_slice($row, 0, $header_count); } } $csv_data = array_combine($header, $row); // Find SKU or ID for lookup - Trim keys and values for Persian compatibility $sku_key = array_search('sku', $mapping); $id_key = array_search('id', $mapping); $product_id = 0; if ($id_key && isset($csv_data[$id_key])) { $product_id = intval(trim($csv_data[$id_key])); } elseif ($sku_key && isset($csv_data[$sku_key])) { $product_id = wc_get_product_id_by_sku(trim($csv_data[$sku_key])); } if (!$product_id) { $results['skipped']++; continue; } // Prepare updates for BulkEditService $updates = []; foreach ($mapping as $csv_key => $wc_field) { if ($wc_field === 'sku' || $wc_field === 'id' || !isset($csv_data[$csv_key])) continue; $val = trim($csv_data[$csv_key]); if ($val === '') continue; // Skip empty cells $updates[$wc_field] = [ 'operation' => 'set', 'value' => $val ]; } if (!empty($updates)) { $bulk_service->apply_updates([$product_id], $updates, 'import_' . time(), 'import'); $results['updated']++; } else { $results['skipped']++; } } fclose($handle); $results['success'] = true; return $results; } }