I am trying to add a custom input field to the account information tab of a customer in admin. i have successfully been able to create a custom attribute in the eav table for my input, but have been unsuccessful in finding how to make my input show up. curious of anyone has any good resources on how to do this?
The above link doesn't work anymore. I found a better explanation at http://www.excellencemagentoblog.com/customer-registration-fields-magento1-6 . If you just do the first steps you will only have the added fields in the admin.
The fastest way is to create a php file and access it through browser add the following content to file.
define('MAGENTO', realpath(dirname(__FILE__)));
ini_set('memory_limit', '32M');
set_time_limit (0);
require_once MAGENTO . '/../app/Mage.php';
Mage::app();
$newFields = array(
'custom_attribute' => array(
'type' => 'text',
'label' => 'Customer Custom Attribute'
)
);
$entities = array('customer');
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
foreach($newFields as $attributeName => $attributeDefs) {
foreach ($entities as $entity) {
$setup->addAttribute($entity, $attributeName, array(
'position' => 1,
'type' => $attributeDefs['type'],
'label' => $attributeDefs['label'],
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'unique' => 0,
'is_configurable' => 0,
'position' => 1,
));
}
}
You have to tell the attribute which forms it's used in:
Mage::getModel('customer/attribute')
->loadByCode('customer', 'your_attrib_code')
->setUsedInForms(array('adminhtml_customer'))
->save();
This can be put in a standard Magento upgrade script for convenience (usually the same script that originally created the attribute, or the one right after it).
Related
Whole day I have been working on this trouble but could not find needed information. Okay, I need adding new fields in the ACF group by PHP. I tested function acf_add_local_field. Nothing working. I see that function go to $store->set( $key, $field )->alias( $key, $name );. And everything should be okay but fields not add. Please, help me. How I can add new ACF fields by PHP? Only fields without group. I have needed group.
acf_add_local_field(
array(
'key' => "generalInfo_".$value,
'label' => $value,
'name' => "generalInfo_".$value,
'type' => 'text',
'parent' => 'generalInfo',
'parent_layout' => 'group_6187fed087950',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array('width' => '70')));
}
I add this code to a custom page template.
I have a problem when applying magento 2.1.9 to my project.
My attribute is ab_size
I have created that attribute with code blow.
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
$entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
foreach ($singleAttributeCodes as $key => $label) {
$categorySetup->removeAttribute($entityTypeId, $key);
$categorySetup->addAttribute(
$entityTypeId,
$key,
[
'type' => 'varchar',
'label' => $label,
'input' => 'select',
'required' => false,
'sort_order' => $sortOrder,
'visible' => true,
'user_defined' => true,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'filterable' => 0,
'visible_on_front' => true,
'used_in_product_listing' => true,
'group' => $group,
'apply_to' => 'simple,configurable,bundle,downloadable,grouped',
]
);
}
With config in the backend.
Enable filter (with result) done
Category Is Anchor done
Reindex done
Enable Category flat done
Enable Product flat done
Reindex all data done
Clear cache done
Use magento clean doesn't have any extension done
Check with attribute color (done it show in navigation)
Product Price Show
Category Show
about my system information
CentOS 7.0
Litespeed
Php7.0
Magento CE 2.1.9
I have debugged that the product collection buckets return empty
I think that problem with creating attribute code, has anyone got the same problem.
Thank anyone have tips.
With select attribute we must use type of int..
I think you have messed your attributes with this code.
Looking at it, it removes all the attributes and adds them but as type varchar, which may not be applicable to all attributes.
I would suggest resetting your Magento database, and then add the attribute using code like the following.
As I do not know what you are planning to use this attribute, some of the settings bellow may not apply to your use case.
$categorySetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'ab_size',
[
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => 'AB Size',
'input' => 'select',
'class' => '',
'source' => '',
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => 0,
'searchable' => false,
'filterable' => true,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]
);
Im trying to implement a wysiwyg editor under text-option in Magentos custom options, but am failing there. I have already searched for several components, but can't get it together though.
I want that editor to appear in the field where the WYSIWYG Value-textarea is right now.
Other source either don't go into detail or aren't working for 1.9.1.
What I have so far: [WR is companyname and EPO is my module]
I've found this snippet, which is used to place a wysiwyg editor on a cms page within a _prepareForm function:
<?php
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled() && ($block = $this->getLayout()->getBlock('head'))) {
$block->setCanLoadTinyMce(true);
}
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save'),
'method' => 'post'
));
$fieldset = $form->addFieldset('base_fieldset', array(
'legend' => Mage::helper('wr_epo')->__("Some Information"),
'class' => 'fieldset-wide',
));
$wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config');
$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('wr_epo')->__('Description'),
'title' => Mage::helper('wr_epo')->__('Description'),
'style' => 'height: 600px;',
'wysiwyg' => true,
'required' => false,
'config' => $wysiwygConfig
));?>
I had an issue like this no to long ago (client wanted custom stuff in an option).
I dont know if this is exactly what you want. But heres what i did:
I made a php file in the root of my magento.
And then i added this code. I found it on stackoverflow. If anyone knows where it comes from be even better.
ini_set('display_errors',0);
require_once 'app/Mage.php';
Mage::app();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
function createNewAttributeSet($name) {
Mage::app('default');
$modelSet = Mage::getModel('eav/entity_attribute_set')
->setEntityTypeId(4) // 4 == "catalog/product"
->setAttributeSetName($name);
$modelSet->save();
$modelSet->initFromSkeleton(4)->save(); // same thing
}
// Replace your attribute name with "extra_info"
$setup->addAttribute('catalog_category', 'extra_info', array(
'group' => 'General Information',
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'Extra Information',
'wysiwyg_enabled' => true,
'visible_on_front' => true,
'is_html_allowed_on_front' => true,
'input' => 'textarea',
'class' => '',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => 1,
'required' => 0,
'user_defined' => 0,
'default' => '',
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'unique' => 0,
'position' => 1,
));
$setup->updateAttribute('catalog_category', 'extra_info', 'is_wysiwyg_enabled', 1);
$setup->updateAttribute('catalog_category', 'extra_info', 'is_html_allowed_on_front', 1);
I do however Think you want to include
'wysiwyg_enabled' => true,
Rather than
'wysiwyg' => true,
(this is refering to your code you pasted earlier)
Other reading:
Things i found that helped with my issues:
https://www.atwix.com/magento/add-category-attribute/
https://docs.magento.com/m1/ce/user_guide/catalog/product-options-custom.html
I've written a module that adds an attribute to the customer model, and it's worked fine.
I wanted to extend the sales/order_shipment model and add another attribute, so I just used the same reference that I had used for the installer for adding the new customer attribute.
I relied on Magento finding and installing the module a file with the following path and name app/code/local/[namespace]/[module_name]/sql/install-01.php
I've set the installer to the value of $this during the setup of the module initially:
$installer = $this;
$installer->startSetup();
I kept the same reference for the installer and just added a new field:
$installer->addAttribute('customer','sap_bp_id',
array(
'type' => 'varchar',
'label' => 'SAP Business One Business Partner ID',
'input' => 'text',
'required' => false,
'visible' => true,
'visible_on_front' => false,
'global' => 1,
'position' => 62,
)
);
$installer->addAttribute('shipment','sap_doc_num',
array(
'type' => 'varchar',
'label' => 'SAP Business One Document Number',
'input' => 'text',
'required' => false,
'visible' => true,
'visible_on_front' => false,
'global' => 1,
'position' => 62,
)
);
It's worked just fine, but I want to know this:
Is this the correct method for adding a new attribute for different models in the same installation file? Is there a better method? Have I missed anything?
I'm writing an import module to import configurable products into magento, which works quite fine. I've tweaked the import so that it can create all necessary attribute sets, attributes and attribute options needed for creating the configurable products. So far everything works ... quite everything.
When the import creates a new attribute, it can not create the configurable product. When I edit the new attribute in the backend and save it without changes, a message appears which tells me to update some indexes. After I have updated the product flat data index, I can run the import again and everything works fine.
I've tried to ways to create a new attribute:
$setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
$setup->addAttribute(
$this->getEntityTypeId(),
$code,
array(
'attribute_code' => $code,
'label' => ucfirst($code),
//'group' => $attributeSet->getId(),
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'input' => 'select',
'unique' => 0,
'required' => 0,
'configurable' => 1,
'filterable' => 1,
'visible_on_front' => 1,
'used_in_product_listing' => 1,
'frontend_label' => array(
$code
)
)
);
The other way is:
$attribute = Mage::getModel("catalog/resource_eav_attribute");
$attribute->addData(
array(
'entity_type_id' => $this->getEntityTypeId(),
'attribute_code' => $code,
'label' => ucfirst($code),
//'group' => $attributeSet->getId(),
'is_user_defined' => 1,
'is_global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'frontend_input' => 'select',
'is_unique' => 0,
'is_required' => 0,
'is_configurable' => 1,
'is_filterable' => 1,
'is_visible_on_front' => 1,
'is_used_in_product_listing'=> 1,
'frontend_label' => array(
$code
)
)
);
$attribute->save();
Both codes create the attribute well but I can't use it to create configurable Attributes. I've tried to manually run the index scripts but this does not help me.
What am I doing wrong? Is creating new attributes somehow the black magic of magento? :-D
I forgot to set the backend type for the new attribute to "int" so it was automatically set to static (which means magento looks for it in the entity table).
The other thing is that i couldn't set the attribute value like this:
$model->setData("newattributecode", 123);
Magento just didn't save the attribute. Instead I had to use the undocumented function Mage_Catalog_Model_Product::addAttributeUpdate() to save the attribute value of this model:
$model->addAttributeUpdate("newattributecode", 123, 0);