Ejemplo n.º 1
0
 public function getFieldHtml($NewFieldData, $section)
 {
     if (!Mage::helper('fieldsmanager')->getStoredDatafor('enable')) {
         return false;
     }
     $BackEndValue = '';
     $StoreId = Mage::app()->getStore()->getId();
     $NewFieldId = 'fm_' . $NewFieldData['attribute_code'];
     $TextFields = new Zend_View();
     $Label = $this->getFieldLabel($NewFieldData['attribute_id']);
     $class = ' t1 ' . $NewFieldData['frontend_class'];
     $NewFieldName = $section . '[fm_' . $NewFieldData['attribute_code'] . ']';
     if (Mage::getSingleton('core/session')->getParentOrderId() && Mage::getSingleton('core/session')->getParentOrderId() != 0) {
         $BackEndValue = $this->getSavedFieldData(Mage::getSingleton('core/session')->getParentOrderId(), $NewFieldData['attribute_code'], 'orders');
     } elseif ($NewFieldData['fme_customer_account'] > 0 && $this->getCustomer()) {
         $customerId = 0;
         if ($this->getCustomer()) {
             $customerId = $this->getCustomer()->getId();
         }
         $BackEndValue = $this->getSavedFieldData($customerId, $NewFieldData['attribute_code'], 'customers');
     }
     $BackEndValue = $BackEndValue != '' ? $BackEndValue : $NewFieldData['default_value'];
     if ($NewFieldData['is_required']) {
         if (in_array($NewFieldData['frontend_input'], array('text', 'textarea', 'date'))) {
             $class .= ' required-entry';
         } elseif (in_array($NewFieldData['frontend_input'], array('select', 'multiselect', 'boolean'))) {
             $class .= ' validate-select';
         } else {
             $class .= ' validate-one-required-by-name';
         }
     }
     $TextInputExtra = array('id' => $NewFieldId, 'class' => $class, 'title' => $Label);
     $OptionsList = array();
     $html = '';
     switch ($NewFieldData['frontend_input']) {
         case 'text':
             $TextInputExtra['class'] .= ' t1 input-text';
             $html .= $TextFields->formText($NewFieldName, $BackEndValue, $TextInputExtra);
             break;
         case 'textarea':
             $TextInputExtra['class'] .= ' t1 input-text';
             $TextInputExtra['style'] = 'height:50px;';
             $html .= $TextFields->formTextarea($NewFieldName, $BackEndValue, $TextInputExtra);
             break;
         case 'select':
             $OptionsList1 = array();
             if ($NewFieldData['is_used_for_price_rules'] == 1) {
                 $OptionsList1[-1] = array('value' => '', 'label' => ' ');
             }
             $OptionsList = $this->getOptionslist($NewFieldData['attribute_id']);
             $OptionsList = array_merge($OptionsList1, $OptionsList);
             $select = Mage::getModel('core/layout')->createBlock('adminhtml/html_select')->setData(array('id' => $NewFieldId, 'class' => $class, 'value' => $BackEndValue))->setName($NewFieldName)->setOptions($OptionsList);
             $html .= $select->getHtml();
             break;
         case 'multiselect':
             if (!is_array($BackEndValue)) {
                 $BackEndValue = explode(',', $BackEndValue);
             }
             $OptionsList = $this->getOptionslist($NewFieldData['attribute_id']);
             $select = Mage::getModel('core/layout')->createBlock('adminhtml/html_select')->setData(array('id' => $NewFieldId, 'class' => $class, 'value' => $BackEndValue))->setExtraParams('multiple')->setName($NewFieldName . '[]')->setOptions($OptionsList);
             $html .= $select->getHtml();
             break;
         case 'checkbox':
             $OptionsList = $this->getOptionslist($NewFieldData['attribute_id']);
             if ($OptionsList) {
                 $newOPtions = array();
                 foreach ($OptionsList as $option) {
                     $newOPtions[$option['value']] = $option['label'];
                 }
                 $class .= ' checkbox';
                 if (!is_array($BackEndValue)) {
                     $BackEndValue = explode(',', $BackEndValue);
                 }
                 $attribs = array('id' => $NewFieldId, 'class' => $class, 'title' => $Label);
                 $html .= $TextFields->formMultiCheckbox($NewFieldName, $BackEndValue, $attribs, $newOPtions, "<br />\n");
             }
             break;
         case 'radio':
             $OptionsList = $this->getOptionslist($NewFieldData['attribute_id']);
             if ($OptionsList) {
                 $OptionsList1 = array();
                 if (!$NewFieldData['is_required']) {
                     $OptionsList1[-1] = array('value' => '', 'label' => Mage::helper('catalog')->__('None'));
                 }
                 $OptionsList = array_merge($OptionsList1, $OptionsList);
                 $newOPtions = array();
                 foreach ($OptionsList as $option) {
                     $newOPtions[$option['value']] = $option['label'];
                 }
                 $class .= ' radio';
                 if (!is_array($BackEndValue)) {
                     $BackEndValue = explode(',', $BackEndValue);
                 }
                 $attribs = array('id' => $NewFieldId, 'class' => $class, 'title' => $Label);
                 $html .= $TextFields->formRadio($NewFieldName, $BackEndValue, $attribs, $newOPtions);
             }
             break;
         case 'boolean':
             if ($BackEndValue == 'No') {
                 $BackEndValue = '0';
             } elseif ($BackEndValue == 'Yes') {
                 $BackEndValue = '1';
             }
             if (!is_array($BackEndValue)) {
                 $BackEndValue = explode(',', $BackEndValue);
             }
             $bool = array(array('value' => 0, 'label' => Mage::helper('catalog')->__('No')), array('value' => 1, 'label' => Mage::helper('catalog')->__('Yes')));
             $bool_html = Mage::getModel('core/layout')->createBlock('adminhtml/html_select')->setData(array('id' => $NewFieldId, 'class' => $class, 'value' => $BackEndValue))->setName($NewFieldName)->setOptions($bool);
             $html .= $bool_html->getHtml();
             break;
         case 'date':
             $html .= $this->getjquerydate($NewFieldName, $NewFieldId, $BackEndValue, $class);
             //                $dateFormat = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
             //		 $date = Mage::getModel('core/layout')->createBlock('adminhtml/html_date')
             //		->setData(array(
             //		    'id'    => $NewFieldId,
             //		    'class' => $class,
             //		    'title'=>$NewFieldName,
             //		    'format'=>$dateFormat,
             //		    'image'=>Mage::getDesign()->getSkinUrl('images/grid-cal.gif')
             //		))
             //		->setValue($BackEndValue, $dateFormat)
             //		->setName($NewFieldName);
             //                $html .= $date->getHtml();
             break;
         case 'message':
             $html .= '<label>' . $BackEndValue . '</label>';
             break;
     }
     return $html;
 }