コード例 #1
0
 /**
  * @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);
     }
 }
コード例 #2
0
ファイル: UpgradeData.php プロジェクト: smile-sa/elasticsuite
 /**
  * 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));
 }
コード例 #3
0
ファイル: InstallData.php プロジェクト: smile-sa/elasticsuite
 /**
  * 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));
         }
     }
 }