Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Shipping_Block_Tracking_Ajax
  • Mage_Shipping_Block_Tracking_Popup
  • Mage_Shipping_Exception
  • Mage_Shipping_Helper_Data
  • Mage_Shipping_Model_Carrier_Abstract
  • Mage_Shipping_Model_Carrier_Flatrate
  • Mage_Shipping_Model_Carrier_Freeshipping
  • Mage_Shipping_Model_Carrier_Pickup
  • Mage_Shipping_Model_Carrier_Tablerate
  • Mage_Shipping_Model_Config
  • Mage_Shipping_Model_Info
  • Mage_Shipping_Model_Mysql4_Carrier_Tablerate
  • Mage_Shipping_Model_Mysql4_Carrier_Tablerate_Collection
  • Mage_Shipping_Model_Rate_Abstract
  • Mage_Shipping_Model_Rate_Request
  • Mage_Shipping_Model_Rate_Result
  • Mage_Shipping_Model_Rate_Result_Abstract
  • Mage_Shipping_Model_Rate_Result_Error
  • Mage_Shipping_Model_Rate_Result_Method
  • Mage_Shipping_Model_Resource_Carrier_Tablerate
  • Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
  • Mage_Shipping_Model_Shipment_Request
  • Mage_Shipping_Model_Shipment_Return
  • Mage_Shipping_Model_Shipping
  • Mage_Shipping_Model_Source_HandlingAction
  • Mage_Shipping_Model_Source_HandlingType
  • Mage_Shipping_Model_Tracking_Result
  • Mage_Shipping_Model_Tracking_Result_Abstract
  • Mage_Shipping_Model_Tracking_Result_Error
  • Mage_Shipping_Model_Tracking_Result_Status

Interfaces

  • Mage_Shipping_Model_Carrier_Interface
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Shipping
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: class Mage_Shipping_Model_Carrier_Tablerate
 29:     extends Mage_Shipping_Model_Carrier_Abstract
 30:     implements Mage_Shipping_Model_Carrier_Interface
 31: {
 32: 
 33:     protected $_code = 'tablerate';
 34:     protected $_isFixed = true;
 35:     protected $_default_condition_name = 'package_weight';
 36: 
 37:     protected $_conditionNames = array();
 38: 
 39:     public function __construct()
 40:     {
 41:         parent::__construct();
 42:         foreach ($this->getCode('condition_name') as $k=>$v) {
 43:             $this->_conditionNames[] = $k;
 44:         }
 45:     }
 46: 
 47:     /**
 48:      * Enter description here...
 49:      *
 50:      * @param Mage_Shipping_Model_Rate_Request $data
 51:      * @return Mage_Shipping_Model_Rate_Result
 52:      */
 53:     public function collectRates(Mage_Shipping_Model_Rate_Request $request)
 54:     {
 55:         if (!$this->getConfigFlag('active')) {
 56:             return false;
 57:         }
 58: 
 59:         // exclude Virtual products price from Package value if pre-configured
 60:         if (!$this->getConfigFlag('include_virtual_price') && $request->getAllItems()) {
 61:             foreach ($request->getAllItems() as $item) {
 62:                 if ($item->getParentItem()) {
 63:                     continue;
 64:                 }
 65:                 if ($item->getHasChildren() && $item->isShipSeparately()) {
 66:                     foreach ($item->getChildren() as $child) {
 67:                         if ($child->getProduct()->isVirtual()) {
 68:                             $request->setPackageValue($request->getPackageValue() - $child->getBaseRowTotal());
 69:                         }
 70:                     }
 71:                 } elseif ($item->getProduct()->isVirtual()) {
 72:                     $request->setPackageValue($request->getPackageValue() - $item->getBaseRowTotal());
 73:                 }
 74:             }
 75:         }
 76: 
 77:         // Free shipping by qty
 78:         $freeQty = 0;
 79:         if ($request->getAllItems()) {
 80:             foreach ($request->getAllItems() as $item) {
 81:                 if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
 82:                     continue;
 83:                 }
 84: 
 85:                 if ($item->getHasChildren() && $item->isShipSeparately()) {
 86:                     foreach ($item->getChildren() as $child) {
 87:                         if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
 88:                             $freeQty += $item->getQty() * ($child->getQty() - (is_numeric($child->getFreeShipping()) ? $child->getFreeShipping() : 0));
 89:                         }
 90:                     }
 91:                 } elseif ($item->getFreeShipping()) {
 92:                     $freeQty += ($item->getQty() - (is_numeric($item->getFreeShipping()) ? $item->getFreeShipping() : 0));
 93:                 }
 94:             }
 95:         }
 96: 
 97:         if (!$request->getConditionName()) {
 98:             $request->setConditionName($this->getConfigData('condition_name') ? $this->getConfigData('condition_name') : $this->_default_condition_name);
 99:         }
