Buat Modul Karyawan seperti modul Pelanggan di magento 2


15

Saya telah membuat modul Karyawan. sama dengan modul pelanggan. saya telah menyalin semua file dari vendor/magento/module-customerke app/code/Magento/Employee. Saya mengganti pelanggan dengan karyawan . tapi itu menunjukkan kesalahan:

'InvalidArgumentException' dengan pesan 'Nama konstan diharapkan.

dan

[InvalidArgumentException]
Tidak ada perintah yang ditentukan dalam namespace "setup".

Saya module.xmlada di app/Code/Magento/Employee/etcfolder

<?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>

Tolong ada yang bilang padaku bagaimana saya bisa menyelesaikannya?

Di.xml saya

<?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>

Um ... ya. Itu tidak akan mudah. Apa sebenarnya yang kamu coba keluar? Anda harus membuatnya sebagai model dan modul ORM khusus.
Ryan Hoerr

saya mencoba membuat modul Karyawan sama dengan modul Pelanggan
mr. maks

Jawaban:


5

Saya pikir ini konstan dalam di.xml:

Magento\Employee\Api\EmployeeMetadataInterface::ENTITY_TYPE_Employee

seharusnya

Magento\Employee\Api\EmployeeMetadataInterface::ENTITY_TYPE_EMPLOYEE

3

mr.max,

Ini solusi untuk Anda:

  1. Periksa, jika Anda mengganti file dengan mempertimbangkan huruf kecil dan huruf besar akun ("pelanggan" -> "karyawan", "Pelanggan" -> "Karyawan" dll.)
  2. Periksa, jika Anda mengubah nama file dan nama folder, di mana ada kata "Pelanggan".
  3. Pastikan Anda belum mengubah kata lain "Pelanggan". Misalnya dalam file

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

    ada kodenya

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

    Itu berarti bahwa metode subscribeCustomerByIdini dipanggil dari modul "module-newsletter" ( Magento\Newsletter\Model\Subscriber). Dan jika Anda mengubah namanya menjadi subscribeEmployeeById, Anda akan mendapatkan kesalahan.

Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.