00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Checkout 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 00028 class Mage_Checkout_Block_Cart_Shipping extends Mage_Checkout_Block_Cart_Abstract 00029 { 00030 protected $_carriers = null; 00031 protected $_rates = array(); 00032 protected $_address = array(); 00033 00034 public function getEstimateRates() 00035 { 00036 if (empty($this->_rates)) { 00037 $groups = $this->getAddress()->getGroupedAllShippingRates(); 00038 $this->_rates = $groups; 00039 } 00040 return $this->_rates; 00041 } 00042 00043 /** 00044 * Get address model 00045 * 00046 * @return Mage_Sales_Model_Quote_Address 00047 */ 00048 public function getAddress() 00049 { 00050 if (empty($this->_address)) { 00051 $this->_address = $this->getQuote()->getShippingAddress(); 00052 } 00053 return $this->_address; 00054 } 00055 00056 public function getCarrierName($carrierCode) 00057 { 00058 if ($name = Mage::getStoreConfig('carriers/'.$carrierCode.'/title')) { 00059 return $name; 00060 } 00061 return $carrierCode; 00062 } 00063 00064 public function getAddressShippingMethod() 00065 { 00066 return $this->getAddress()->getShippingMethod(); 00067 } 00068 00069 public function getEstimateCountryId() 00070 { 00071 return $this->getAddress()->getCountryId(); 00072 } 00073 00074 public function getEstimatePostcode() 00075 { 00076 return $this->getAddress()->getPostcode(); 00077 } 00078 00079 public function getEstimateCity() 00080 { 00081 return $this->getAddress()->getCity(); 00082 } 00083 00084 public function getEstimateRegionId() 00085 { 00086 return $this->getAddress()->getRegionId(); 00087 } 00088 00089 public function getEstimateRegion() 00090 { 00091 return $this->getAddress()->getRegion(); 00092 } 00093 00094 public function getCityActive() 00095 { 00096 return (bool)Mage::getStoreConfig('carriers/dhl/active'); 00097 } 00098 00099 public function getStateActive() 00100 { 00101 return (bool)Mage::getStoreConfig('carriers/dhl/active') || (bool)Mage::getStoreConfig('carriers/tablerate/active'); 00102 } 00103 00104 public function formatPrice($price) 00105 { 00106 return $this->getQuote()->getStore()->convertPrice($price, true); 00107 } 00108 00109 public function getShippingPrice($price, $flag) 00110 { 00111 return $this->formatPrice($this->helper('tax')->getShippingPrice($price, $flag, $this->getAddress())); 00112 } 00113 00114 /** 00115 * Obtain available carriers instances 00116 * 00117 * @return array 00118 */ 00119 public function getCarriers() 00120 { 00121 if (null === $this->_carriers) { 00122 $this->_carriers = array(); 00123 $this->getEstimateRates(); 00124 foreach ($this->_rates as $rateGroup) { 00125 if (!empty($rateGroup)) { 00126 foreach ($rateGroup as $rate) { 00127 $this->_carriers[] = $rate->getCarrierInstance(); 00128 } 00129 } 00130 } 00131 } 00132 return $this->_carriers; 00133 } 00134 00135 /** 00136 * Check if one of carriers require state/province 00137 * 00138 * @return bool 00139 */ 00140 public function isStateProvinceRequired() 00141 { 00142 foreach ($this->getCarriers() as $carrier) { 00143 if ($carrier->isStateProvinceRequired()) { 00144 return true; 00145 } 00146 } 00147 return false; 00148 } 00149 00150 /** 00151 * Check if one of carriers require city 00152 * 00153 * @return bool 00154 */ 00155 public function isCityRequired() 00156 { 00157 foreach ($this->getCarriers() as $carrier) { 00158 if ($carrier->isCityRequired()) { 00159 return true; 00160 } 00161 } 00162 return false; 00163 } 00164 00165 /** 00166 * Check if one of carriers require zip code 00167 * 00168 * @return bool 00169 */ 00170 public function isZipCodeRequired() 00171 { 00172 foreach ($this->getCarriers() as $carrier) { 00173 if ($carrier->isZipCodeRequired()) { 00174 return true; 00175 } 00176 } 00177 return false; 00178 } 00179 }