/**
  * @param \Magento\Eav\Setup\EavSetup $eavSetup
  * @param array $attributes
  */
 public function installCustomerForms(EavSetup $eavSetup, array $attributes)
 {
     $customer = (int) $eavSetup->getEntityTypeId('customer');
     $customerAddress = (int) $eavSetup->getEntityTypeId('customer_address');
     /**
      * @var ModuleDataSetupInterface $setup
      */
     $setup = $eavSetup->getSetup();
     $attributeIds = [];
     $select = $setup->getConnection()->select()->from(['ea' => $setup->getTable('eav_attribute')], ['entity_type_id', 'attribute_code', 'attribute_id'])->where('ea.entity_type_id IN(?)', [$customer, $customerAddress]);
     foreach ($setup->getConnection()->fetchAll($select) as $row) {
         if (preg_match('/kana/', $row['attribute_code'])) {
             $attributeIds[$row['entity_type_id']][$row['attribute_code']] = $row['attribute_id'];
         }
     }
     $data = [];
     $usedInCustomerForms = ['customer_account_create', 'customer_account_edit', 'adminhtml_customer'];
     $usedInAddressForms = ['customer_register_address', 'customer_address_edit', 'adminhtml_customer_address'];
     $usedInForms = [];
     foreach ($attributeIds as $entity => $attrs) {
         foreach ($attrs as $attributeCode => $attributeId) {
             if ($entity == $customer) {
                 $usedInForms = $usedInCustomerForms;
             } else {
                 $usedInForms = $usedInAddressForms;
             }
             foreach ($usedInForms as $formCode) {
                 $data[] = ['form_code' => $formCode, 'attribute_id' => $attributeId];
             }
         }
     }
     if ($data) {
         $setup->getConnection()->insertMultiple($setup->getTable('customer_form_attribute'), $data);
     }
 }
