*/ /** * Magento Webshopapps Module * * @category Webshopapps * @package Webshopapps Wsacommon * @copyright Copyright (c) 2011 Zowta Ltd (http://www.webshopapps.com) * @license www.webshopapps.com/license/license.txt * @author Karen Baker */ abstract class Webshopapps_Wsacommon_Model_Shipping_Carrier_Baseabstract extends Mage_Shipping_Model_Carrier_Abstract { protected $_debug; protected $_request = null; protected $_result = null; protected $_rawRequest = null; protected $_modName = 'none'; protected $_code; protected static $_quotesCache = array(); const XML_PATH_STORE_ADDRESS1 = 'shipping/origin/street_line1'; const XML_PATH_STORE_ADDRESS2 = 'shipping/origin/street_line2'; const XML_PATH_STORE_CITY = 'shipping/origin/city'; const XML_PATH_STORE_REGION_ID = 'shipping/origin/region_id'; const XML_PATH_STORE_ZIP = 'shipping/origin/postcode'; const XML_PATH_STORE_COUNTRY_ID = 'shipping/origin/country_id'; abstract protected function _getQuotes(); abstract public function getCode($type, $code=''); public function getTrackingInfo($tracking) { $info = array(); $result = $this->getTracking($tracking); if($result instanceof Mage_Shipping_Model_Tracking_Result){ if ($trackings = $result->getAllTrackings()) { return $trackings[0]; } } elseif (is_string($result) && !empty($result)) { return $result; } else { $info['title'] = $this->getConfigData('title'); $info['number'] = $tracking; return $info; } return false; } /** * Check if carrier has shipping tracking option available * All Mage_Usa carriers have shipping tracking option available * * @return boolean */ public function isTrackingAvailable() { return true; } public function getResult() { return $this->_result; } /** * Enter description here... * * @param Mage_Shipping_Model_Rate_Request $data * @return Mage_Shipping_Model_Rate_Result */ public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } if ($this->_modName == 'none') { $this->_debug = $this->getConfigData('debug'); } else { $this->_debug = Mage::helper('wsalogger')->isDebug($this->_modName); } $this->setRequest($request); $this->_result = $this->_getQuotes(); $this->_updateFreeMethodQuote($request); return $this->getResult(); } protected function _setFreeMethodRequest($freeMethod) { $this->_rawRequest->setIgnoreFreeItems(true); } public function getAllowedMethods() { return array($this->_code=>$this->getConfigData('name')); } /** * Returns cache key for some request to carrier quotes service * * @param string|array $requestParams * @return string */ protected function _getQuotesCacheKey($requestParams) { if (is_array($requestParams)) { $requestParams = implode(',', array_merge( array($this->getCarrierCode()), array_keys($requestParams), $requestParams) ); } return crc32($requestParams); } /** * Checks whether some request to rates have already been done, so we have cache for it * Used to reduce number of same requests done to carrier service during one session * * Returns cached response or null * * @param string|array $requestParams * @return null|string */ protected function _getCachedQuotes($requestParams) { $key = $this->_getQuotesCacheKey($requestParams); return isset(self::$_quotesCache[$key]) ? self::$_quotesCache[$key] : null; } /** * Sets received carrier quotes to cache * * @param string|array $requestParams * @param string $response * @return Mage_Usa_Model_Shipping_Carrier_Abstract */ protected function _setCachedQuotes($requestParams, $response) { $key = $this->_getQuotesCacheKey($requestParams); self::$_quotesCache[$key] = $response; return $this; } }