本文整理汇总了PHP中Varien_Data_Form::getElements方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Form::getElements方法的具体用法?PHP Varien_Data_Form::getElements怎么用?PHP Varien_Data_Form::getElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Data_Form
的用法示例。
在下文中一共展示了Varien_Data_Form::getElements方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepareEditForm
/**
* @param Open_Gallery_Model_Item $item
* @param Varien_Data_Form $form
* @return $this|Open_Gallery_Helper_Item_Interface
*/
public function prepareEditForm(Open_Gallery_Model_Item $item, Varien_Data_Form $form)
{
$isReadonlyMode = false;
foreach ($form->getElements() as $element) {
/** @var Varien_Data_Form_Element_Abstract $element */
if ($element instanceof Varien_Data_Form_Element_Fieldset && 'general_information' == $element->getId()) {
$fieldSet = $element;
$fieldSet->addField('value', 'image', array('name' => 'item[value]', 'label' => $this->__('Image File'), 'title' => $this->__('Image File'), 'required' => !$item->getData('value'), 'disabled' => $isReadonlyMode, 'note' => $this->__('Allowed format(s): <strong>%s</strong>', implode(', ', $item->getAllowedFormats())) . '<br/>' . $this->__('Your server allow you to upload files not more than <strong>%s</strong>. You can modify <strong>post_max_size</strong> (currently is %s) and <strong>upload_max_filesize</strong> (currently is %s) values in php.ini if you want to upload larger files.', $this->getDataMaxSize(), $this->getPostMaxSize(), $this->getUploadMaxSize())));
break;
}
}
return $this;
}
示例2: getFields
public function getFields()
{
$form = new Varien_Data_Form();
//todo add logic for getting fields by step
$dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
switch (intval(Mage::helper('gomage_checkout')->getConfigData('deliverydate/dateformat'))) {
case GoMage_DeliveryDate_Model_Adminhtml_System_Config_Source_Dateformat::EUROPEAN:
$dateFormatIso = 'dd.MM.yyyy';
break;
default:
$dateFormatIso = 'MM.dd.yyyy';
}
$element = new GoMage_DeliveryDate_Model_Form_Element_Date(array('name' => 'deliverydate[date]', 'label' => $this->__('Select a Date:'), 'title' => $this->__('Delivery Date'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'format' => $dateFormatIso, 'no_span' => 1));
$element->setId('delivery_date');
$interval = intval(Mage::helper('gomage_checkout')->getConfigData('deliverydate/interval_days'));
$available_days = Mage::helper('gomage_deliverydate')->getDeliveryDays();
$available_days = array_keys($available_days);
$shift = 0;
$date_value = time() + $interval * 60 * 60 * 24;
$w = date('w', $date_value);
if (!in_array($w, $available_days)) {
if ($w > max($available_days)) {
$shift = 7 - $w + min($available_days);
} else {
foreach ($available_days as $d) {
if ($d > $w) {
$shift = $d - $w;
break;
}
}
}
}
$date_value = time() + ($interval + $shift) * (60 * 60 * 24);
while ($this->isNonWorkingDay($date_value) || !in_array(date('w', $date_value), $available_days)) {
$date_value += 60 * 60 * 24;
}
$element->setValue(date('d.m.Y', $date_value));
$form->addElement($element, false);
$values = array();
$delivery_days = Mage::helper('gomage_deliverydate')->getDeliveryDays();
if (isset($delivery_days[date('w', $date_value)])) {
$values_options = Mage::getModel('gomage_deliverydate/adminhtml_system_config_source_hour')->toOptionHash();
foreach ($delivery_days[date('w', $date_value)] as $value) {
$values[$value] = $values_options[$value];
}
}
$form->addField('delivery_time', 'select', array('name' => 'deliverydate[time]', 'title' => $this->__('Delivery Time'), 'no_span' => 1, 'values' => $values));
return $form->getElements();
}
示例3: getFormElements
public function getFormElements()
{
if (!is_null($this->_formElements)) {
return $this->_formElements;
}
$attributes = $this->getAttributes();
$attributesToRender = $this->_getElementsToRender();
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('amcustomerattr' . rand(0, 100), array('class' => 'amcustomerattr'));
/**
* Loading current customer, it we are on edit page
*/
$customer = Mage::getSingleton('customer/session')->isLoggedIn() ? Mage::getSingleton('customer/session')->getCustomer() : null;
$currentStore = $customer ? $customer->getStoreId() : Mage::app()->getStore()->getId();
$isAnyAttributeApplies = false;
$customerAttributes = Mage::getSingleton('customer/session')->getAmcustomerattr();
foreach ($attributes as $attribute) {
if (!empty($attributesToRender) && !in_array($attribute->getAttributeCode(), $attributesToRender)) {
continue;
}
if ($attribute->getAccountFilled() && $this->_isCustomerEdit() && $customer->getData($attribute->getAttributeCode()) || $attribute->getBillingFilled() && $this->_isCheckout() && $customer && $customer->getData($attribute->getAttributeCode())) {
continue;
}
$storeIds = explode(',', $attribute->getData('store_ids'));
if (!in_array($currentStore, $storeIds) && 0 != $currentStore && !in_array(0, $storeIds)) {
continue;
}
$isAnyAttributeApplies = true;
$inputType = $attribute->getFrontend()->getInputType();
if (!$inputType) {
continue;
}
$typeInternal = $attribute->getTypeInternal();
$inputTypes = array('statictext' => 'note', 'selectgroup' => 'select');
if ($typeInternal) {
$inputType = isset($inputTypes[$typeInternal]) ? $inputTypes[$typeInternal] : $typeInternal;
}
$fieldType = $inputType;
// $rendererClass = $attribute->getFrontend()->getInputRendererClass();
$renderer = "Amasty_Customerattr_Block_Data_Form_Element_" . ucfirst($inputType);
if (class_exists($renderer)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $renderer);
}
$fieldName = $this->_isCheckout() ? 'billing[amcustomerattr][' . $attribute->getAttributeCode() . ']' : 'amcustomerattr[' . $attribute->getAttributeCode() . ']';
if ('file' == $inputType) {
$fieldName = 'amcustomerattr[' . $attribute->getAttributeCode() . ']';
}
// default_value
$attributeValue = '';
if ('statictext' != $typeInternal) {
if ($customer) {
$attributeValue = $customer->getData($attribute->getAttributeCode());
} elseif ($attribute->getData('default_value')) {
$attributeValue = $attribute->getData('default_value');
}
// if for example there was page reload with error, we putting attribute back from session
if (isset($customerAttributes[$attribute->getAttributeCode()])) {
$attributeValue = $customerAttributes[$attribute->getAttributeCode()];
}
} else {
$attributeValue = $attribute->getData('default_value');
}
$fileAttributeValue = '';
if ('file' == $inputType) {
$fileAttributeValue = $attributeValue;
$attributeValue = '';
}
// applying translations
$translations = $attribute->getStoreLabels();
if (isset($translations[Mage::app()->getStore()->getId()])) {
$attributeLabel = $translations[Mage::app()->getStore()->getId()];
} else {
$attributeLabel = $attribute->getFrontend()->getLabel();
}
$required = 0;
if ($attribute->getIsRequired() || $attribute->getRequiredOnFront()) {
$required = 1;
$this->_hasRequired = true;
}
if ($attribute->getFrontend()->getClass()) {
$this->_hasValidation = true;
}
$config = array('name' => $fieldName, 'label' => $attributeLabel, 'class' => $attribute->getFrontend()->getClass(), 'required' => $required, 'disabled' => $attribute->getIsReadOnly(), 'note' => $attribute->getNote(), 'value' => $attributeValue, 'text' => $attributeValue);
/*if ('selectgroup' == $attribute->getTypeInternal()
&& Mage::getSingleton('customer/session')->isLoggedIn()
&& !Mage::getStoreConfig('amcustomerattr/general/allow_change_group')) {
$config['disabled'] = 1;
}*/
$afterElementHtml = '';
if ('date' == $inputType) {
$config['readonly'] = 1;
$config['onclick'] = 'amcustomerattr_trig(' . $attribute->getAttributeCode() . '_trig)';
$afterElementHtml .= '<script type="text/javascript">' . 'function amcustomerattr_trig(id)' . '{ $(id).click(); }' . '</script>';
}
$element = $fieldset->addField($attribute->getAttributeCode(), $fieldType, $config)->setEntityAttribute($attribute);
if ('file' == $inputType) {
if ($fileAttributeValue) {
// to Controller
$fileName = Mage::helper('amcustomerattr')->cleanFileName($fileAttributeValue);
//.........这里部分代码省略.........
示例4: _prepareForm
/**
* Prepare form before rendering HTML
*
* @return Enterprise_Cms_Block_Adminhtml_Cms_Hierarchy_Edit_Form
*/
protected function _prepareForm()
{
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getUrl('*/*/save'), 'method' => 'post'));
/**
* Define general properties for each node
*/
$fieldset = $form->addFieldset('node_properties_fieldset', array('legend' => Mage::helper('enterprise_cms')->__('Page Properties')));
$fieldset->addField('nodes_data', 'hidden', array('name' => 'nodes_data'));
$fieldset->addField('removed_nodes', 'hidden', array('name' => 'removed_nodes'));
$fieldset->addField('node_id', 'hidden', array('name' => 'node_id'));
$fieldset->addField('node_page_id', 'hidden', array('name' => 'node_page_id'));
$fieldset->addField('node_label', 'text', array('name' => 'label', 'label' => Mage::helper('enterprise_cms')->__('Title'), 'required' => true, 'onchange' => 'hierarchyNodes.nodeChanged()', 'tabindex' => '10'));
$fieldset->addField('node_identifier', 'text', array('name' => 'identifier', 'label' => Mage::helper('enterprise_cms')->__('URL Key'), 'required' => true, 'class' => 'validate-identifier', 'onchange' => 'hierarchyNodes.nodeChanged()', 'tabindex' => '20'));
$fieldset->addField('node_label_text', 'note', array('label' => Mage::helper('enterprise_cms')->__('Title')));
$fieldset->addField('node_identifier_text', 'note', array('label' => Mage::helper('enterprise_cms')->__('URL Key')));
$fieldset->addField('node_preview', 'link', array('label' => Mage::helper('enterprise_cms')->__('Preview'), 'href' => '#', 'value' => Mage::helper('enterprise_cms')->__('No preview available')));
$yesNoOptions = Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray();
/**
* Define field set with elements for root nodes
*/
if (Mage::helper('enterprise_cms/hierarchy')->isMetadataEnabled()) {
$fieldset = $form->addFieldset('metadata_fieldset', array('legend' => Mage::helper('enterprise_cms')->__('Render Metadata in HTML Head')));
$fieldset->addField('meta_first_last', 'select', array('label' => Mage::helper('enterprise_cms')->__('First'), 'title' => Mage::helper('enterprise_cms')->__('First'), 'name' => 'meta_first_last', 'values' => $yesNoOptions, 'onchange' => 'hierarchyNodes.nodeChanged()', 'container_id' => 'field_meta_first_last', 'tabindex' => '30'));
$fieldset->addField('meta_next_previous', 'select', array('label' => Mage::helper('enterprise_cms')->__('Next/Previous'), 'title' => Mage::helper('enterprise_cms')->__('Next/Previous'), 'name' => 'meta_next_previous', 'values' => $yesNoOptions, 'onchange' => 'hierarchyNodes.nodeChanged()', 'container_id' => 'field_meta_next_previous', 'tabindex' => '40'));
$fieldset->addField('meta_cs_enabled', 'select', array('label' => Mage::helper('enterprise_cms')->__('Enable Chapter/Section'), 'title' => Mage::helper('enterprise_cms')->__('Enable Chapter/Section'), 'name' => 'meta_cs_enabled', 'values' => $yesNoOptions, 'onchange' => 'hierarchyNodes.nodeChanged()', 'container_id' => 'field_meta_cs_enabled', 'tabindex' => '45'));
$fieldset->addField('meta_chapter_section', 'select', array('label' => Mage::helper('enterprise_cms')->__('Chapter/Section'), 'title' => Mage::helper('enterprise_cms')->__('Chapter/Section'), 'name' => 'meta_chapter_section', 'values' => Mage::getSingleton('enterprise_cms/source_hierarchy_menu_chapter')->toOptionArray(), 'onchange' => 'hierarchyNodes.nodeChanged()', 'container_id' => 'field_meta_chapter_section', 'tabindex' => '50'));
}
/**
* Pagination options
*/
$pagerFieldset = $form->addFieldset('pager_fieldset', array('legend' => Mage::helper('enterprise_cms')->__('Pagination Options for Nested Pages')));
$pagerFieldset->addField('pager_visibility', 'select', array('label' => Mage::helper('enterprise_cms')->__('Enable Pagination'), 'name' => 'pager_visibility', 'values' => Mage::getSingleton('enterprise_cms/source_hierarchy_visibility')->toOptionArray(), 'value' => Enterprise_Cms_Helper_Hierarchy::METADATA_VISIBILITY_PARENT, 'onchange' => "hierarchyNodes.metadataChanged('pager_visibility', 'pager_fieldset')", 'tabindex' => '70'));
$pagerFieldset->addField('pager_frame', 'text', array('name' => 'pager_frame', 'label' => Mage::helper('enterprise_cms')->__('Frame'), 'onchange' => 'hierarchyNodes.nodeChanged()', 'container_id' => 'field_pager_frame', 'note' => Mage::helper('enterprise_cms')->__('How many Links to display at once'), 'tabindex' => '80'));
$pagerFieldset->addField('pager_jump', 'text', array('name' => 'pager_jump', 'label' => Mage::helper('enterprise_cms')->__('Frame Skip'), 'onchange' => 'hierarchyNodes.nodeChanged()', 'container_id' => 'field_pager_jump', 'note' => Mage::helper('enterprise_cms')->__('If the Current Frame Position does not cover Utmost Pages, will render Link to Current Position plus/minus this Value'), 'tabindex' => '90'));
/**
* Context menu options
*/
$menuFieldset = $form->addFieldset('menu_fieldset', array('legend' => Mage::helper('enterprise_cms')->__('Navigation Menu Options')));
$menuFieldset->addField('menu_excluded', 'select', array('label' => Mage::helper('enterprise_cms')->__('Exclude from Navigation Menu'), 'name' => 'menu_excluded', 'values' => $yesNoOptions, 'onchange' => "hierarchyNodes.nodeChanged()", 'container_id' => 'field_menu_excluded', 'tabindex' => '100'));
$menuFieldset->addField('menu_visibility', 'select', array('label' => Mage::helper('enterprise_cms')->__('Enable Navigation Menu'), 'name' => 'menu_visibility', 'values' => $yesNoOptions, 'onchange' => "hierarchyNodes.metadataChanged('menu_visibility', 'menu_fieldset')", 'container_id' => 'field_menu_visibility', 'tabindex' => '110'));
$menuFieldset->addField('menu_layout', 'select', array('label' => Mage::helper('enterprise_cms')->__('Menu Layout'), 'name' => 'menu_layout', 'values' => Mage::getSingleton('enterprise_cms/source_hierarchy_menu_layout')->toOptionArray(true), 'onchange' => "hierarchyNodes.nodeChanged()", 'container_id' => 'field_menu_layout', 'tabindex' => '115'));
$menuBriefOptions = array(array('value' => 1, 'label' => Mage::helper('enterprise_cms')->__('Only Children')), array('value' => 0, 'label' => Mage::helper('enterprise_cms')->__('Neighbours and Children')));
$menuFieldset->addField('menu_brief', 'select', array('label' => Mage::helper('enterprise_cms')->__('Menu Detalization'), 'name' => 'menu_brief', 'values' => $menuBriefOptions, 'onchange' => "hierarchyNodes.nodeChanged()", 'container_id' => 'field_menu_brief', 'tabindex' => '120'));
$menuFieldset->addField('menu_levels_down', 'text', array('name' => 'menu_levels_down', 'label' => Mage::helper('enterprise_cms')->__('Maximal Depth'), 'onchange' => 'hierarchyNodes.nodeChanged()', 'container_id' => 'field_menu_levels_down', 'note' => Mage::helper('enterprise_cms')->__('Node Levels to Include'), 'tabindex' => '130'));
$menuFieldset->addField('menu_ordered', 'select', array('label' => Mage::helper('enterprise_cms')->__('List Type'), 'title' => Mage::helper('enterprise_cms')->__('List Type'), 'name' => 'menu_ordered', 'values' => Mage::getSingleton('enterprise_cms/source_hierarchy_menu_listtype')->toOptionArray(), 'onchange' => 'hierarchyNodes.menuListTypeChanged()', 'container_id' => 'field_menu_ordered', 'tabindex' => '140'));
$menuFieldset->addField('menu_list_type', 'select', array('label' => Mage::helper('enterprise_cms')->__('List Style'), 'title' => Mage::helper('enterprise_cms')->__('List Style'), 'name' => 'menu_list_type', 'values' => Mage::getSingleton('enterprise_cms/source_hierarchy_menu_listmode')->toOptionArray(), 'onchange' => 'hierarchyNodes.nodeChanged()', 'container_id' => 'field_menu_list_type', 'tabindex' => '150'));
if ($this->isLockedByOther()) {
foreach ($form->getElements() as $formElement) {
if ($formElement->getType() == 'fieldset') {
foreach ($formElement->getElements() as $fieldsetElement) {
$fieldsetElement->setDisabled(true);
}
}
}
}
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
示例5: initForm
/**
* Initialize form
*
* @return Mage_Adminhtml_Block_Customer_Edit_Tab_Account
*/
public function initForm()
{
$form = new Varien_Data_Form();
$form->setHtmlIdPrefix('_account');
$form->setFieldNameSuffix('account');
$customer = Mage::registry('current_customer');
/** @var $customerForm Mage_Customer_Model_Form */
$customerForm = Mage::getModel('customer/form');
$customerForm->setEntity($customer)->setFormCode('adminhtml_customer')->initDefaultValues();
$fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('customer')->__('Account Information')));
$attributes = $customerForm->getAttributes();
foreach ($attributes as $attribute) {
/* @var $attribute Mage_Eav_Model_Entity_Attribute */
$attribute->setFrontendLabel(Mage::helper('customer')->__($attribute->getFrontend()->getLabel()));
$attribute->unsIsVisible();
}
$disableAutoGroupChangeAttributeName = 'disable_auto_group_change';
$this->_setFieldset($attributes, $fieldset, array($disableAutoGroupChangeAttributeName));
$form->getElement('group_id')->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_attribute_group')->setDisableAutoGroupChangeAttribute($customerForm->getAttribute($disableAutoGroupChangeAttributeName))->setDisableAutoGroupChangeAttributeValue($customer->getData($disableAutoGroupChangeAttributeName)));
if ($customer->getId()) {
foreach ($form->getElements() as $mfieldset) {
$mfieldset->removeField('amountused');
$mfieldset->removeField('credit_amount');
$mfieldset->removeField('credit_due_date');
$mfieldset->removeField('credit_payment_status');
$mfieldset->removeField('credit_pending_amount');
$mfieldset->removeField('credit_time_period');
$mfieldset->removeField('storecreditactive');
$mfieldset->removeField('zapproverimage');
$mfieldset->removeField('zcorporateapprover');
$mfieldset->removeField('zmyapprover');
$mfieldset->removeField('suffix');
$mfieldset->removeField('taxvat');
$mfieldset->removeField('company');
$mfieldset->removeField('approver');
$mfieldset->removeField('is_verified');
$mfieldset->removeField('order_placed');
//$mfieldset->removeField('std_code');
$mfieldset->removeField('new_telephone');
$mfieldset->removeField('is_approver');
$mfieldset->removeField('zcorporatename');
}
$renderer = $this->getLayout()->createBlock('adminhtml/customer_edit_renderer_telephone');
$form->getElement('std_code')->setRenderer($renderer);
$form->getElement('website_id')->setDisabled('disabled');
$form->getElement('created_in')->setDisabled('disabled');
} else {
$fieldset->removeField('created_in');
$form->getElement('website_id')->addClass('validate-website-has-store');
$websites = array();
foreach (Mage::app()->getWebsites(true) as $website) {
$websites[$website->getId()] = !is_null($website->getDefaultStore());
}
$prefix = $form->getHtmlIdPrefix();
$form->getElement('website_id')->setAfterElementHtml('<script type="text/javascript">' . "\n var {$prefix}_websites = " . Mage::helper('core')->jsonEncode($websites) . ";\n Validation.add(\n 'validate-website-has-store',\n '" . Mage::helper('customer')->__('Please select a website which contains store view') . "',\n function(v, elem){\n return {$prefix}_websites[elem.value] == true;\n }\n );\n Element.observe('{$prefix}website_id', 'change', function(){\n Validation.validate(\$('{$prefix}website_id'))\n }.bind(\$('{$prefix}website_id')));\n " . '</script>');
}
$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$form->getElement('website_id')->setRenderer($renderer);
// if (Mage::app()->isSingleStoreMode()) {
// $fieldset->removeField('website_id');
// $fieldset->addField('website_id', 'hidden', array(
// 'name' => 'website_id'
// ));
// $customer->setWebsiteId(Mage::app()->getStore(true)->getWebsiteId());
// }
$customerStoreId = null;
if ($customer->getId()) {
$customerStoreId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
}
$prefixElement = $form->getElement('prefix');
if ($prefixElement) {
$prefixOptions = $this->helper('customer')->getNamePrefixOptions($customerStoreId);
if (!empty($prefixOptions)) {
$fieldset->removeField($prefixElement->getId());
$prefixField = $fieldset->addField($prefixElement->getId(), 'select', $prefixElement->getData(), $form->getElement('group_id')->getId());
$prefixField->setValues($prefixOptions);
if ($customer->getId()) {
$prefixField->addElementValues($customer->getPrefix());
}
}
}
$suffixElement = $form->getElement('suffix');
if ($suffixElement) {
$suffixOptions = $this->helper('customer')->getNameSuffixOptions($customerStoreId);
if (!empty($suffixOptions)) {
$fieldset->removeField($suffixElement->getId());
$suffixField = $fieldset->addField($suffixElement->getId(), 'select', $suffixElement->getData(), $form->getElement('lastname')->getId());
$suffixField->setValues($suffixOptions);
if ($customer->getId()) {
$suffixField->addElementValues($customer->getSuffix());
}
}
}
if ($customer->getId()) {
if (!$customer->isReadonly()) {
//.........这里部分代码省略.........
示例6: getFormElements
//.........这里部分代码省略.........
$collection->addFieldToFilter('main_table.is_visible_on_front', 1);
} else {
$collection->addFieldToFilter('e.is_visible_on_front', 1);
}
} else {
$collection->addFieldToFilter('is_visible_on_front', 1);
}
if ($this->_isCheckout()) {
// Show on Billing During Checkout
$collection->addFieldToFilter('used_in_product_listing', 1);
}
$collection->addFieldToFilter('entity_type_id', $this->_entityTypeId);
if ('true' == (string) Mage::getConfig()->getNode('modules/Amasty_Orderattr/active')) {
$alias = 'main_table';
if (false !== strpos($collection->getSelect()->__toString(), $alias)) {
$collection->getSelect()->order('main_table.sorting_order');
} else {
$collection->getSelect()->order('e.sorting_order');
}
} else {
$collection->getSelect()->order('sorting_order');
}
$attributes = $collection->load();
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('amcustomerattr', array());
/**
* Loading current customer, it we are on edit page
*/
$customer = Mage::getSingleton('customer/session')->isLoggedIn() ? Mage::getSingleton('customer/session')->getCustomer() : null;
$isAnyAttributeApplies = false;
$customerAttributes = Mage::getSingleton('customer/session')->getAmcustomerattr();
foreach ($attributes as $attribute) {
$currentStore = $customer ? $customer->getStoreId() : Mage::app()->getStore()->getId();
$storeIds = explode(',', $attribute->getData('store_ids'));
$defaultValue = $attribute->getDefaultValue();
if (!in_array($currentStore, $storeIds) && !in_array(0, $storeIds)) {
continue;
}
$isAnyAttributeApplies = true;
if ($inputType = $attribute->getFrontend()->getInputType()) {
if ($attribute->getTypeInternal()) {
$inputType = $attribute->getTypeInternal();
}
$fieldType = $inputType;
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
if (!empty($rendererClass)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $rendererClass);
}
$fieldName = $this->_isCheckout() ? 'billing[amcustomerattr][' . $attribute->getAttributeCode() . ']' : 'amcustomerattr[' . $attribute->getAttributeCode() . ']';
// default_value
$attributeValue = '';
if ($customer) {
$attributeValue = $customer->getData($attribute->getAttributeCode());
} elseif ($attribute->getData('default_value')) {
$attributeValue = $attribute->getData('default_value');
}
// if for example there was page reload with error, we putting attribute back from session
if (isset($customerAttributes[$attribute->getAttributeCode()])) {
$attributeValue = $customerAttributes[$attribute->getAttributeCode()];
}
// applying translations
$translations = $attribute->getStoreLabels();
if (isset($translations[Mage::app()->getStore()->getId()])) {
$attributeLabel = $translations[Mage::app()->getStore()->getId()];
} else {
$attributeLabel = $attribute->getFrontend()->getLabel();
}
$element = $fieldset->addField($attribute->getAttributeCode(), $fieldType, array('name' => $fieldName, 'label' => $attributeLabel, 'class' => $attribute->getFrontend()->getClass(), 'required' => $attribute->getIsRequired(), 'note' => $attribute->getNote(), 'value' => $attributeValue))->setEntityAttribute($attribute);
$element->setAfterElementHtml('<div style="padding: 4px;"></div>');
if ($inputType == 'select' || $inputType == 'selectimg' || $inputType == 'multiselect' || $inputType == 'multiselectimg') {
// getting values translations
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($attribute->getId())->setStoreFilter(Mage::app()->getStore()->getId(), false)->load();
foreach ($valuesCollection as $item) {
$values[$item->getId()] = $item->getValue();
}
// applying translations
$options = $attribute->getSource()->getAllOptions(true, true);
foreach ($options as $i => $option) {
if (isset($values[$option['value']])) {
$options[$i]['label'] = $values[$option['value']];
}
if ($defaultValue == $option['value']) {
$options[$i]['default'] = true;
}
}
$element->setValues($options);
} elseif ($inputType == 'date') {
$element->setImage($this->getSkinUrl('images/grid-cal.gif'));
$element->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
}
}
}
if ($isAnyAttributeApplies) {
$this->_formElements = $form->getElements();
} else {
$this->_formElements = array();
}
return $this->_formElements;
}
示例7: getFormsFields
public function getFormsFields($_index)
{
/* {#AITOC_COMMENT_END#}
$performer = Aitoc_Aitsys_Abstract_Service::get()->platform()->getModule('AdjustWare_Deliverydate')->getLicense()->getPerformer();
$ruler = $performer->getRuler();
$storeId = Mage::getSingleton('adminhtml/sales_order_create')->getSession()->getData('store_id');
if (!($ruler->checkRule('store',$storeId,'store') ))
{
return array();
}
{#AITOC_COMMENT_START#} */
if (!Mage::getStoreConfig('checkout/adjdeliverydate/enabled') || !Mage::getStoreConfig('checkout/adjdeliverydate/multienabled')) {
return array();
}
$hlp = Mage::helper('adjdeliverydate');
$form = new Varien_Data_Form(array('field_name_suffix' => 'adj'));
$layout = Mage::app()->getFrontController()->getAction()->getLayout();
$form->addField('delivery_date' . $_index, 'date', array('name' => 'delivery_date' . $_index, 'label' => $hlp->__('Delivery Date'), 'title' => $hlp->__('Delivery Date'), 'image' => Mage::getDesign()->getSkinUrl('images/grid-cal.gif'), 'input_format' => Varien_Date::DATE_INTERNAL_FORMAT, 'format' => Mage::getStoreConfig('checkout/adjdeliverydate/format'), 'no_span' => 1, 'validator' => 'adjdeliverydate/validator_deliverydate', 'value' => $this->_getCurrentQuoteFieldValue('delivery_date', $_index)))->setRenderer($layout->createBlock('adjdeliverydate/renderer_deliverydate'));
if (Mage::getStoreConfig('checkout/adjdeliverydate/show_time')) {
$form->addField('delivery_time' . $_index, 'time', array('name' => 'delivery_time' . $_index, 'label' => $hlp->__('Delivery Time'), 'title' => $hlp->__('Delivery Time'), 'no_span' => 1, 'value' => $this->_getCurrentQuoteFieldValue('delivery_time', $_index)))->setRenderer($layout->createBlock('adjdeliverydate/renderer_time'));
}
if (Mage::getStoreConfig('checkout/adjdeliverydate/show_comment')) {
$form->addField('delivery_comment' . $_index, 'text', array('name' => 'delivery_comment' . $_index, 'label' => $hlp->__('Comments'), 'title' => $hlp->__('Comments'), 'no_span' => 1, 'class' => 'input-text delivery-comment', 'value' => $this->_getCurrentQuoteFieldValue('delivery_comment', $_index)))->setRenderer($layout->createBlock('adjdeliverydate/renderer_default'));
}
return $form->getElements();
}
示例8: prepareEditForm
/**
* @param Open_Gallery_Model_Item $item
* @param Varien_Data_Form $form
* @return $this|Open_Gallery_Helper_Item_Interface
*/
public function prepareEditForm(Open_Gallery_Model_Item $item, Varien_Data_Form $form)
{
$isReadonlyMode = false;
foreach ($form->getElements() as $element) {
/** @var Varien_Data_Form_Element_Abstract $element */
if ($element instanceof Varien_Data_Form_Element_Fieldset && 'general_information' == $element->getId()) {
$fieldSet = $element;
$fieldSet->addField('additional_type', 'select', array('name' => 'item[additional][type]', 'label' => $this->__('Source Type'), 'title' => $this->__('Source Type'), 'required' => true, 'disabled' => $isReadonlyMode, 'options' => Mage::getModel('open_gallery/config_system_source_type')->toOptionArray()));
$fieldSet->addField('additional_value_file', 'file', array('name' => 'item[additional_value_file]', 'label' => $this->__('Video File'), 'title' => $this->__('Video File'), 'required' => !strlen($item->getData('value')), 'disabled' => $isReadonlyMode, 'container_id' => 'container_value_file', 'note' => $this->__('Allowed format(s): <strong>%s</strong>', implode(', ', $item->getAllowedFormats())) . '<br/>' . $this->__('Your server allow you to upload files not more than <strong>%s</strong>. You can modify <strong>post_max_size</strong> (currently is %s) and <strong>upload_max_filesize</strong> (currently is %s) values in php.ini if you want to upload larger files.', $this->getDataMaxSize(), $this->getPostMaxSize(), $this->getUploadMaxSize())));
$fieldSet->addField('additional_value_youtube', 'text', array('name' => 'item[additional][value_youtube]', 'label' => $this->__('YouTube ID'), 'title' => $this->__('YouTube ID'), 'required' => true, 'disabled' => $isReadonlyMode, 'container_id' => 'container_value_youtube'));
$fieldSet->addField('additional_value_embedded', 'textarea', array('name' => 'item[additional][value_embedded]', 'label' => $this->__('Embed Code'), 'title' => $this->__('Embed Code'), 'required' => true, 'disabled' => $isReadonlyMode, 'container_id' => 'container_value_embedded'));
break;
}
}
return $this;
}
示例9: getFormElements
//.........这里部分代码省略.........
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('amorderattr', array());
foreach ($attributes as $attribute) {
$currentStore = Mage::app()->getStore()->getId();
$storeIds = explode(',', $attribute->getData('store_ids'));
if (!in_array($currentStore, $storeIds) && !in_array(0, $storeIds)) {
continue;
}
if ($inputType = $attribute->getFrontend()->getInputType()) {
$afterElementHtml = '';
$fieldType = $inputType;
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
if (!empty($rendererClass)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $rendererClass);
}
// global name space, will merge from all steps
$fieldName = 'amorderattr[' . $attribute->getAttributeCode() . ']';
// default_value
$attributeValue = '';
if ($attribute->getData('default_value')) {
$attributeValue = $attribute->getData('default_value');
}
// if enabled, we will pre-fill the attribut with the last used value. works for registered customer only
if ($attribute->getSaveSelected() && Mage::getSingleton('customer/session')->isLoggedIn()) {
$orderCollection = Mage::getModel('sales/order')->getCollection();
$orderCollection->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getId());
// 1.3 compatibility
$alias = Mage::helper('ambase')->isVersionLessThan(1, 4) ? 'e' : 'main_table';
$orderCollection->getSelect()->join(array('custom_attributes' => Mage::getModel('amorderattr/attribute')->getResource()->getTable('amorderattr/order_attribute')), "{$alias}.entity_id = custom_attributes.order_id", array($attribute->getAttributeCode()));
$orderCollection->getSelect()->order('custom_attributes.order_id DESC');
$orderCollection->getSelect()->limit(1);
if ($orderCollection->getSize() > 0) {
foreach ($orderCollection as $lastOrder) {
$attributeValue = $lastOrder->getData($attribute->getAttributeCode());
}
}
}
// applying translations
$translations = $attribute->getStoreLabels();
if (isset($translations[Mage::app()->getStore()->getId()])) {
$attributeLabel = $translations[Mage::app()->getStore()->getId()];
} else {
$attributeLabel = $attribute->getFrontend()->getLabel();
}
$element = $fieldset->addField($attribute->getAttributeCode(), $fieldType, array('name' => $fieldName, 'label' => $attributeLabel, 'class' => $attribute->getFrontend()->getClass(), 'required' => $attribute->getIsRequired(), 'note' => $attribute->getNote(), 'value' => $attributeValue))->setEntityAttribute($attribute);
$afterElementHtml .= '<div style="padding: 4px;"></div>';
if ($inputType == 'select' || $inputType == 'multiselect') {
$values = array();
// getting values translations
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($attribute->getId())->setStoreFilter(Mage::app()->getStore()->getId(), false)->load();
foreach ($valuesCollection as $item) {
$values[$item->getId()] = $item->getValue();
}
// applying translations
$options = $attribute->getSource()->getAllOptions(true, true);
foreach ($options as $i => $option) {
if (isset($values[$option['value']])) {
$options[$i]['label'] = $values[$option['value']];
}
}
if ($inputType == 'select' && $attribute->getParentDropdown()) {
$parentAttribute = Mage::getModel('eav/entity_attribute')->load($attribute->getParentDropdown());
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($attribute->getId())->load();
$linkedRelationship = array();
if ($valuesCollection->getSize() > 0) {
foreach ($valuesCollection as $value) {
foreach ($options as $option) {
if ($option['value'] == $value->getOptionId()) {
$linkedRelationship[$option['value']] = $value->getParentOptionId();
}
}
}
$optionsJson = Zend_Json::encode($options);
$relationsJson = Zend_Json::encode($linkedRelationship);
$afterElementHtml .= '<script type="text/javascript">' . 'Event.observe(window, "load", function(){ peditGrid' . $attribute->getId() . ' = new amLinkedFields("' . $parentAttribute->getAttributeCode() . '", "' . $attribute->getAttributeCode() . '", ' . $optionsJson . ', ' . $relationsJson . '); });' . '</script>';
if ($attributeValue) {
// applying saved for future checkout value
$afterElementHtml .= '<script type="text/javascript">' . 'Event.observe(window, "load", function(){
$$("#' . $attribute->getAttributeCode() . ' option[value=' . $attributeValue . ']").each(function(elem){ elem.selected = true; });
});' . '</script>';
}
}
} else {
$element->setValues($options);
}
} elseif ($inputType == 'date' && 'time' != $attribute->getNote()) {
$element->setImage($this->getSkinUrl('images/grid-cal.gif'));
$element->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
} elseif ($inputType == 'date' && 'time' == $attribute->getNote()) {
$element->setImage($this->getSkinUrl('images/grid-cal.gif'));
$element->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT) . ' HH:mm');
$element->setTime(true);
}
$element->setAfterElementHtml($afterElementHtml);
}
}
$this->_formElements = $form->getElements();
return $this->_formElements;
}
示例10: getFormElements
public function getFormElements()
{
if ($this->_formElements) {
return $this->_formElements;
}
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
$customer = $quote->getCustomer();
$customerData = $customer->getData();
$attributes = Mage::getModel('customer/attribute')->getCollection();
$filters = array("is_user_defined = 1", "entity_type_id = " . Mage::getModel('eav/entity')->setType('customer')->getTypeId());
$attributes = Mage::helper('amcustomerattr')->addFilters($attributes, 'eav_attribute', $filters);
$sorting = 'sorting_order';
$filters = array();
$attributes = Mage::helper('amcustomerattr')->addFilters($attributes, 'customer_eav_attribute', $filters, $sorting);
$attributes->load();
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('amcustomerattr', array());
$formData = array();
foreach ($attributes as $attribute) {
$currentStore = Mage::getSingleton('adminhtml/session_quote')->getStore()->getId();
$storeIds = explode(',', $attribute->getData('store_ids'));
if (!in_array($currentStore, $storeIds) && !in_array(0, $storeIds)) {
continue;
}
if ($inputType = $attribute->getFrontend()->getInputType()) {
$fieldType = $inputType;
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
if (!empty($rendererClass)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $rendererClass);
}
// applying translations
$attributeLabel = $attribute->getFrontendLabel();
$elementOptions = array('name' => $attribute->getAttributeCode(), 'label' => $attributeLabel, 'class' => $attribute->getFrontend()->getClass(), 'required' => $attribute->getIsRequired());
if ('checkboxes' == $inputType || 'radios' == $inputType) {
$elementOptions['name'] .= '[]';
$formData[$attribute->getAttributeCode()] = explode(',', $customerData[$attribute->getAttributeCode()]);
$elementOptions['values'] = $attribute->getSource()->getAllOptions(false, true);
} else {
if (isset($customerData[$attribute->getAttributeCode()])) {
$formData[$attribute->getAttributeCode()] = $customerData[$attribute->getAttributeCode()];
}
}
$afterElementHtml = '';
if ('date' == $inputType) {
$dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$elementOptions = array('name' => $attribute->getAttributeCode(), 'label' => $attributeLabel, 'title' => $attributeLabel, 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'class' => $attribute->getFrontend()->getClass(), 'required' => $attribute->getIsRequired(), 'format' => $dateFormatIso, 'readonly' => 1, 'onclick' => 'amcustomerattr_trig(' . $attribute->getAttributeCode() . '_trig)');
if ('time' == $attribute->getNote()) {
$elementOptions['time'] = true;
$elementOptions['format'] .= ' HH:mm';
}
$afterElementHtml .= '<script type="text/javascript">' . 'function amcustomerattr_trig(id)' . '{ $(id).click(); }' . '</script>';
}
$element = $fieldset->addField($attribute->getAttributeCode(), $fieldType, $elementOptions)->setEntityAttribute($attribute);
if ($inputType == 'radios' || $inputType == 'select' || $inputType == 'multiselect' || $inputType == 'boolean') {
// getting values translations
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($attribute->getId())->setStoreFilter($currentStore, false)->load();
foreach ($valuesCollection as $item) {
$values[$item->getId()] = $item->getValue();
}
// applying translations
$options = $attribute->getSource()->getAllOptions(true, true);
foreach ($options as $i => $option) {
if (isset($values[$option['value']])) {
$options[$i]['label'] = $values[$option['value']];
}
}
$element->setAfterElementHtml($afterElementHtml);
$element->setValues($options);
}
}
}
$form->setValues($formData);
$this->_formElements = $form->getElements();
return $this->_formElements;
}
示例11: getFormElements
public function getFormElements()
{
if ($this->_formElements) {
return $this->_formElements;
}
$collection = Mage::getModel('eav/entity_attribute')->getCollection();
$collection->addFieldToFilter('checkout_step', array(2, 3, 4, 5));
$collection->addFieldToFilter('entity_type_id', $this->_entityTypeId);
$collection->getSelect()->order('sorting_order');
$attributes = $collection->load();
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('amorderattr', array());
$attributeValues = null;
/**
* Reorder or order edit process. Should load values from old order.
*/
if (($reorderId = Mage::getSingleton('adminhtml/session_quote')->getOrderId()) || ($reorderId = Mage::getSingleton('adminhtml/session_quote')->getReordered())) {
$attributeValues = Mage::getModel('amorderattr/attribute')->load($reorderId, 'order_id');
}
foreach ($attributes as $attribute) {
$currentStore = Mage::getSingleton('adminhtml/session_quote')->getStore()->getId();
$storeIds = explode(',', $attribute->getData('store_ids'));
if (!in_array($currentStore, $storeIds) && !in_array(0, $storeIds)) {
continue;
}
if ($inputType = $attribute->getFrontend()->getInputType()) {
$fieldType = $inputType;
$rendererClass = $attribute->getFrontend()->getInputRendererClass();
if (!empty($rendererClass)) {
$fieldType = $inputType . '_' . $attribute->getAttributeCode();
$fieldset->addType($fieldType, $rendererClass);
}
// global name space, will merge from all steps
$fieldName = 'amorderattr[' . $attribute->getAttributeCode() . ']';
// default_value
$attributeValue = '';
if ($attribute->getData('default_value')) {
$attributeValue = $attribute->getData('default_value');
}
if ($attributeValues && $attributeValues->hasData($attribute->getAttributeCode())) {
$attributeValue = $attributeValues->getData($attribute->getAttributeCode());
}
// applying translations
$attributeLabel = $attribute->getFrontendLabel();
$element = $fieldset->addField($attribute->getAttributeCode(), $fieldType, array('name' => $fieldName, 'label' => $attributeLabel, 'class' => $attribute->getFrontend()->getClass(), 'required' => $attribute->getIsRequired(), 'note' => $attribute->getNote(), 'value' => $attributeValue))->setEntityAttribute($attribute);
if ($inputType == 'select' || $inputType == 'multiselect') {
// getting values translations
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setAttributeFilter($attribute->getId())->setStoreFilter($currentStore, false)->load();
foreach ($valuesCollection as $item) {
$values[$item->getId()] = $item->getValue();
}
// applying translations
$options = $attribute->getSource()->getAllOptions(true, true);
foreach ($options as $i => $option) {
if (isset($values[$option['value']])) {
$options[$i]['label'] = $values[$option['value']];
}
}
$element->setValues($options);
} elseif ($inputType == 'date') {
$element->setImage($this->getSkinUrl('images/grid-cal.gif'));
$element->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
}
}
}
$this->_formElements = $form->getElements();
return $this->_formElements;
}