Beispiel #2
0
 /**
  * Update some categories attributes to have them indexed into ES.
  * Basically :
  *  - Name (indexable and searchable
  *  - Description (indexable and searchable)
  *  - Url Path (indexable)
  */
 private function updateCategorySearchableAttributes()
 {
     $setup = $this->eavSetup->getSetup();
     $connection = $setup->getConnection();
     $table = $setup->getTable('catalog_eav_attribute');
     // Set Name and description indexable and searchable.
     $attributeIds = [$this->eavSetup->getAttributeId(\Magento\Catalog\Model\Category::ENTITY, 'name'), $this->eavSetup->getAttributeId(\Magento\Catalog\Model\Category::ENTITY, 'description')];
     foreach (['is_searchable', 'is_used_in_spellcheck'] as $configField) {
         foreach ($attributeIds as $attributeId) {
             $connection->update($table, [$configField => 1], $connection->quoteInto('attribute_id = ?', $attributeId));
         }
     }
     // Set url_path indexable.
     $urlPathAttributeId = $this->eavSetup->getAttributeId(\Magento\Catalog\Model\Category::ENTITY, 'url_path');
     $connection->update($table, ['is_searchable' => 1], $connection->quoteInto('attribute_id = ?', $urlPathAttributeId));
 }
 /**
  * Add entity attribute. Overwritten for flat entities support
  *
  * @param int|string $entityTypeId
  * @param string $code
  * @param array $attr
  * @return $this
  */
 public function addAttribute($entityTypeId, $code, array $attr)
 {
     if (isset($this->_flatEntityTables[$entityTypeId]) && $this->_flatTableExist($this->_flatEntityTables[$entityTypeId])) {
         $this->_addFlatAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr);
     } else {
         parent::addAttribute($entityTypeId, $code, $attr);
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Init
  *
  * @param ModuleDataSetupInterface $setup
  * @param Context $context
  * @param CacheInterface $cache
  * @param CollectionFactory $attrGroupCollectionFactory
  * @param CategoryFactory $categoryFactory
  */
 public function __construct(
     ModuleDataSetupInterface $setup,
     Context $context,
     CacheInterface $cache,
     CollectionFactory $attrGroupCollectionFactory,
     CategoryFactory $categoryFactory
 ) {
     $this->categoryFactory = $categoryFactory;
     parent::__construct($setup, $context, $cache, $attrGroupCollectionFactory);
 }
Beispiel #5
0
 /**
  * Update default values for the name field of category and product entities.
  *
  * @return void
  */
 private function updateDefaultValuesForNameAttributes()
 {
     $setup = $this->eavSetup->getSetup();
     $connection = $setup->getConnection();
     $table = $setup->getTable('catalog_eav_attribute');
     $attributeIds = [$this->eavSetup->getAttributeId(\Magento\Catalog\Model\Product::ENTITY, 'name'), $this->eavSetup->getAttributeId(\Magento\Catalog\Model\Category::ENTITY, 'name')];
     foreach (['is_used_in_spellcheck', 'is_used_in_autocomplete'] as $configField) {
         foreach ($attributeIds as $attributeId) {
             $connection->update($table, [$configField => 1], $connection->quoteInto('attribute_id = ?', $attributeId));
         }
     }
 }
 /**
  * Add customer attributes to customer forms
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function installCustomerForms()
 {
     $customer = (int) parent::getEntityTypeId('customer');
     $customerAddress = (int) parent::getEntityTypeId('customer_address');
     $attributeIds = [];
     $select = $this->getSetup()->getConnection()->select()->from(['ea' => $this->getSetup()->getTable('eav_attribute')], ['entity_type_id', 'attribute_code', 'attribute_id'])->where('ea.entity_type_id IN(?)', [$customer, $customerAddress]);
     foreach ($this->getSetup()->getConnection()->fetchAll($select) as $row) {
         $attributeIds[$row['entity_type_id']][$row['attribute_code']] = $row['attribute_id'];
     }
     $data = [];
     $entities = $this->getDefaultEntities();
     $attributes = $entities['customer']['attributes'];
     foreach ($attributes as $attributeCode => $attribute) {
         $attributeId = $attributeIds[$customer][$attributeCode];
         $attribute['system'] = isset($attribute['system']) ? $attribute['system'] : true;
         $attribute['visible'] = isset($attribute['visible']) ? $attribute['visible'] : true;
         if ($attribute['system'] != true || $attribute['visible'] != false) {
             $usedInForms = ['customer_account_create', 'customer_account_edit', 'checkout_register'];
             if (!empty($attribute['adminhtml_only'])) {
                 $usedInForms = ['adminhtml_customer'];
             } else {
                 $usedInForms[] = 'adminhtml_customer';
             }
             if (!empty($attribute['admin_checkout'])) {
                 $usedInForms[] = 'adminhtml_checkout';
             }
             foreach ($usedInForms as $formCode) {
                 $data[] = ['form_code' => $formCode, 'attribute_id' => $attributeId];
             }
         }
     }
     $attributes = $entities['customer_address']['attributes'];
     foreach ($attributes as $attributeCode => $attribute) {
         $attributeId = $attributeIds[$customerAddress][$attributeCode];
         $attribute['system'] = isset($attribute['system']) ? $attribute['system'] : true;
         $attribute['visible'] = isset($attribute['visible']) ? $attribute['visible'] : true;
         if (false === ($attribute['system'] == true && $attribute['visible'] == false)) {
             $usedInForms = ['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address'];
             foreach ($usedInForms as $formCode) {
                 $data[] = ['form_code' => $formCode, 'attribute_id' => $attributeId];
             }
         }
     }
     if ($data) {
         $this->getSetup()->getConnection()->insertMultiple($this->getSetup()->getTable('customer_form_attribute'), $data);
     }
 }
Beispiel #7
0
 /**
  * Upgrade Ship Bundle Items attribute
  *
  * @param EavSetup $eavSetup
  * @return void
  */
 private function upgradeShipmentType(EavSetup $eavSetup)
 {
     $eavSetup->addAttributeToGroup(ProductAttributeInterface::ENTITY_TYPE_CODE, 'Default', 'Bundle Items', 'shipment_type', 1);
     $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'frontend_input', 'select');
     $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'frontend_label', 'Ship Bundle Items');
     $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'source_model', 'Magento\\Bundle\\Model\\Product\\Attribute\\Source\\Shipment\\Type');
     $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'default_value', 0);
     $eavSetup->updateAttribute(ProductAttributeInterface::ENTITY_TYPE_CODE, 'shipment_type', 'is_visible', 1);
 }