How to add a WYSIWYG editor to Magento custom options - php

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

Related

prestashop and helperlist active

I'm trying to add à new column in catalog/product on prestashop 1.6 with Helperlist.
The column is similar to the "active" column, it's à simple switch button that turn the option to true or false.
I edited the controller AdminProduct to add the field, the field display the correct value (true or false) of the field list, but the button is not working (it's doesn't switch to true of false) like the active button do.
The active button code :
$this->fields_list['active'] = array(
'title' => $this->l('Status'),
'active' => 'status',
'filter_key' => $alias.'!active',
'align' => 'text-center',
'type' => 'bool',
'class' => 'fixed-width-sm',
'orderby' => false
);
my code :
$this->fields_list['AllShopActive'] = array(
'title' => $this->l('All Shop'),
'active' => 'AllShopActive',
'filter_key' => 'a!AllShopActive',
'align' => 'text-center',
'type' => 'bool',
'class' => 'fixed-width-sm',
'orderby' => false
);
I've looked in the helperlist doc on prestashop, but the documentation is very light and it's the first time I use HelperList, any help would be nice.
I know the problem come from this line : 'active' => 'AllShopActive'
but I don't know how to solve it.
Thank you for your help.
The simplest way is to implement it with ajax. To do it you need to add 'ajax' => true to your definition:
$this->fields_list['AllShopActive'] = array(
'title' => $this->l('All Shop'),
'active' => 'AllShopActive',
'filter_key' => 'a!AllShopActive',
'align' => 'text-center',
'type' => 'bool',
'class' => 'fixed-width-sm',
'orderby' => false,
'ajax' => true
);
and than add the method to controller. Something like
public function ajaxProcessAllShopActiveProduct()
{
your code here
}

Magento 2 Attribute Not Show In Navigation

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' => ''
]
);

How to validate multiply select using Zend Framework 2

