I would like to add a price field into my admin form under my product edit page, but I cannot add a “price” type into my fieldset.
$fieldset->addField($attribute->getAttributeCode(), 'price', array(
'label' => Mage::helper('mymod')->__($attribute->getFrontendLabel()),
'class' => $attribute->getIsRequired()?'required-entry':'',
'required' => $attribute->getIsRequired()?true:false,
'name' => $attribute->getAttributeCode(),
'note' => Mage::helper('mymod')->__($attribute->getNote()),
));
it is giving the following error.
Fatal error: Class 'Varien_Data_Form_Element_Price' not found in .. /lib/Varien/Data/Form/Abstract.php on line 144
PS.
I am digging the code in
Mage_Adminhtml_Block_Widget_Form
where in function
_setFieldset
It can use the price as fieldType.
Edit # 11/6:
Digging into _setFieldset(), from the first line
$this->_addElementTypes($fieldset);
will invoke an implementable function
function _getAdditionalElementTypes()
to add additional data type (such as price, gallary..) not in the given list.
I think you just just have to do text because these are the available options:
Button
Checkbox
Checkboxes
Collection
Column
Date
Editor
Fieldset
File
Gallery
Hidden
Image
Imagefile
Label
Link
Multiline
Multiselect
Note
Obscure
Password
Radio
Radios
Reset
Select
Submit
Text
Textarea
Time
Related
i have an ChoiceType::class input field in my form with, now just as an example, two choices:
'choices' => ['type1' => '1', 'type2' => '2']
now when the user select type2 i want to add an exta TextType::class inputfield to the form.
But i dont want to show the input field before and i want it to be required if selected type2 and not if selected type1.
I hope it make sense, i try it to to with javascript and set the attribute to hidden or not, but
then the form is not been send because of the required attribute.
I tried it with form events but did not get it to work in that way.
Thanks
You were on the right way, you have to do it in Javascript. You just need to manage the attr required in Javascript so that the form does not block you with something like this:
Remove the required attribute from a field: document.getElementById("id").required = false;
Make a field required : document.getElementById("id").required = true;
And you can check if the form can be sumitted with : document.getElementById("idForm").reportValidity();.
I using implementation of conditional fields with data-attributes, e.g.:
->add('typeField', EnumType::class, [
'label' => 'Type',
'class' => MyTypeEnum::Class,
])
->add('someField', TextField::class, [
'data-controller' => 'depends-on',
'data-depends-on' => 'my_form_typeField',
'data-depends-value' => MyTypeEnum::OTHER->value,
])
On frontend JS stimulus controller show/hide someField depend on typeField value.
And validation() function in object ('data_class' in formType) make custom validation, e.g.:
/**
* #Assert\Callback
*/
public function validate(ExecutionContextInterface $context)
{
if ($this->typeField !== MyTypeEnum::OTHER) {
$context->buildViolation('message')->atPath('typeField')->addViolation();
}
}
I recently added a 'tooltip description' column to an attribute. I used this following code
$fieldset->addField('tooltip', 'text', array(
'name' => 'tooltip',
'label' => Mage::helper('catalog')->__('Tooltip'),
'title' => Mage::helper('catalog')->__('Tooltip')
));
to add a field in my app\code\core\Mage\Adminhtml\Block\Catalog\Product\Attribute\Edit\Tab\Main.php. This adds the extra field to the attribute-edit screen. I also added a column with type TEXT in the eav_attribute table to make sure the property gets saved when editing your attribute. And it worked perfectly in the backend. See the following Image:
Now I want to show the Tooltip Description value in frontend where the attributes value are shown....say in attributes.phtml page. So what is the code to dispaly it in frontend.
Try following
<?php
foreach ($this->getAttributes() as $_attribute){
echo $_attribute->getTooltip();
}
?>
UPDATE
$attribute_code = $_data['code'];
$attribute_details = Mage::getSingleton("eav/config")->getAttribute('catalog_product', $attribute_code);
$attribute = $attribute_details->getData(); // returns array
echo "<pre>";
print_r($attribute);
Hy Guys!
I am facing a problem regarding datetime field display in Popup. If i add a datetime field to Advanced Search of ProspectLists it get displayed as shown below and works perfectly:
in the custom modules ProspectLists searchdefs advanced_search array it is defined as :
array (
'type' => 'datetime',
'label' => 'LBL_DATE_ENTERED',
'width' => '10%',
'default' => true,
'name' => 'date_entered', ),
but when i try to select a ProspectList from a Prospect List subpanel in Campaigns, the popup that gets displayed render the date field with out dropdown as shown below:
The other problem is this that when i perform search from popup for a specific date it displays nothing.
I am using SugarCRM CE 6.5.11.
Any idea how to display dropdown with date field.?
In method SugarFieldBase::isRangeSearchView you should check condition
$_REQUEST['action']!='Popup'
File include/SugarFields/Fields/Base/SugarFieldBase.php
I remove it from conditions.
protected function isRangeSearchView($vardef)
{
//return !empty($vardef['enable_range_search']) && !empty($_REQUEST['action']) && $_REQUEST['action']!='Popup';
return !empty($vardef['enable_range_search']) && !empty($_REQUEST['action']);
}
I think what you're looking for is the "Ranged Search" attribute.
You can enable it in studio by going to the custom field and checking the "Enable Range Search" checkbox.
Or, you can edit the custom/modules/{module}/metadata/SearchFields.php and add the following to the field in question:
'enable_range_search' => true
Does anyone know how can I add a custom product attribute with a widget renderer?
You can see this in Promo rules if you select SKU you'll got an Ajax popup with product selection.
so how would I go about it?
in :
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY...
In other words, how can I use a widget to select custom attribute values?
EDIT:
The scenario is as follows:
I would like to create a product attribute that will, upon a button click, open a product selection widget.
After the selection, the selected SKU's will go in in a comma delimited format.
This behavior can be seen in the catalog and shopping cart price rules.
If you filter the rule by SKU (SKU attribute must be enabled to "apply to rules"), you'll get a field and a button that will open the product selection widget.
Here is some thoughts that should get you going on the right track:
First, in a setup script, create your entity:
$installer->addAttribute('catalog_product', 'frontend_display', array(
'label' => 'Display Test',
'type' => 'varchar',
'frontend_model' => 'Test_Module/Entity_Attribute_Frontend_CsvExport',
'input' => 'select',
'required' => 0,
'user_defined' => false,
'group' => 'General'
));
Make sure to set the frontend_model to the model that you are going to use. The frontend model affects the display of the attribute (both in the frontend and the adminhtml sections).
Next, create yourself the class, and override one or both of the following functions:
public function getInputType()
{
return parent::getInputType();
}
public function getInputRendererClass()
{
return "Test_Module_Block_Adminhtml_Entity_Renderer_CsvExport";
}
The first (getInputType()) is used to change the input type to a baked in input type (see Varien_Data_Form_Element_* for the options). However, to set your own renderer class, use the latter function - getInputRendererClass(). That is what I am going to demonstrate below:
public function getElementHtml()
{
return Mage::app()->getLayout()->createBlock('Test_Module/Adminhtml_ExportCsv', 'export')->toHtml();
}
Here, to clean things up, I am instantiating another block, as the element itself doesn't have the extra functions to display buttons and the like.
Then finally, create this file:
class Test_Module_Block_Adminhtml_ExportCsv extends Mage_Adminhtml_Block_Widget
{
protected function _prepareLayout()
{
$button = $this->getLayout()->createBlock('adminhtml/widget_button')
->setData(array(
'label' => $this->__('Generate CSV'),
'onclick' => '',
'class' => 'ajax',
));
$this->setChild('generate', $button);
}
protected function _toHtml()
{
return $this->getChildHtml();
}
}
This doesn't cover the AJAX part, but will get you very close to getting the rest to work.
been looking for a solution to add a feature for "Custom Columns"... Meaning, I present a list of columns that I can show the user and he selects the ones he wants to see and after the selection the table is updated and add/removes the needed columns.
Didn't find anything on Google (perhaps it has a different name than what I was looking for...)
Anyone has an Idea on how it can be accomplished?
Thanks in advance!
This is not a complete sample, but can give you some clues on how to implement it. You've to define some kind of form to collect the data about how your grid has to be rendered. I recommend you to create a CFormModel class if there are more than 3 input fields. Create a view file with the form and a div or renderPartial of a file containing a grid:
$form = $this->beginWidget('CActiveFormExt');
echo $form->errorSummary($model);
echo $form->labelEx($model,'column1');
echo $form->dropDownList($model
echo $form->error($model,'column1');
echo CHtml::ajaxSubmitButton('UpdateGrid',array('controller/grid'),
array('update'=>'#grid'),
$this->endWidget();
// you can render the 'default options' before any ajax update
$this->renderPartial('_grid',array($customColumns=>array('id','name'),'dataProvider'=>$dataProvider));
In the _grid.php view file:
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'grid',
'dataProvider'=>$dataProvider,
'columns' => $customColumns;
));
In the controller:
function actionGrid(){
// recover the form data, and build the custom columns array
$customColumns = array();
$customColumns[] = '.....';
$dataProvider = ...;
$this->renderPartial('_formTrabajo', array('customColumns' => $idSiniestro, 'dataProvider' => $dataProvider'), false);
}
When you click the ajaxSubmitButton, the form is sent to the url specified through ajax, and the reply from the controller must contain the renderPartial of the view containing the grid, so the jQuery call can replace the html correctly. You must pass an array from your controller to the partial view of the grid, with the custom list of columns you want to display.