### Install Improved Import via Composer Source: https://context7.com/firebearstudio/importexportfree/llms.txt Commands to install the extension, enable the module, run setup upgrades, and clear the cache. ```bash # Install the module via Composer composer require firebear/importexportfree # Enable the module php -f bin/magento module:enable Firebear_ImportExport # Run setup upgrade php -f bin/magento setup:upgrade # Deploy static content php -f bin/magento setup:static-content:deploy # Clear cache php -f bin/magento cache:clean ``` -------------------------------- ### Upgrade Magento 2 Setup Source: https://github.com/firebearstudio/importexportfree/blob/master/README.md Run this command after installing or updating modules to upgrade your Magento 2 setup. ```bash php -f bin/magento setup:upgrade ``` -------------------------------- ### CSV Product Import with Images from URL Source: https://context7.com/firebearstudio/importexportfree/llms.txt Example CSV format for importing products, including product details and image URLs. Requires CSV. ```csv sku,name,product_type,attribute_set,price,qty,base_image,small_image,thumbnail SKU001,"Test Product",simple,Default,29.99,100,https://example.com/images/product1.jpg,https://example.com/images/product1.jpg,https://example.com/images/product1.jpg SKU002,"Another Product",simple,Default,49.99,50,https://example.com/images/product2.jpg,https://example.com/images/product2.jpg,https://example.com/images/product2.jpg ``` -------------------------------- ### Deploy Magento 2 Static Content Source: https://github.com/firebearstudio/importexportfree/blob/master/README.md Execute this command to deploy static content for your Magento 2 store, essential after module installations or configuration changes. ```bash php -f bin/magento setup:static-content:deploy ``` -------------------------------- ### Install Firebear ImportExportFree via Composer Source: https://github.com/firebearstudio/importexportfree/blob/master/README.md Use this Composer command to add the Firebear ImportExportFree module to your Magento 2 project. ```bash composer require firebear/importexportfree ``` -------------------------------- ### Dropbox Import Source Implementation Source: https://context7.com/firebearstudio/importexportfree/llms.txt This class handles importing CSV files and product images from Dropbox. It requires an access token and file paths configured in the system. ```php getData($this->code . '_file_path'); $fileName = basename($sourceFilePath); $filePath = $this->_directory->getAbsolutePath($this->getImportPath() . '/' . $fileName); // Create directory if not exists $dirname = dirname($filePath); if (!is_dir($dirname)) { mkdir($dirname, 0775, true); } // Download file content from Dropbox $fileContent = $this->downloadFile($sourceFilePath); file_put_contents($filePath, $fileContent); return $filePath; } /** * Import image from Dropbox * @param string $importImage Image filename * @param string $imageSting Target path string */ public function importImage($importImage, $imageSting) { $filePath = $this->_directory->getAbsolutePath($this->getMediaImportPath() . $imageSting); $sourceDir = $this->getData($this->code . '_import_images_file_dir'); $dirname = dirname($filePath); if (!is_dir($dirname)) { mkdir($dirname, 0775, true); } $fileContent = $this->downloadFile($sourceDir . $importImage); file_put_contents($filePath, $fileContent); } /** * Download file from Dropbox API * @param string $filePath Dropbox file path * @return string|bool File content */ protected function downloadFile($filePath) { $url = 'https://content.dropboxapi.com/2/files/download'; $resource = curl_init($url); curl_setopt($resource, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer ' . $this->getData($this->code . '_access_token'), 'Dropbox-API-Arg: {"path": "' . $filePath . '"}' ]); curl_setopt($resource, CURLOPT_RETURNTRANSFER, true); curl_setopt($resource, CURLOPT_FOLLOWLOCATION, 1); $result = curl_exec($resource); curl_close($resource); return $result; } } ``` -------------------------------- ### Product Import Source: https://context7.com/firebearstudio/importexportfree/llms.txt This section is a placeholder for Product Import related API documentation. -------------------------------- ### System Configuration XML for FTP Source: https://context7.com/firebearstudio/importexportfree/llms.txt Defines the system configuration XML for setting up FTP connection parameters in the Magento admin. Requires XML. ```xml
firebear Firebear_ImportExport::config_importexport You will be able to define file path during import/export process
``` -------------------------------- ### FTP/SFTP Import Source Implementation Source: https://context7.com/firebearstudio/importexportfree/llms.txt This PHP class handles importing data from remote FTP and SFTP servers. It includes methods for establishing connections, downloading source files, and importing images. ```php getSourceClient()) { $sourceFilePath = $this->getData($this->code . '_file_path'); $fileName = basename($sourceFilePath); $filePath = $this->_directory->getAbsolutePath($this->getImportPath() . '/' . $fileName); // Create import folder $filesystem = new \Magento\Framework\Filesystem\Io\File(); $filesystem->setAllowCreateFolders(true); $filesystem->checkAndCreateFolder($this->_directory->getAbsolutePath($this->getImportPath())); // Download file from FTP $result = $client->read($sourceFilePath, $filePath); if ($result) { return $filePath; } } throw new \Magento\Framework\Exception\LocalizedException(__("File not found")); } /** * Download remote images to temporary media directory */ public function importImage($importImage, $imageSting) { if ($client = $this->getSourceClient()) { $sourceFilePath = $this->getData($this->code . '_file_path'); $sourceDirName = dirname($sourceFilePath); $filePath = $this->_directory->getAbsolutePath($this->getMediaImportPath() . $imageSting); $dirname = dirname($filePath); if (!is_dir($dirname)) { mkdir($dirname, 0775, true); } $client->read($sourceDirName . '/' . $importImage, $filePath); } } /** * Prepare and return FTP client connection * @return \Firebear\ImportExport\Model\Filesystem\Io\Ftp */ protected function getSourceClient() { if (!$this->getClient()) { $settings = [ 'host' => $this->getData('ftp_host'), 'port' => $this->getData('ftp_port'), 'user' => $this->getData('ftp_user'), 'password' => $this->getData('ftp_password'), 'passive' => true ]; $connection = new \Firebear\ImportExport\Model\Filesystem\Io\Ftp(); $connection->open($settings); $this->client = $connection; } return $this->getClient(); } } ``` -------------------------------- ### Data Helper for Source Model Factory Source: https://context7.com/firebearstudio/importexportfree/llms.txt Provides utility methods for the import/export module, including retrieving source models by type and checking debug mode. Requires PHP. ```php prepareSourceClassName($sourceType); if ($sourceClassName && class_exists($sourceClassName)) { return $this->getSourceFactory()->create($sourceClassName); } throw new LocalizedException( __("Import source type class for '" . $sourceType . "' is not exist.") ); } /** * Prepare source type class name * @param string $sourceType * @return string */ protected function prepareSourceClassName($sourceType) { return 'Firebear\ImportExport\Model\Source\Type\' . ucfirst(strtolower($sourceType)); } /** * Check if debug mode is enabled * @return bool */ public function getDebugMode() { return (bool)$this->coreConfig->getValue( self::GENERAL_DEBUG, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); } } ``` -------------------------------- ### Product Import CSV with Tier Prices Source: https://context7.com/firebearstudio/importexportfree/llms.txt Use this CSV format to import products, including their tier pricing. Tier prices are defined in a specific format within the 'tier_prices' column. ```csv sku,name,product_type,attribute_set,price,tier_prices SKU001,"Bulk Product",simple,Default,100,"General,100,10,0,All|Retailer,200,9,0,All" ``` -------------------------------- ### URL Import Source Implementation Source: https://context7.com/firebearstudio/importexportfree/llms.txt This PHP class facilitates importing data from HTTP/HTTPS URLs. It includes methods for downloading source files and importing images directly from web links. ```php getSourceClient()) { $fileName = preg_replace('/[^a-z0-9\._-]+/i', '', $this->_fileName); $fileName = str_replace("%", "_", $fileName); $this->_directory->writeFile( $this->_directory->getRelativePath($this->getImportPath() . '/' . $fileName), $read->readAll() ); return $this->_directory->getAbsolutePath() . $this->_directory->getRelativePath($this->getImportPath() . '/' . $fileName); } return false; } /** * Download remote images from URL */ public function importImage($importImage, $imageSting) { $filePath = $this->_directory->getAbsolutePath($this->getMediaImportPath() . $imageSting); $dirname = dirname($filePath); if (!is_dir($dirname)) { mkdir($dirname, 0775, true); } if (preg_match('/\bhttps?:\/\//i', $importImage, $matches)) { $url = str_replace($matches[0], '', $importImage); $driver = $this->getProperDriverCode($matches); $read = $this->_readFactory->create($url, $driver); $this->_directory->writeFile( $this->_directory->getRelativePath($filePath), $read->readAll() ); } return true; } /** * Get HTTP/HTTPS driver based on URL protocol */ protected function getProperDriverCode($matches) { if (is_array($matches)) { return (false === strpos($matches[0], 'https')) ? DriverPool::HTTP : DriverPool::HTTPS; } return DriverPool::HTTP; } } ``` -------------------------------- ### UrlKeyManagerInterface Source: https://context7.com/firebearstudio/importexportfree/llms.txt Interface for managing product URL keys to prevent duplicates during import. ```APIDOC ## UrlKeyManagerInterface ### Description Interface for managing product URL keys to prevent duplicates during import. ### Methods - **addUrlKeys(string $sku, string $urlKey)**: Add URL key for SKU. - **getUrlKeys()**: Get all stored URL keys. - **isUrlKeyExist(string $sku, string $urlKey)**: Check if URL key exists for different SKU. ``` -------------------------------- ### Main Import Class Source: https://context7.com/firebearstudio/importexportfree/llms.txt The `Import` class extends Magento's core import functionality to support multiple source types and enhanced validation. ```APIDOC ## Class: Firebear\ImportExport\Model\Import ### Description This class extends Magento's core import functionality, providing support for various source types and enhanced validation mechanisms. ### Methods #### `checkModified(int $timestamp)` **Description:** Checks if a remote file has been modified since the last import. **Parameters:** - **timestamp** (int) - Required - The timestamp of the last import. **Returns:** - `bool|int` - The modified timestamp or `false` if the source is not available or not modified. #### `uploadSource()` **Description:** Downloads the source file to a temporary directory. Supports direct file uploads (tar/txt) and remote sources. **Returns:** - `string|null` - The local file path of the uploaded source, or `null` if an error occurs. #### `getSource()` **Description:** Gets the source model instance based on the import source type. **Returns:** - ` Firebear ImportExport Model Source Type AbstractType` - The source model instance. ``` -------------------------------- ### Create Product Attributes via CSV Source: https://context7.com/firebearstudio/importexportfree/llms.txt Use the attribute column syntax to define new product attributes directly within a CSV import file. ```csv sku,name,attribute|attribute_code:size|frontend_input:select|attribute_set:Default PROD001,"Test Product",XL PROD002,"Another Product",M ``` -------------------------------- ### Data Helper Source: https://context7.com/firebearstudio/importexportfree/llms.txt Helper class for managing source model factories and debug configuration. ```APIDOC ## Data Helper ### Description Provides methods to retrieve source models based on type and check system debug configuration. ### Methods - **getSourceModelByType(string $sourceType)**: Get source model by source type code (e.g., 'ftp', 'dropbox', 'url'). - **getDebugMode()**: Check if debug mode is enabled in system configuration. ``` -------------------------------- ### Implement Category Import Class Source: https://context7.com/firebearstudio/importexportfree/llms.txt Extend the AbstractEntity class to handle hierarchical category imports with support for Add, Update, Delete, and Replace behaviors. ```php _validatedRows = null; if (Import::BEHAVIOR_DELETE == $this->getBehavior()) { $this->deleteCategories(); } else { $this->saveCategoriesData(); } $this->eventManager->dispatch('catalog_category_import_finish_before', ['adapter' => $this]); return true; } /** * Prepare new category by full path * @param string $rowPath Category path like "Default Category/Women/Dresses" * @param array $rowData Category data */ protected function prepareCategoriesByPath($rowPath, $rowData) { $parentId = \Magento\Catalog\Model\Category::TREE_ROOT_ID; $pathParts = explode(self::DELIMITER_CATEGORY, $rowPath); $path = ''; foreach ($pathParts as $pathPart) { $path .= $pathPart; if (!isset($this->categories[$path])) { $category = $this->categoryFactory->create(); $parentCategory = $this->categoriesCache[$parentId] ?? $this->categoryFactory->create()->load($parentId); $category->setParentId($parentId); $category->setIsActive(true); $category->setIncludeInMenu(true); $category->setAttributeSetId($category->getDefaultAttributeSetId()); $category->addData($rowData); $category->setName($pathPart); $category->setPath($parentCategory->getPath()); $category->save(); $this->categoriesCache[$category->getId()] = $category; $this->categories[$path] = $category->getId(); } $parentId = $this->categories[$path]; $path .= self::DELIMITER_CATEGORY; } return $this; } public function getEntityTypeCode() { return 'catalog_category'; } } ``` -------------------------------- ### Define Attribute Properties in PHP Source: https://context7.com/firebearstudio/importexportfree/llms.txt Configure attribute properties programmatically using the attribute column format string. ```php 'size', // Attribute code (required) 'frontend_input' => 'select', // Input type: text, textarea, select, multiselect, date, boolean 'is_required' => 0, // Required: 1 or 0 'is_global' => 1, // Scope: 0=Store View, 1=Global, 2=Website 'is_unique' => 0, // Unique value: 1 or 0 'is_searchable' => 1, // Use in search: 1 or 0 'is_filterable' => 1, // Use in layered navigation: 1 or 0 'is_comparable' => 0, // Comparable on storefront: 1 or 0 'is_visible_on_front' => 1, // Visible on catalog pages: 1 or 0 'frontend_label_0' => 'Size', // Default label 'attribute_set' => 'Default,Accessories' // Comma-separated attribute set names ]; ``` -------------------------------- ### Format Category CSV Import Source: https://context7.com/firebearstudio/importexportfree/llms.txt Structure category data with hierarchical paths using the required CSV format. ```csv name,url_key,description,is_active,include_in_menu,is_anchor,path "Women/Dresses/Summer",summer-dresses,"Summer dress collection",1,1,1, "Women/Dresses/Winter",winter-dresses,"Winter dress collection",1,1,1, "Accessories",accessories,"All accessories",1,1,1,"Default Category" ``` -------------------------------- ### UrlKeyManagerInterface Definition Source: https://context7.com/firebearstudio/importexportfree/llms.txt Defines the interface for managing product URL keys to prevent duplicates during import operations. Requires PHP. ```php getImportSource()) { $filePath = $this->getData($sourceType . '_file_path'); return $filePath; } return false; } /** * Get source type code * @return string */ public function getCode() { return $this->code; } // Abstract methods to be implemented by source types abstract function uploadSource(); abstract function importImage($importImage, $imageSting); abstract function checkModified($timestamp); abstract protected function getSourceClient(); } ``` -------------------------------- ### PHP Import Class Implementation Source: https://context7.com/firebearstudio/importexportfree/llms.txt This class extends Magento's core import functionality to support multiple source types and enhanced validation. It includes methods for checking remote file modifications and handling file uploads. ```php getSource()) { return $this->getSource()->checkModified($timestamp); } return true; } /** * Download remote source file to temporary directory * @return string|null Local file path */ public function uploadSource() { $result = null; if ($this->getImportSource() && $this->getImportSource() != 'file') { $source = $this->getSource(); $result = $source->uploadSource(); } else { // Handle direct file upload with tar/txt support $uploader = $this->_uploaderFactory->create(['fileId' => self::FIELD_NAME_SOURCE_FILE]); $extension = $uploader->getFileExtension(); if ($extension == 'tar') { $uploader->skipDbProcessing(true); $archiveData = $uploader->save($this->getWorkingDir()); $phar = new \PharData($archiveData['path'] . $archiveData['file']); $phar->extractTo($archiveData['path'], null, true); $result = $archiveData['path'] . $phar->getFilename(); } elseif ($extension == 'txt') { $fileData = $uploader->save($this->getWorkingDir()); $result = $fileData['path'] . $fileData['file']; } } if ($result) { $sourceFileRelative = $this->_varDirectory->getRelativePath($result); $this->createHistoryReport($sourceFileRelative, $this->getEntity()); return $result; } return parent::uploadSource(); } /** * Get source model instance based on import source type * @return \Firebear\ImportExport\Model\Source\Type\AbstractType */ public function getSource() { if (!$this->_source) { $sourceType = $this->getImportSource(); $this->_source = $this->_helper->getSourceModelByType($sourceType); $this->_source->setData($this->getData()); } return $this->_source; } } ``` -------------------------------- ### Extend Magento Product Import for Dynamic Attributes Source: https://context7.com/firebearstudio/importexportfree/llms.txt This class overrides the standard import logic to process custom attribute syntax and inject new options into the EAV database tables during runtime. ```php _validatedRows = null; if (Import::BEHAVIOR_REPLACE == $this->getBehavior()) { $this->_replaceFlag = true; $this->replaceProducts(); } elseif (Import::BEHAVIOR_DELETE == $this->getBehavior()) { $this->_deleteProducts(); } else { $this->saveProductsData(); } $this->_eventManager->dispatch('catalog_product_import_finish_before', ['adapter' => $this]); return true; } /** * Create new attribute values on the fly during import * @param object $productTypeModel Product type model * @param array $rowData Row data * @return array Modified row data */ public function createAttributeValues($productTypeModel, $rowData) { $options = []; $attributeSet = $rowData[self::COL_ATTR_SET]; foreach ($rowData as $attrCode => $attrValue) { // Handle new attribute syntax: attribute|attribute_code:size|frontend_input:select if (preg_match('/^(attribute\|).+/', $attrCode)) { $columnData = explode('|', $attrCode); $columnData = $this->prepareAttributeData($columnData); $rowData[$columnData['attribute_code']] = $rowData[$attrCode]; unset($rowData[$attrCode]); $attrCode = $columnData['attribute_code']; } $attrParams = $productTypeModel->retrieveAttribute($attrCode, $attributeSet); if (!empty($attrParams) && !$attrParams['is_static']) { // Create new select/multiselect options switch ($attrParams['type']) { case 'select': if (!isset($attrParams['options'][strtolower($rowData[$attrCode])])) { $options[$attrParams['id']][] = [ 'sort_order' => count($attrParams['options']) + 1, 'value' => $rowData[$attrCode], 'code' => $attrCode ]; } break; case 'multiselect': foreach (explode(Product::PSEUDO_MULTI_LINE_SEPARATOR, $rowData[$attrCode]) as $value) { if (!isset($attrParams['options'][strtolower($value)])) { $options[$attrParams['id']][] = [ 'sort_order' => count($attrParams['options']) + 1, 'value' => $value, 'code' => $attrCode ]; } } break; } } } // Insert new attribute options into database if (!empty($options)) { foreach ($options as $attributeId => $optionsArray) { foreach ($optionsArray as $option) { $connection = $this->_connection; $resource = $this->_resourceFactory->create(); // Insert option $table = $resource->getTable('eav_attribute_option'); $data = ['attribute_id' => $attributeId, 'sort_order' => $option['sort_order']]; $connection->insert($table, $data); $intOptionId = $connection->lastInsertId($table); // Insert option value $table = $resource->getTable('eav_attribute_option_value'); $data = ['option_id' => $intOptionId, 'store_id' => 0, 'value' => $option['value']]; $connection->insert($table, $data); $productTypeModel->addAttributeOption($option['code'], strtolower($option['value']), $intOptionId); } } } return $rowData; } } ``` -------------------------------- ### Clean Magento 2 Cache Source: https://github.com/firebearstudio/importexportfree/blob/master/README.md Clear the Magento 2 cache to ensure that all changes are reflected on the frontend and backend. ```bash php -f bin/magento cache:clean ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.