I am trying to validate a multiply select using input filter, but every time I see a error. The error is "notInArray":"The input was not found in the haystack".(I use ajax but it doesn`t metter).
I will show part of my code to be more clear.
in Controller:
if ($request->isPost()) {
$post = $request->getPost();
$form = new \Settings\Form\AddUserForm($roles);//
$form->get('positions')
->setOptions(
array('value_options'=> $post['positions']));
//.... more code...
When I put print_r($post['positions']); I see:
array(0 => 118, 1 => 119)
in ..../form/UserForm.php I create the multiply element
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'multiple' => 'multiple',
'id' => 'choosed_positions',
),
'required' => false,
'name' => 'positions',
));
and in the validation file the code is:
$inputFilter->add($factory->createInput(array(
'name' => 'positions',
'required' => false,
'validators' => array(
array(
'name' => 'InArray',
'options' => array(
'haystack' => array(118,119),
'messages' => array(
'notInArray' => 'Please select your position !'
),
),
),
),
What can be the reason every time to see this error, and how I can fix it?
By default selects have attached InArray validator in Zend Framework 2.
If you are adding new one - you will have two.
You should disable default one as follow:
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'options' => array(
'disable_inarray_validator' => true, // <-- disable
),
'attributes' => array(
'multiple' => 'multiple',
'id' => 'choosed_positions',
),
'required' => false,
'name' => 'positions',
));
And you should get rid of the additional error message.
Please let us know if that would helped you.

Adding Custom attribute in forms

I am using magento V1.5. I am working on Customer EAV & have tried to create another EAV module.
I have added few attributes in customer entity. Now MY requirement is those attributes must be editable from frontend as well as backend.
Please tell me how to add those attributes in forntend form (customer edit form). & Tell me what to do in backend to have those options to be editable.
I am thinking if there is a way in admin like in our Form.php we prepare form with adding elements to it. then we not need to write a code to create actual html. Magento automatically does it. SO idea is it must also load the new attributes in that was just added. (like they appear in product edit.)
Second Issue is, Can u guys tell me what should I write in my Grid.php >> prepareCollection (for other EAV module ). so that it must get all the attributes with their values ( or may be few )
here is something that I have in my Grid.php but its not working
protected function _prepareCollection()
{
$collection = Mage::getModel('pincodes/eavpincodes')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
& this is my collection file
class Namespace_Pincodes_Model_Resource_Eav_Mysql4_Eavpincodes_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
{
protected function _construct()
{
$this->_init('pincodes/eavpincodes');
}
}
But its not returning anything in my grid
& here is my Attribute collection file
class Inkfruit_Pincodes_Model_Resource_Eav_Mysql4_Attribute_Collection extends Mage_Eav_Model_Mysql4_Entity_Attribute_Collection
{
public function _construct()
{
$this->_init('pincodes/resource_eav_attribute', 'eav/entity_attribute');
}
protected function _initSelect()
{
$this->getSelect()->from(array('main_table' => $this->getResource()->getMainTable()))
->where('main_table.entity_type_id=?', Mage::getModel('eav/entity')->setType('pincodes_eavpincodes')->getTypeId())
->join(
array('additional_table' => $this->getTable('pincodes/eavpincodes')),
'additional_table.attribute_set_id=main_table.attribute_id' // I think this sql need to be changed but I have no idea what it'll be
);
return $this;
}
}
Guys thank you so much. This forum has been specially very helpful to me
Regards
SAM
Ok guys I have created a separate module for customers that has one mysql4_install file & it goes as follows
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer', 'profile_image', array(
'label' => 'Profile Image',
'type' => 'varchar',
'input' => 'file',
'visible' => true,
'required' => false,
'user_defined' => true,
));
$setup->addAttribute('customer', 'mobile', array(
'label' => 'Mobile Number',
'type' => 'int',
'input' => 'text',
'visible' => true,
'required' => false,
'user_defined' => true,
));
$installer->endSetup();
$installer->installEntities();
But when I hit the url for this module I see no error but these attributes are not in my database.
I also have created Entity_Setup file & it goes as follows I think its incorrect but I gave it a try
<?php
class Namespace_Customer_Entity_Setup extends Mage_Eav_Model_Entity_Setup
{
public function getDefaultEntities()
{
return array (
'customer' => array(
'entity_model' => 'customer/customer',
'attribute_model' => 'customer/attribute',
'table' => 'customer/entity',
'attributes' => array(
'profile_image' => array(
//the EAV attribute type, NOT a mysql varchar
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => 'Profile Image',
'input' => 'file',
'class' => '',
'source' => '',
// store scope == 0
// global scope == 1
// website scope == 2
'global' => 0,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => true,
'filterable' => true,
'comparable' => false,
'visible_on_front' => false,
'unique' => false
),
'mobile' => array(
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => 'Mobile Number',
'input' => 'text',
'class' => '',
'source' => '',
'global' => 0,
'visible' => true,
'required' => true,
'user_defined' => true,
'default' => '',
'searchable' => true,
'filterable' => true,
'comparable' => false,
'visible_on_front' => false,
'unique' => false
),
),
)
);
}
}
But I see nothing, not any new attribute in database.
Can u guys help here whats wrong??
Thanks
Guys here is My solution. the above answers worked for adding attribute to database only
My question has three parts.
1. Adding attributes to entity in database.
Ans. the above install scripts worked. using a Setup.php & mysql_install/ mysql_upgrade script.
2. Attribute should be editable from Frontend
Ans. We need to modify the file app/design/fontend/default//template/customer/form/edit.phtml
3. Attribute must be editable from Backend
Ans. for that we need to add this snippet in our config.xml
<global>
<fieldsets>
<customer_account>
<create>1</create><update>1</update>
</customer_account>
</fieldsets>
</global>
this will do everything
Hope this will help somebody
This worked for me, notice the additional lines:
<?php
class Millena_CustomerExportAdditions_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
{
public function getDefaultEntities()
{
return array(
'customer' => array(
'entity_model' =>'customer/customer',
'attribute_model' => 'customer/attribute',
'table' => 'customer/entity',
'additional_attribute_table' => 'customer/eav_attribute',
'entity_attribute_collection' => 'customer/attribute_collection',
'attributes' => array(
'export_status' => array(
//'group' => 'Group/Tab',
'label' => 'Customer Export Status',
'type' => 'int',
'input' => 'select',
'default' => '0',
'class' => '',
'backend' => '',
'frontend' => '',
'source' => 'millena_customerExportAdditions/customer_attribute_source_exportStatus',
'global' => 2, //global scope
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false
)
)
)
);
}
}
Install script is simply:
<?php
$installer = $this;
$installer->installEntities();
Having same issue here. Using addAttribute in 1.5.0.1 seems to add it into database but customer admin won't render it.
This method works fine with product and category attributes. And in 1.4.0.0 it works for customers too.
In Magento chagelog there is bullet point under improvements about customer attribute rendering. I'll start checking it next.

How to add an attribute programmatically

I'd like to add an attribute to products, and I want to do this programmatically. So I added a mysql-install-0.1.0.php to a module of mine, and I added this (inspired from existing examples) :
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'collection', array(
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => 'Collection',
'input' => 'text',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => false,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'apply_to' => '',
'is_configurable' => false
));
$installer->endSetup();
Syntax seems OK, but when it comes to execute this part of the code, here is the problem :
Fatal error: Call to undefined method
Mage_Core_Model_Resource_Setup::addAttribute()
in
/home/frleq/Dev/projets/AVIP/WORKSPACE/avip_magento/app/code/local/Smile/Magentaho/sql/magentaho_setup/mysql4-install-0.1.0.php
on line 7
Do you see what's wrong? Code isn't so complicated, and it is inspired from existing and worling ones...
Thank you
You are using the wrong setup class. Check your setup class declaration in config.xml. You are using Mage_Core_Model_Resource_Setup. Try Mage_Eav_Model_Entity_Setup instead.
If you want to use product-related options (filterable, searchable etc.), you should use Mage_Catalog_Model_Resource_Eav_Mysql4_Setup class.
In latest versions of Magento you should use Mage_Catalog_Model_Resource_Setup class.

Categories