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
00028 abstract class Mage_Shipping_Model_Carrier_Abstract extends Varien_Object
00029 {
00030 protected $_code;
00031 protected $_rates = null;
00032 protected $_numBoxes = 1;
00033
00034 const HANDLING_TYPE_PERCENT = 'P';
00035 const HANDLING_TYPE_FIXED = 'F';
00036
00037 const HANDLING_ACTION_PERPACKAGE = 'P';
00038 const HANDLING_ACTION_PERORDER = 'O';
00039
00040 public function __construct()
00041 {
00042
00043 }
00044
00045
00046
00047
00048
00049
00050
00051 public function getConfigData($field)
00052 {
00053 if (empty($this->_code)) {
00054 return false;
00055 }
00056 $path = 'carriers/'.$this->_code.'/'.$field;
00057 return Mage::getStoreConfig($path, $this->getStore());
00058 }
00059
00060 public function getConfigFlag($field)
00061 {
00062 if (empty($this->_code)) {
00063 return false;
00064 }
00065 $path = 'carriers/'.$this->_code.'/'.$field;
00066 return Mage::getStoreConfigFlag($path, $this->getStore());
00067 }
00068
00069 abstract public function collectRates(Mage_Shipping_Model_Rate_Request $request);
00070
00071 public function checkAvailableShipCountries(Mage_Shipping_Model_Rate_Request $request)
00072 {
00073 $speCountriesAllow = $this->getConfigData('sallowspecific');
00074
00075
00076
00077 if($speCountriesAllow && $speCountriesAllow==1){
00078 $showMethod = $this->getConfigData('showmethod');
00079 $availableCountries = array();
00080 if( $this->getConfigData('specificcountry') ) {
00081 $availableCountries = explode(',',$this->getConfigData('specificcountry'));
00082 }
00083 if ($availableCountries && in_array($request->getDestCountryId(), $availableCountries)) {
00084 return $this;
00085 } elseif ($showMethod && (!$availableCountries || ($availableCountries && !in_array($request->getDestCountryId(), $availableCountries)))){
00086 $error = Mage::getModel('shipping/rate_result_error');
00087 $error->setCarrier($this->_code);
00088 $error->setCarrierTitle($this->getConfigData('title'));
00089 $errorMsg = $this->getConfigData('specificerrmsg');
00090 $error->setErrorMessage($errorMsg?$errorMsg:Mage::helper('shipping')->__('The shipping module is not available for selected delivery country'));
00091 return $error;
00092 } else {
00093
00094
00095
00096 return false;
00097 }
00098 }
00099 return $this;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109 public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
00110 {
00111 return $this;
00112 }
00113
00114 public function isActive()
00115 {
00116 $active = $this->getConfigData('active');
00117 return $active==1 || $active=='true';
00118 }
00119
00120
00121
00122
00123
00124
00125 public function isTrackingAvailable()
00126 {
00127 return false;
00128 }
00129
00130 public function getSortOrder()
00131 {
00132 return $this->getConfigData('sort_order');
00133 }
00134
00135 protected function _updateFreeMethodQuote($request)
00136 {
00137 if ($request->getFreeMethodWeight()==$request->getPackageWeight()
00138 || !$request->hasFreeMethodWeight()) {
00139 return;
00140 }
00141
00142 if (!$freeMethod = $this->getConfigData('free_method')) {
00143 return;
00144 }
00145 $freeRateId = false;
00146
00147 if (is_object($this->_result)) {
00148 foreach ($this->_result->getAllRates() as $i=>$item) {
00149 if ($item->getMethod()==$freeMethod) {
00150 $freeRateId = $i;
00151 break;
00152 }
00153 }
00154 }
00155
00156 if ($freeRateId===false) {
00157 return;
00158 }
00159 $price = null;
00160 if ($request->getFreeMethodWeight()>0) {
00161 $this->_setFreeMethodRequest($freeMethod);
00162
00163 $result = $this->_getQuotes();
00164 if ($result && ($rates = $result->getAllRates()) && count($rates)>0) {
00165 if ((count($rates) == 1) && ($rates[0] instanceof Mage_Shipping_Model_Rate_Result_Method)) {
00166 $price = $rates[0]->getPrice();
00167 }
00168 if (count($rates) > 1) {
00169 foreach ($rates as $rate) {
00170 if ($rate instanceof Mage_Shipping_Model_Rate_Result_Method && $rate->getMethod() == $freeMethod) {
00171 $price = $rate->getPrice();
00172 }
00173 }
00174 }
00175 }
00176 } else {
00177
00178
00179
00180
00181 $price = 0;
00182 }
00183
00184
00185
00186
00187 if (!is_null($price)) {
00188 $this->_result->getRateById($freeRateId)->setPrice($price);
00189 }
00190 }
00191
00192 public function getMethodPrice($cost, $method='')
00193 {
00194 if ($method == $this->getConfigData('free_method') &&
00195 $this->getConfigData('free_shipping_enable') &&
00196 $this->getConfigData('free_shipping_subtotal') <= $this->_rawRequest->getValueWithDiscount())
00197 {
00198 $price = '0.00';
00199 } else {
00200 $price = $this->getFinalPriceWithHandlingFee($cost);
00201 }
00202 return $price;
00203 }
00204
00205
00206
00207
00208
00209
00210 public function getFinalPriceWithHandlingFee($cost)
00211 {
00212 $handlingFee = $this->getConfigData('handling_fee');
00213 $finalMethodPrice = 0;
00214 $handlingType = $this->getConfigData('handling_type');
00215 if (!$handlingType) {
00216 $handlingType = self::HANDLING_TYPE_FIXED;
00217 }
00218 $handlingAction = $this->getConfigData('handling_action');
00219 if (!$handlingAction) {
00220 $handlingAction = self::HANDLING_ACTION_PERORDER;
00221 }
00222
00223 if($handlingAction == self::HANDLING_ACTION_PERPACKAGE)
00224 {
00225 if ($handlingType == self::HANDLING_TYPE_PERCENT) {
00226 $finalMethodPrice = ($cost + ($cost * $handlingFee/100)) * $this->_numBoxes;
00227 } else {
00228 $finalMethodPrice = ($cost + $handlingFee) * $this->_numBoxes;
00229 }
00230 } else {
00231 if ($handlingType == self::HANDLING_TYPE_PERCENT) {
00232 $finalMethodPrice = ($cost * $this->_numBoxes) + ($cost * $this->_numBoxes * $handlingFee/100);
00233 } else {
00234 $finalMethodPrice = ($cost * $this->_numBoxes) + $handlingFee;
00235 }
00236
00237 }
00238 return $finalMethodPrice;
00239 }
00240
00241
00242
00243
00244
00245
00246
00247 public function convertWeightToLbs($weight)
00248 {
00249 return $weight;
00250 }
00251
00252
00253
00254
00255
00256
00257 public function getTotalNumOfBoxes($weight)
00258 {
00259
00260
00261
00262 $this->_numBoxes = 1;
00263 $weight = $this->convertWeightToLbs($weight);
00264 $maxPackageWeight = $this->getConfigData('max_package_weight');
00265 if($weight > $maxPackageWeight && $maxPackageWeight != 0) {
00266 $this->_numBoxes = ceil($weight/$maxPackageWeight);
00267 $weight = $weight/$this->_numBoxes;
00268 }
00269 return $weight;
00270 }
00271
00272 public function isStateProvinceRequired()
00273 {
00274 return false;
00275 }
00276
00277 public function isCityRequired()
00278 {
00279 return false;
00280 }
00281
00282 public function isZipCodeRequired()
00283 {
00284 return false;
00285 }
00286 }