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_Usa 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 * Abstract USA shipping carrier model 00029 * 00030 * @author Magento Core Team <core@magentocommerce.com> 00031 */ 00032 abstract class Mage_Usa_Model_Shipping_Carrier_Abstract extends Mage_Shipping_Model_Carrier_Abstract 00033 { 00034 00035 const USA_COUNTRY_ID = 'US'; 00036 const PUERTORICO_COUNTRY_ID = 'PR'; 00037 00038 public function getTrackingInfo($tracking) 00039 { 00040 $info = array(); 00041 00042 $result = $this->getTracking($tracking); 00043 00044 if($result instanceof Mage_Shipping_Model_Tracking_Result){ 00045 if ($trackings = $result->getAllTrackings()) { 00046 return $trackings[0]; 00047 } 00048 } 00049 elseif (is_string($result) && !empty($result)) { 00050 return $result; 00051 } 00052 00053 return false; 00054 } 00055 00056 /** 00057 * Check if carrier has shipping tracking option available 00058 * All Mage_Usa carriers have shipping tracking option available 00059 * 00060 * @return boolean 00061 */ 00062 public function isTrackingAvailable() 00063 { 00064 return true; 00065 } 00066 00067 public function isCityRequired() 00068 { 00069 return true; 00070 } 00071 00072 public function isZipCodeRequired() 00073 { 00074 return true; 00075 } 00076 00077 /** 00078 * Processing additional validation to check is carrier applicable. 00079 * 00080 * @param Mage_Shipping_Model_Rate_Request $request 00081 * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean 00082 */ 00083 public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request) 00084 { 00085 $maxAllowedWeight = (float) $this->getConfigData('max_package_weight'); 00086 $error = null; 00087 $showMethod = $this->getConfigData('showmethod'); 00088 foreach ($request->getAllItems() as $item) { 00089 if ($item->getProduct() && $item->getProduct()->getId()) { 00090 if ($item->getProduct()->getWeight() > $maxAllowedWeight) { 00091 $error = Mage::getModel('shipping/rate_result_error'); 00092 $error->setCarrier($this->_code) 00093 ->setCarrierTitle($this->getConfigData('title')); 00094 $errorMsg = $this->getConfigData('specificerrmsg'); 00095 $error->setErrorMessage($errorMsg?$errorMsg:Mage::helper('shipping')->__('The shipping module is not available.')); 00096 break; 00097 } 00098 } 00099 } 00100 if (null !== $error && $showMethod) { 00101 return $error; 00102 } elseif (null !== $error) { 00103 return false; 00104 } 00105 return $this; 00106 } 00107 }