toOptionArray(false); if (isset($countries[0]) && !$countries[0]['value']) { $countries[0] = array('value' => '*', 'label' => '*'); } return $countries; } protected function getDestRegionValues() { $regions = array(array('value' => '0', 'label' => '*')); $model = $this->getModel(); $destCountryId = trim($model->getDestCountryId(),','); if ($destCountryId) { $regionCollection = Mage::getModel('directory/region')->getCollection() ->addCountryFilter($destCountryId); $regions = $regionCollection->toOptionArray(); if (isset($regions[0])) $regions[0]['label'] = '*'; } return $regions; } protected function getConditionNameValues() { return Mage::getModel('adminhtml/system_config_source_shipping_tablerate')->toOptionArray(); } protected function getCityValue() { $model = $this->getModel(); $destCity = $model->getDestCity(); return (($destCity == '*') || ($destCity == '')) ? '*' : $destCity; } protected function getDestZipValue() { $model = $this->getModel(); $destZip = $model->getDestZip(); return (($destZip == '*') || ($destZip == '')) ? '*' : $destZip; } protected function getDestZipToValue() { $model = $this->getModel(); $destZipTo = $model->getDestZipTo(); return (($destZipTo == '*') || ($destZipTo == '')) ? '*' : $destZipTo; } protected function getTitleValue() { $model = $this->getModel(); $title = $model->getData('title'); return $title; } protected function _prepareForm() { $helper = $this->_getHelper(); $model = $this->getModel(); $isElementDisabled = false; $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')); $form->setHtmlIdPrefix('pacsoft_rate_'); $fieldset = $form->addFieldset('main_fieldset', array('legend' => $helper->__('Rate Information'))); if ($model->getId()) { $fieldset->addField('pk', 'hidden', array( 'name' => 'pk', 'value' => $model->getId(), )); } $fieldset->addField('website_id', 'hidden', array( 'name' => 'website_id', 'value' => $model->getWebsiteId(), )); $fieldset->addField('dest_country_id', 'multiselect', array( 'name' => 'dest_country_id', 'label' => $helper->__('Country'), 'title' => $helper->__('Country'), 'required' => true, 'value' => $model->getDestCountryId(), 'values' => $this->getDestCountryValues(), 'disabled' => $isElementDisabled, 'note' => Mage::helper('pacsoft')->__('Multiple selection of countries is possible. If a country requires selection of state/region it can not be selected together with other countries.'), )); $fieldset->addField('dest_region_id', 'select', array( 'name' => 'dest_region_id', 'label' => $helper->__('Region/State'), 'title' => $helper->__('Region/State'), 'required' => false, 'value' => $model->getDestRegionId(), 'values' => $this->getDestRegionValues(), 'disabled' => $isElementDisabled, )); $fieldset->addField('dest_city', 'text', array( 'name' => 'dest_city', 'label' => $helper->__('City'), 'title' => $helper->__('City'), 'note' => $helper->__('\'*\' or blank - matches any'), 'required' => false, 'value' => $this->getCityValue(), 'disabled' => $isElementDisabled, )); $fieldset->addField('dest_zip', 'text', array( 'name' => 'dest_zip', 'label' => $helper->__('Zip/Postal Code From'), 'title' => $helper->__('Zip/Postal Code From'), 'note' => $helper->__('\'*\' or blank - matches any'), 'required' => false, 'value' => $this->getDestZipValue(), 'disabled' => $isElementDisabled, )); $fieldset->addField('dest_zip_to', 'text', array( 'name' => 'dest_zip_to', 'label' => $helper->__('Zip/Postal Code To'), 'title' => $helper->__('Zip/Postal Code To'), 'note' => $helper->__('\'*\' or blank - matches any'), 'required' => false, 'value' => $this->getDestZipToValue(), 'disabled' => $isElementDisabled, )); $fieldset->addField('condition_name', 'select', array( 'name' => 'condition_name', 'label' => $helper->__('Condition Name'), 'title' => $helper->__('Condition Name'), 'required' => true, 'value' => $model->getConditionName(), 'values' => $this->getConditionNameValues(), 'disabled' => $isElementDisabled, 'note' => Mage::helper('pacsoft')->__('Choose whether you want to calculate shipping based on weight, price or number of items'), )); $fieldset->addField('condition_from_value', 'text', array( 'name' => 'condition_from_value', 'label' => $helper->__('Condition Value From'), 'title' => $helper->__('Condition Value From'), 'required' => true, 'value' => floatval($model->getConditionFromValue()), 'disabled' => $isElementDisabled, 'note' => Mage::helper('pacsoft')->__('Specify the value in the same unit as selected condition - weight/price/#'), )); $fieldset->addField('condition_to_value', 'text', array( 'name' => 'condition_to_value', 'label' => $helper->__('Condition Value To'), 'title' => $helper->__('Condition Value To'), 'required' => true, 'value' => floatval($model->getConditionToValue()), 'disabled' => $isElementDisabled, 'note' => Mage::helper('pacsoft')->__('Specify the value in the same unit as selected condition - weight/price/#'), )); $fieldset->addField('price', 'text', array( 'name' => 'price', 'label' => $helper->__('Price'), 'title' => $helper->__('Price'), 'required' => true, 'value' => floatval($model->getPrice()), 'disabled' => $isElementDisabled, )); $fieldset->addField('cost', 'text', array( 'name' => 'cost', 'label' => $helper->__('Cost'), 'title' => $helper->__('Cost'), 'required' => true, 'value' => floatval($model->getCost()), 'disabled' => $isElementDisabled, )); $fieldset->addField('service', 'select', array( 'name' => 'service', 'label' => $helper->__('Service'), 'title' => $helper->__('Service'), 'required' => false, 'value' => $model->getService(), 'options' => Mage::helper('pacsoft/rates')->getServiceOptions(), 'disabled' => $isElementDisabled, )); $fieldset->addField('addons', 'multiselect', array( 'name' => 'addons', 'label' => $helper->__('Add-ons'), 'title' => $helper->__('Add-ons'), 'required' => false, 'value' => $model->getAddons(), 'values' => Mage::helper('pacsoft/rates')->getPosibleAddons(), 'disabled' => $isElementDisabled, )); $fieldset->addField('title', 'text', array( 'name' => 'title', 'label' => $helper->__('Title'), 'title' => $helper->__('Title'), 'required' => false, 'value' => $this->getTitleValue(), 'disabled' => $isElementDisabled, 'note' => Mage::helper('pacsoft')->__('Name of the shipping rate (shown in frontend)'), )); $fieldset->addField('sort_order', 'text', array( 'name' => 'sort_order', 'label' => $helper->__('Sort order'), 'title' => $helper->__('Sort order'), 'required' => false, 'value' => $model->getSortOrder(), 'disabled' => $isElementDisabled, 'note' => Mage::helper('pacsoft')->__('Using the sort order you can decide in which order the shipping rates are displayed in the frontend'), )); $fieldset->addField('external_id', 'text', array( 'name' => 'external_id', 'label' => $helper->__('External ID'), 'title' => $helper->__('External ID'), 'required' => false, 'value' => $model->getExternalId(), 'disabled' => $isElementDisabled, 'note' => Mage::helper('pacsoft')->__('Can be uses like "Consignor ID"'), )); Mage::dispatchEvent('pacsoft_adminhtml_rate_edit_prepare_form', array('form' => $form)); $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); } }