100: 
101:          // Package weight and qty free shipping
102:         $oldWeight = $request->getPackageWeight();
103:         $oldQty = $request->getPackageQty();
104: 
105:         $request->setPackageWeight($request->getFreeMethodWeight());
106:         $request->setPackageQty($oldQty - $freeQty);
107: 
108:         $result = Mage::getModel('shipping/rate_result');
109:         $rate = $this->getRate($request);
110: 
111:         $request->setPackageWeight($oldWeight);
112:         $request->setPackageQty($oldQty);
113: 
114:         if (!empty($rate) && $rate['price'] >= 0) {
115:             $method = Mage::getModel('shipping/rate_result_method');
116: 
117:             $method->setCarrier('tablerate');
118:             $method->setCarrierTitle($this->getConfigData('title'));
119: 
120:             $method->setMethod('bestway');
121:             $method->setMethodTitle($this->getConfigData('name'));
122: 
123:             if ($request->getFreeShipping() === true || ($request->getPackageQty() == $freeQty)) {
124:                 $shippingPrice = 0;
125:             } else {
126:                 $shippingPrice = $this->getFinalPriceWithHandlingFee($rate['price']);
127:             }
128: 
129:             $method->setPrice($shippingPrice);
130:             $method->setCost($rate['cost']);
131: 
132:             $result->append($method);
133:         }
134: 
135:         return $result;
136:     }
137: 
138:     public function getRate(Mage_Shipping_Model_Rate_Request $request)
139:     {
140:         return Mage::getResourceModel('shipping/carrier_tablerate')->getRate($request);
141:     }
142: 
143:     public function getCode($type, $code='')
144:     {
145:         $codes = array(
146: 
147:             'condition_name'=>array(
148:                 'package_weight' => Mage::helper('shipping')->__('Weight vs. Destination'),
149:                 'package_value'  => Mage::helper('shipping')->__('Price vs. Destination'),
150:                 'package_qty'    => Mage::helper('shipping')->__('# of Items vs. Destination'),
151:             ),
152: 
153:             'condition_name_short'=>array(
154:                 'package_weight' => Mage::helper('shipping')->__('Weight (and above)'),
155:                 'package_value'  => Mage::helper('shipping')->__('Order Subtotal (and above)'),
156:                 'package_qty'    => Mage::helper('shipping')->__('# of Items (and above)'),
157:             ),
158: 
159:         );
160: 
161:         if (!isset($codes[$type])) {
162:             throw Mage::exception('Mage_Shipping', Mage::helper('shipping')->__('Invalid Table Rate code type: %s', $type));
163:         }
164: 
165:         if (''===$code) {
166:             return $codes[$type];
167:         }
168: 
169:         if (!isset($codes[$type][$code])) {
170:             throw Mage::exception('Mage_Shipping', Mage::helper('shipping')->__('Invalid Table Rate code for type %s: %s', $type, $code));
171:         }
172: 
173:         return $codes[$type][$code];
174:     }
175: 
176:     /**
177:      * Get allowed shipping methods
178:      *
179:      * @return array
180:      */
181:     public function getAllowedMethods()
182:     {
183:         return array('bestway'=>$this->getConfigData('name'));
184:     }
185: 
186: }
187: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0