00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class Mage_AmazonPayments_Block_Adminhtml_Shipping_Methods
00028 extends Mage_Adminhtml_Block_System_Config_Form_Field
00029 {
00030
00031 protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
00032 {
00033 $this->setElement($element);
00034
00035 $html = '<select name="'.$this->getElement()->getName().'[method]" '.$this->_getDisabled().'>';
00036 $html .= '<option value="None">'.$this->__(' Select shipping method').'</option>';
00037 foreach ($this->getShippingMethods() as $carrierCode=>$carrier) {
00038 $html .= '<optgroup label="'.$carrier['title'].'" style="border-top:solid 1px black; margin-top:3px;">';
00039 foreach ($carrier['methods'] as $methodCode=>$method) {
00040 $code = $carrierCode.'/'.$methodCode;
00041 $html .= '<option value="'.$code.'" '.$this->_getSelected($code).' style="background:white;">'.$method['title'].'</option>';
00042 }
00043 $html .= '</optgroup>';
00044 }
00045 $html .= '</select>';
00046
00047 return $html;
00048 }
00049
00050 protected function getShippingMethods()
00051 {
00052 if (!$this->hasData('shipping_methods')) {
00053 $website = $this->getRequest()->getParam('website');
00054 $store = $this->getRequest()->getParam('store');
00055
00056 $storeId = null;
00057 if (!is_null($website)) {
00058 $storeId = Mage::getModel('core/website')->load($website, 'code')->getDefaultGroup()->getDefaultStoreId();
00059 } elseif (!is_null($store)) {
00060 $storeId = Mage::getModel('core/store')->load($store, 'code')->getId();
00061 }
00062
00063 $methods = array();
00064 $carriers = Mage::getSingleton('shipping/config')->getActiveCarriers($storeId);
00065 foreach ($carriers as $carrierCode=>$carrierModel) {
00066 if (!$carrierModel->isActive()) {
00067 continue;
00068 }
00069 $carrierMethods = $carrierModel->getAllowedMethods();
00070 if (!$carrierMethods) {
00071 continue;
00072 }
00073 $carrierTitle = Mage::getStoreConfig('carriers/'.$carrierCode.'/title', $storeId);
00074 $methods[$carrierCode] = array(
00075 'title' => $carrierTitle,
00076 'methods' => array(),
00077 );
00078 foreach ($carrierMethods as $methodCode=>$methodTitle) {
00079 $methods[$carrierCode]['methods'][$methodCode] = array(
00080 'title' => '['.$carrierCode.'] '.$methodTitle,
00081 );
00082 }
00083 }
00084 $this->setData('shipping_methods', $methods);
00085 }
00086 return $this->getData('shipping_methods');
00087 }
00088
00089 protected function _getDisabled()
00090 {
00091 return $this->getElement()->getDisabled() ? ' disabled' : '';
00092 }
00093
00094 protected function _getValue($key)
00095 {
00096 return $this->getElement()->getData('value/'.$key);
00097 }
00098
00099 protected function _getSelected($value)
00100 {
00101 return $this->getElement()->getData('value/method') == $value ? 'selected="selected"' : '';
00102 }
00103 }