Créer un module employé comme un module client dans magento 2


15

J'ai créé le module Employé. Identique au module client. j'ai copié tous les fichiers de vendor/magento/module-customerà app/code/Magento/Employee. J'ai remplacé le client par l' employé . mais cela montre une erreur:

'InvalidArgumentException' avec le message 'Un nom constant est attendu.

et

[InvalidArgumentException]
Aucune commande n'est définie dans l'espace de noms "setup".

Mon dossier module.xmlest dansapp/Code/Magento/Employee/etc

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Employee" setup_version="2.0.6">
    <sequence>
        <module name="Magento_Eav"/>
        <module name="Magento_Directory"/>
    </sequence>
</module>
</config>

S'il vous plaît, quelqu'un me dit comment puis-je le résoudre?

Mon di.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Employee\Api\AddressRepositoryInterface"
                type="Magento\Employee\Model\ResourceModel\AddressRepository" />
    <preference for="Magento\Employee\Api\EmployeeRepositoryInterface"
                type="Magento\Employee\Model\ResourceModel\EmployeeRepository" />
    <preference for="Magento\Employee\Api\GroupManagementInterface"
                type="Magento\Employee\Model\GroupManagement" />
    <preference for="Magento\Employee\Api\GroupRepositoryInterface"
                type="Magento\Employee\Model\ResourceModel\GroupRepository" />
    <preference for="Magento\Employee\Api\Data\EmployeeInterface" type="Magento\Employee\Model\Data\Employee" />
    <preference for="Magento\Employee\Api\Data\AddressInterface" type="Magento\Employee\Model\Data\Address" />
    <preference for="Magento\Employee\Api\Data\RegionInterface" type="Magento\Employee\Model\Data\Region" />
    <preference for="Magento\Employee\Api\Data\AttributeMetadataInterface"
                type="Magento\Employee\Model\Data\AttributeMetadata" />
    <preference for="Magento\Employee\Api\Data\GroupInterface" type="Magento\Employee\Model\Data\Group" />
    <preference for="Magento\Employee\Api\Data\OptionInterface" type="Magento\Employee\Model\Data\Option" />
    <preference for="Magento\Employee\Api\Data\ValidationRuleInterface"
                type="Magento\Employee\Model\Data\ValidationRule" />
    <preference for="Magento\Employee\Api\Data\ValidationResultsInterface"
                type="Magento\Employee\Model\Data\ValidationResults" />
    <preference for="Magento\Employee\Api\Data\GroupSearchResultsInterface"
                type="Magento\Framework\Api\SearchResults" />
    <preference for="Magento\Employee\Api\Data\EmployeeSearchResultsInterface"
                type="Magento\Framework\Api\SearchResults" />
    <preference for="Magento\Employee\Api\Data\AddressSearchResultsInterface"
                type="Magento\Framework\Api\SearchResults" />
    <preference for="Magento\Employee\Api\AccountManagementInterface"
                type="Magento\Employee\Model\AccountManagement" />
    <preference for="Magento\Employee\Api\EmployeeMetadataInterface"
                type="Magento\Employee\Model\Metadata\EmployeeCachedMetadata" />
    <preference for="Magento\Employee\Api\AddressMetadataInterface"
                type="Magento\Employee\Model\Metadata\AddressCachedMetadata" />
    <preference for="Magento\Employee\Api\EmployeeMetadataManagementInterface"
                type="Magento\Employee\Model\Metadata\EmployeeMetadataManagement" />
    <preference for="Magento\Employee\Api\AddressMetadataManagementInterface"
                type="Magento\Employee\Model\Metadata\AddressMetadataManagement" />
    <preference for="Magento\Employee\Api\EmployeeManagementInterface"
                type="Magento\Employee\Model\EmployeeManagement" />
    <type name="Magento\Employee\Model\EmployeeSession">
    <arguments>
        <argument name="configShare" xsi:type="object">Magento\Employee\Model\Config\Share\Proxy</argument>
        <argument name="employeeUrl" xsi:type="object">Magento\Employee\Model\Url\Proxy</argument>
        <argument name="employeeResource" xsi:type="object">Magento\Employee\Model\ResourceModel\Employee\Proxy</argument>
        <argument name="storage" xsi:type="object">Magento\Employee\Model\Session\Storage</argument>
        <argument name="employeeRepository" xsi:type="object">Magento\Employee\Api\EmployeeRepositoryInterface\Proxy</argument>
    </arguments>
