pimcore-magento2-bridge
pimcore-magento2-bridge copied to clipboard
Attempted to load class "IntegrationConfiguration"
Using Pimcore 6.0
composer require divante-ltd/pimcore-magento2-bridge:dev-develop-v2
getting below error :
Attempted to load class "IntegrationConfiguration" from namespace "Pimcore\Model\DataObject". Did you forget a "use" statement for "Divante\MagentoIntegrationBundle\Domain\DataObject\IntegrationConfiguration"?
Do we have solution to fix this?
Made the changes in installer.php and it worked for me
* @copyright Copyright (c) 2018 DIVANTE (https://divante.co) */ namespace Divante\MagentoIntegrationBundle\Migrations; use Divante\MagentoIntegrationBundle\Domain\IntegrationConfiguration\IntegrationHelper; use Doctrine\DBAL\Migrations\Version; use Doctrine\DBAL\Schema\Schema; use Pimcore\Cache; use Pimcore\Db\Connection; use Pimcore\Extension\Bundle\Installer\MigrationInstaller; use Pimcore\Migrations\MigrationManager; use Pimcore\Model\DataObject; use Pimcore\Model\Property\Predefined; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Config\FileLocator; use Symfony\Component\Process\Process; use Pimcore\Model\DataObject\ClassDefinition; use Pimcore\Model\DataObject\ClassDefinition\Service; /** * Class Installer * @package Divante\MagentoIntegrationBundle\Migrations */ class Installer extends MigrationInstaller { const CONFIGURATION_CLASS_NAME = 'IntegrationConfiguration'; /** @var FileLocator */ protected $fileLocator; private $installSourcesPath; /** * @var array */ private $classesToInstall = [ 'IntegrationConfiguration' => 'IntegrationConfiguration' ]; /** * @param BundleInterface $bundle * @param Connection $connection * @param MigrationManager $migrationManager * @param FileLocator $fileLocator */ public function __construct( BundleInterface $bundle, Connection $connection, MigrationManager $migrationManager, FileLocator $fileLocator ) { $this->fileLocator = $fileLocator; $this->installSourcesPath = __DIR__ . '/../Resources/install'; parent::__construct($bundle, $connection, $migrationManager); } /** * @param Schema $schema * @param Version $version */ public function migrateInstall(Schema $schema, Version $version): void { if (!Predefined::getByKey(IntegrationHelper::PRODUCT_TYPE_CONFIGURABLE_ATTRIBUTE) instanceof Predefined) { $propertyData = [ 'name' => 'Configurable Attributes', 'key' => IntegrationHelper::PRODUCT_TYPE_CONFIGURABLE_ATTRIBUTE, 'ctype' => 'object', 'type' => 'text', 'inheritable' => true ]; $property = Predefined::create(); $property->setValues($propertyData); $property->save(); } Cache::disable(); $this->installClasses(); // $classDefinition = $this->locateClassDefinitionFile(); // $command = ['bin/console', 'pimcore:definition:import:class', $classDefinition]; // $process = new Process($command, PIMCORE_PROJECT_ROOT); // $process->setTimeout(0); // $process->run(); // $this->outputWriter->write($process->getOutput()); Cache::enable(); if (!file_exists(PIMCORE_LOG_DIRECTORY . '/magento2-connector')) { mkdir(PIMCORE_LOG_DIRECTORY . '/magento2-connector', 0740); } $this->createSampleObject(); } /** * @return string */ protected function locateClassDefinitionFile(): string { $filename = '@DivanteMagentoIntegrationBundle/Resources/install/classes/class_IntegrationConfiguration_export.json'; return $this->fileLocator->locate($filename); } protected function createSampleObject() { $object = new DataObject\IntegrationConfiguration(); $object->setParent(DataObject\Service::createFolderByPath('/integration-configuration')); $object->setPublished(false); $object->setOmitMandatoryCheck(true); $object->setKey('magento-configuration'); $object->save(); } private function getClassesToInstall(): array { $result = []; foreach (array_keys($this->classesToInstall) as $className) { $filename = sprintf('class_%s_export.json', $className); $path = $this->installSourcesPath . '/classes/' . $filename; $path = realpath($path); if (false === $path || !is_file($path)) { throw new AbortMigrationException(sprintf( 'Class export for class "%s" was expected in "%s" but file does not exist', $className, $path )); } $result[$className] = $path; } return $result; } private function installClasses() { $classes = $this->getClassesToInstall(); $mapping = $this->classesToInstall; foreach ($classes as $key => $path) { $class = ClassDefinition::getByName($key); if ($class) { $this->outputWriter->write(sprintf( '
@prince0212 Could you create Pull Request with changes?
sure will do the needful
I am getting the same error on an already running instance (since 2020). After running composer update
and attempting to edit existing configuration object in the Pimcore UI / admin:
Attempted to load class "IntegrationConfiguration" from namespace "Divante\MagentoIntegrationBundle\Model\DataObject". Did you forget a "use" statement for another namespace?
I can't access the configuration object, as the error breaks the Pimcore UI. ~~Doesn't look like namespacing is the problem here?~~ This is on PHP 7.4 and Symfony 4.4 so this could be namespacing / autoloading issue(?)
Related to #105 and #110, the package does not comply with PSR-4, so Composer 2 won't autoload the necessary classes.
A fix has been commited to the develop-v2
branch only.
An easy solution is to downgrade Composer to V1 (composer self-update --1
) and running composer update
, then all classes autoload properly.