Какая сущность допускает атрибуты с ограниченной областью действия?


/vendor/magento/module-eav/Model/Entity/Attribute/ScopedAttributeInterface.php

Существует 3 определенных области

/**
 * @api
 * @since 100.0.2
 */
interface ScopedAttributeInterface
{
    const SCOPE_STORE = 0;

    const SCOPE_GLOBAL = 1;

    const SCOPE_WEBSITE = 2;
}

А вот база данных для entity_type_code

mysql> SELECT entity_type_id, entity_type_code FROM eav_entity_type;
+----------------+------------------+
| entity_type_id | entity_type_code |
+----------------+------------------+
|              1 | customer         |
|              2 | customer_address |
|              3 | catalog_category |
|              4 | catalog_product  |
|              5 | order            |
|              6 | invoice          |
|              7 | creditmemo       |
|              8 | shipment         |
+----------------+------------------+

Итак, выше всех сущностей, Какая Сущность Допускает атрибуты области действия.

enter image description here

customer и customer_address Не поддерживает атрибут области действия [Глобальный]

catalog_category и catalog_product Поддерживает область действия Атрибут [По умолчанию, Веб-сайт и магазин]

Итак, вопрос в том, Таблицы продаж поддерживают ли атрибут Scope? Потому что таблицы продаж хранятся в Magento в виде плоских таблиц.

5: order
6: invoice
7: creditmemo
8: shipment
Author: nikin, 2019-01-17

2 answers

  • customer и customer_address Не поддерживают атрибут области видимости [Глобл]
  • catalog_category и catalog_product Поддерживают атрибут области видимости [По умолчанию, Веб-сайт и магазин]

Итак, вопрос в том, поддерживают ли таблицы продаж атрибут Scope? Потому что таблицы продаж хранятся в виде плоской таблицы в Magento

Продажи НЕ поддерживают атрибуты области.

enter image description here

Подтверждение 1: Проверьте таблицу eav_entity_type в Magento 2

  • attribute_model и entity_attribute_collection равно НУЛЮ для объектов, связанных с продажами.
  • Где в качестве атрибутов клиента могут быть созданы области применения.
  • Атрибуты каталога могут быть созданы с учетом области действия.

Подтверждение 2: Проверьте функцию getDefaultEntities в папке Setup, это устраняет сомнения.

Vendor/magento/module-customer/Setup/CustomerSetup.php

/**
     * Retrieve default entities: customer, customer_address
     *
     * @return array
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function getDefaultEntities()
    {
        $entities = [
            'customer' => [
                'entity_type_id' => \Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER,
                'entity_model' => \Magento\Customer\Model\ResourceModel\Customer::class,
                'attribute_model' => \Magento\Customer\Model\Attribute::class,
                'table' => 'customer_entity',
                'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
                'additional_attribute_table' => 'customer_eav_attribute',
                'entity_attribute_collection' => \Magento\Customer\Model\ResourceModel\Attribute\Collection::class,
                'attributes' => [
                    'website_id' => [
                        'type' => 'static',
                        'label' => 'Associate to Website',
                        'input' => 'select',
                        'source' => \Magento\Customer\Model\Customer\Attribute\Source\Website::class,
                        'backend' => \Magento\Customer\Model\Customer\Attribute\Backend\Website::class,
                        'sort_order' => 10,
                        'position' => 10,
                        'adminhtml_only' => 1,
                    ],
                    'store_id' => [
                        'type' => 'static',
                        'label' => 'Create In',
                        'input' => 'select',
                        'source' => \Magento\Customer\Model\Customer\Attribute\Source\Store::class,
                        'backend' => \Magento\Customer\Model\Customer\Attribute\Backend\Store::class,
                        'sort_order' => 20,
                        'visible' => false,
                        'adminhtml_only' => 1,
                    ],

Vendor/magento/module-catalog/Setup/CategorySetup.php

/**
     * Default entities and attributes
     *
     * @return array
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    public function getDefaultEntities()
    {
        return [
            'catalog_category' => [
                'entity_type_id' => self::CATEGORY_ENTITY_TYPE_ID,
                'entity_model' => Category::class,
                'attribute_model' => Attribute::class,
                'table' => 'catalog_category_entity',
                'additional_attribute_table' => 'catalog_eav_attribute',
                'entity_attribute_collection' =>
                    Collection::class,
                'attributes' => [
                    'name' => [
                        'type' => 'varchar',
                        'label' => 'Name',
                        'input' => 'text',
                        'sort_order' => 1,
                        'global' => ScopedAttributeInterface::SCOPE_STORE,
                        'group' => 'General Information',
                    ],

Vendor/magento/module-sales/Setup/SalesSetup.php

/**
     * @return array
     */
    public function getDefaultEntities()
    {
        $entities = [
            'order' => [
                'entity_type_id' => self::ORDER_ENTITY_TYPE_ID,
                'entity_model' => \Magento\Sales\Model\ResourceModel\Order::class,
                'table' => 'sales_order',
                'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
                'increment_per_store' => true,
                'attributes' => [],
            ],
            'invoice' => [
                'entity_type_id' => self::INVOICE_PRODUCT_ENTITY_TYPE_ID,
                'entity_model' => \Magento\Sales\Model\ResourceModel\Order\Invoice::class,
                'table' => 'sales_invoice',
                'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
                'increment_per_store' => true,
                'attributes' => [],
            ],
            'creditmemo' => [
                'entity_type_id' => self::CREDITMEMO_PRODUCT_ENTITY_TYPE_ID,
                'entity_model' => \Magento\Sales\Model\ResourceModel\Order\Creditmemo::class,
                'table' => 'sales_creditmemo',
                'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
                'increment_per_store' => true,
                'attributes' => [],
            ],
            'shipment' => [
                'entity_type_id' => self::SHIPMENT_PRODUCT_ENTITY_TYPE_ID,
                'entity_model' => \Magento\Sales\Model\ResourceModel\Order\Shipment::class,
                'table' => 'sales_shipment',
                'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
                'increment_per_store' => true,
                'attributes' => [],
            ],
        ];
        return $entities;
    }

В конформации 2 - getDefaultEntities Область применима для атрибутов клиента и каталога, а также категорий, Но Продажи НЕ поддерживают атрибуты области, это не определено в Настройке.

 7
Author: Aditya Shah, 2019-01-18 07:55:05

Насколько я понимаю, вы можете создавать пользовательские атрибуты только для следующих типов сущностей:

  1. Заказчик (Область применения: Глобальный)
  2. адрес_пользователя (Область действия: Глобальная)
  3. каталог_категории (Область действия: По умолчанию, Веб-сайт и магазин)
  4. каталог_продуктов (Область применения: По умолчанию, Веб-сайт и магазин)

Как и при просмотре столбца таблицы eav_entity_type additional_attribute_table и entity_attribute_collection, вы можете увидеть значения только для 4 entity_types.

И для атрибута клиента по умолчанию область действия равна Глобальный (по умолчанию), поэтому вам не нужно устанавливать атрибут scope. Для остальных, т.е. Категории каталога и продукта, вы можете установить любую область, т.е. Глобальную (по умолчанию), Веб-сайт или магазин

Для rest я не думаю, что вы можете создать, но если вы хотите создать дополнительный столбец для остальной части сущности, вы можете использовать атрибут расширения особенность M2

 7
Author: Aman Agarwal, 2020-01-10 04:31:52