</type>
    <type name="Magento\Employee\Helper\Address">
        <arguments>
            <argument name="addressConfig" xsi:type="object">Magento\Employee\Model\Address\Config\Proxy</argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\Config\Share">
        <arguments>
            <argument name="employeeResource" xsi:type="object">Magento\Employee\Model\ResourceModel\Employee\Proxy</argument>
        </arguments>
    </type>
    <type name="Magento\Eav\Model\Entity\Setup\PropertyMapper\Composite">
        <arguments>
            <argument name="propertyMappers" xsi:type="array">
                <item name="employee" xsi:type="string">Magento\Employee\Model\ResourceModel\Setup\PropertyMapper</item>
            </argument>
        </arguments>
    </type>
    <type name="Magento\Framework\Model\ActionValidator\RemoveAction">
        <arguments>
            <argument name="protectedModels" xsi:type="array">
                <item name="employee" xsi:type="string">Magento\Employee\Model\Employee</item>
            </argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\ResourceModel\Address">
        <arguments>
            <argument name="employeeRepository" xsi:type="object">Magento\Employee\Api\EmployeeRepositoryInterface\Proxy</argument>
            <argument name="entitySnapshot" xsi:type="object">EavVersionControlSnapshot</argument>
            <argument name="entityRelationComposite" xsi:type="object">EmployeeAddressRelationsComposite</argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\Address\Config">
        <arguments>
            <argument name="reader" xsi:type="object">Magento\Employee\Model\Address\Config\Reader\Proxy</argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\Visitor">
        <arguments>
            <argument name="ignoredUserAgents" xsi:type="array">
                <item name="google1" xsi:type="string">Googlebot/1.0 (googlebot@googlebot.com http://googlebot.com/)</item>
                <item name="google2" xsi:type="string">Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)</item>
                <item name="google3" xsi:type="string">Googlebot/2.1 (+http://www.googlebot.com/bot.html)</item>
            </argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\ResourceModel\Group" shared="false">
        <arguments>
            <argument name="groupManagement" xsi:type="object">Magento\Employee\Api\GroupManagementInterface\Proxy</argument>
        </arguments>
    </type>
    <virtualType name="SectionInvalidationConfigReader" type="Magento\Framework\Config\Reader\Filesystem">
        <arguments>
            <argument name="idAttributes" xsi:type="array">
                <item name="/config/action" xsi:type="string">name</item>
                <item name="/config/action/section" xsi:type="string">name</item>
            </argument>
            <argument name="fileName" xsi:type="string">sections.xml</argument>
            <argument name="converter" xsi:type="object">\Magento\Employee\EmployeeData\SectionConfigConverter</argument>
            <argument name="schemaLocator" xsi:type="object">Magento\Employee\EmployeeData\SchemaLocator</argument>
            <argument name="defaultScope" xsi:type="string">frontend</argument>
        </arguments>
    </virtualType>
    <virtualType name="SectionInvalidationConfigData" type="Magento\Framework\Config\Data">
        <arguments>
            <argument name="reader" xsi:type="object">SectionInvalidationConfigReader</argument>
            <argument name="cacheId" xsi:type="string">sections_invalidation_config</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Employee\Block\SectionConfig">
        <arguments>
            <argument name="sectionConfig" xsi:type="object">SectionInvalidationConfigData</argument>
        </arguments>
    </type>
    <type name="Magento\Eav\Model\EavCustomAttributeTypeLocator">
        <arguments>
            <argument name="serviceEntityTypeMap" xsi:type="array">
                <item name="Magento\Employee\Api\Data\EmployeeInterface" xsi:type="const">Magento\Employee\Api\EmployeeMetadataInterface::ENTITY_TYPE_Employee</item>
            </argument>
            <argument name="serviceBackendModelDataInterfaceMap" xsi:type="array">
                <item name="Magento\Employee\Api\Data\EmployeeInterface" xsi:type="array">
                    <item name="Magento\Eav\Model\Attribute\Data\Image" xsi:type="string">Magento\Framework\Api\Data\ImageContentInterface</item>
                </item>
            </argument>
        </arguments>
    </type>
    <virtualType name="EavVersionControlSnapshot" type="Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot">
        <arguments>
            <argument name="metadata" xsi:type="object">Magento\Eav\Model\Entity\VersionControl\Metadata</argument>
        </arguments>
    </virtualType>
    <virtualType name="EmployeeRelationsComposite" type="Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite">
        <arguments>
            <argument name="relationProcessors" xsi:type="array">
                <item name="default" xsi:type="object">Magento\Employee\Model\ResourceModel\Employee\Relation</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="EmployeeAddressRelationsComposite" type="Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite">
        <arguments>
            <argument name="relationProcessors" xsi:type="array">
                <item name="default" xsi:type="object">Magento\Employee\Model\ResourceModel\Address\Relation</item>
            </argument>
        </arguments>
    </virtualType>
    <type name="Magento\Employee\Model\ResourceModel\Employee">
        <arguments>
            <argument name="entitySnapshot" xsi:type="object">EavVersionControlSnapshot</argument>
            <argument name="entityRelationComposite" xsi:type="object">EmployeeRelationsComposite</argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\ResourceModel\Employee\Collection">
        <arguments>
            <argument name="entitySnapshot" xsi:type="object">EavVersionControlSnapshot</argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\ResourceModel\Address\Collection">
        <arguments>
            <argument name="entitySnapshot" xsi:type="object">EavVersionControlSnapshot</argument>
        </arguments>
    </type>
    <virtualType name="Magento\Employee\Model\ResourceModel\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
        <arguments>
            <argument name="mainTable" xsi:type="string">employee_grid_flat</argument>
            <argument name="resourceModel" xsi:type="string">Magento\Employee\Model\ResourceModel\Employee</argument>
        </arguments>
    </virtualType>
    <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
        <arguments>
            <argument name="collections" xsi:type="array">
                <item name="employee_listing_data_source" xsi:type="string">Magento\Employee\Model\ResourceModel\Grid\Collection</item>
                <item name="employee_online_grid_data_source" xsi:type="string">Magento\Employee\Model\ResourceModel\Online\Grid\Collection</item>
            </argument>
        </arguments>
    </type>
    <virtualType name="EmployeeNameHandler" type="Magento\Framework\Indexer\Handler\ConcatHandler">
        <arguments>
            <argument name="concatExpression" xsi:type="object">EmployeeNameExpression</argument>
        </arguments>
    </virtualType>
    <virtualType name="ShippingAddressHandler" type="Magento\Framework\Indexer\Handler\ConcatHandler">
        <arguments>
            <argument name="concatExpression" xsi:type="object">ShippingAddressExpression</argument>
        </arguments>
    </virtualType>
    <virtualType name="BillingAddressHandler" type="Magento\Framework\Indexer\Handler\ConcatHandler">
        <arguments>
            <argument name="concatExpression" xsi:type="object">BillingAddressExpression</argument>
        </arguments>
    </virtualType>
    <virtualType name="LastVisitAtHandler" type="Magento\Framework\Indexer\Handler\ConcatHandler">
        <arguments>
            <argument name="concatExpression" xsi:type="object">LastVisitAtSubSelect</argument>
        </arguments>
    </virtualType>
    <virtualType name="LastVisitAtSubSelect" type="Magento\Framework\DB\Sql\LookupExpression">
        <arguments>
            <argument name="targetTable" xsi:type="string">employee_visitor</argument>
            <argument name="targetColumn" xsi:type="string">last_visit_at</argument>
            <argument name="referenceColumns" xsi:type="array">
                <item name="employee_id" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">e</item>
                    <item name="columnName" xsi:type="string">entity_id</item>
                </item>
            </argument>
            <argument name="sortOrder" xsi:type="array">
                <item name="DESC" xsi:type="string">last_visit_at</item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="EmployeeNameExpression" type="Magento\Framework\DB\Sql\ConcatExpression">
        <arguments>
            <argument name="tableName" xsi:type="string">e</argument>
            <argument name="columns" xsi:type="array">
                <item name="prefix" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">e</item>
                    <item name="columnName" xsi:type="string">prefix</item>
                </item>
                <item name="firstname" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">e</item>
                    <item name="columnName" xsi:type="string">firstname</item>
                </item>
                <item name="middlename" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">e</item>
                    <item name="columnName" xsi:type="string">middlename</item>
                </item>
                <item name="lastname" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">e</item>
                    <item name="columnName" xsi:type="string">lastname</item>
                </item>
                <item name="suffix" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">e</item>
                    <item name="columnName" xsi:type="string">suffix</item>
                </item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="ShippingAddressExpression" type="Magento\Framework\DB\Sql\ConcatExpression">
        <arguments>
            <argument name="columns" xsi:type="array">
                <item name="prefix" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">shipping</item>
                    <item name="columnName" xsi:type="string">street</item>
                </item>
                <item name="firstname" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">shipping</item>
                    <item name="columnName" xsi:type="string">city</item>
                </item>
                <item name="middlename" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">shipping</item>
                    <item name="columnName" xsi:type="string">region</item>
                </item>
                <item name="lastname" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">shipping</item>
                    <item name="columnName" xsi:type="string">postcode</item>
                </item>
            </argument>
        </arguments>
    </virtualType>
    <virtualType name="BillingAddressExpression" type="Magento\Framework\DB\Sql\ConcatExpression">
        <arguments>
            <argument name="columns" xsi:type="array">
                <item name="prefix" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">billing</item>
                    <item name="columnName" xsi:type="string">street</item>
                </item>
                <item name="firstname" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">billing</item>
                    <item name="columnName" xsi:type="string">city</item>
                </item>
                <item name="middlename" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">billing</item>
                    <item name="columnName" xsi:type="string">region</item>
                </item>
                <item name="lastname" xsi:type="array">
                    <item name="tableAlias" xsi:type="string">billing</item>
                    <item name="columnName" xsi:type="string">postcode</item>
                </item>
            </argument>
        </arguments>
    </virtualType>
    <type name="Magento\Employee\Model\Indexer\AttributeProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Magento\Employee\Model\ResourceModel\Attribute\Collection</argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\Indexer\Address\AttributeProvider">
        <arguments>
            <argument name="collection" xsi:type="object" shared="false">Magento\Employee\Model\ResourceModel\Address\Attribute\Collection</argument>
        </arguments>
    </type>
    <type name="Magento\Employee\Model\ResourceModel\Online\Grid\Collection">
        <arguments>
            <argument name="mainTable" xsi:type="string">employee_visitor</argument>
            <argument name="resourceModel" xsi:type="string">Magento\Employee\Model\ResourceModel\Visitor</argument>
        </arguments>
    </type>
</config>

Euh ... ouais. Ce ne sera pas si facile. Qu'essayez-vous exactement de sortir? Vous devez le créer en tant que modèle et module ORM personnalisé.
Ryan Hoerr

j'essaye de créer le module employé même que le module client
mr. max

Réponses:


5

Je pense que cette constante dans di.xml:

Magento\Employee\Api\EmployeeMetadataInterface::ENTITY_TYPE_Employee

devrait être

Magento\Employee\Api\EmployeeMetadataInterface::ENTITY_TYPE_EMPLOYEE

3

mr.max,

Voici une solution pour vous:

  1. Vérifiez, si vous avez remplacé les fichiers en tenant compte des lettres minuscules et majuscules ("client" -> "employé", "client" -> "employé" etc.)
  2. Vérifiez, si vous avez changé les noms de fichier et les noms de dossier, où se trouve le mot "Client".
  3. Assurez-vous que vous n'avez pas changé d'autres mots "Client". Par exemple, dans le fichier

    vendor/magento/module-customer/Controller/Adminhtml/Index/MassSubscribe.php

    il y a un code

    $this->subscriberFactory->create()->subscribeCustomerById($customerId);

    Cela signifie que la méthode subscribeCustomerByIdest appelée depuis le module "module-newsletter" ( Magento\Newsletter\Model\Subscriber). Et si vous changez son nom en subscribeEmployeeById, vous obtiendrez des erreurs.

En utilisant notre site, vous reconnaissez avoir lu et compris notre politique liée aux cookies et notre politique de confidentialité.
Licensed under cc by-sa 3.0 with attribution required.