![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/scripts/ |
<?php use Magento\Framework\App\Bootstrap; use Magento\Catalog\Model\Product\Action as ProductAction; try { require_once '../app/bootstrap.php'; } catch (\Exception $e) { echo 'Autoload error: ' . $e->getMessage(); exit(1); } ini_set('display_errors', 1); error_reporting(E_ALL); echo 'sa'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $appState = $objectManager->get('Magento\Framework\App\State'); $appState->setAreaCode('frontend'); $productAction = $objectManager->create(ProductAction::class); $csvFilePath = 'stds.csv'; // Update this with your actual CSV file path $csvData = []; echo 'sa'; // Load and parse the CSV file if (($handle = fopen($csvFilePath, "r")) !== FALSE) { $header = fgetcsv($handle, 1000, ","); while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { $csvData[] = array_combine($header, $row); } fclose($handle); } // Iterate through each row in the CSV foreach ($csvData as $data) { $styleCode = $data['Style']; // Replace with the actual column name for SKU // Load existing product by SKU $configurableproduct = $objectManager->create('Magento\Catalog\Model\Product')->loadByAttribute('sku', $styleCode); if ($configurableproduct) { // Configurable product exists, update the 'standard' attribute // Loop through Standard1 to Standard10 and format data as <ul><li>...</li></ul> $standardData = '<ul>'; for ($i = 1; $i <= 10; $i++) { $columnName = 'Standard' . $i; if (!empty($data[$columnName])) { $standardData .= '<li>' . htmlspecialchars($data[$columnName]) . '</li>'; } } $standardData .= '</ul>'; if ($standardData !== '<ul></ul>') { $productAction->updateAttributes( [$configurableproduct->getId()], ['standards' => $standardData], 0 ); } try { $configurableproduct->save(); echo "Updated 'standard' attribute for SKU: $styleCode.\n"; } catch (Exception $ex) { echo "Error Updating Configurable Product: " . $ex->getMessage() . "\n"; } } else { echo "Configurable Product with SKU: $styleCode does not exist.\n"; } }