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
00029
00030
00031
00032
00033
00034
00035 class Mage_Shipping_Model_Carrier_Flatrate
00036 extends Mage_Shipping_Model_Carrier_Abstract
00037 implements Mage_Shipping_Model_Carrier_Interface
00038 {
00039
00040 protected $_code = 'flatrate';
00041
00042
00043
00044
00045
00046
00047
00048 public function collectRates(Mage_Shipping_Model_Rate_Request $request)
00049 {
00050 if (!$this->getConfigFlag('active')) {
00051 return false;
00052 }
00053
00054 $freeBoxes = 0;
00055 if ($request->getAllItems()) {
00056 foreach ($request->getAllItems() as $item) {
00057 if ($item->getFreeShipping() && !$item->getProduct()->isVirtual()) {
00058 $freeBoxes+=$item->getQty();
00059 }
00060 }
00061 }
00062 $this->setFreeBoxes($freeBoxes);
00063
00064 $result = Mage::getModel('shipping/rate_result');
00065 if ($this->getConfigData('type') == 'O') {
00066 $shippingPrice = $this->getConfigData('price');
00067 } elseif ($this->getConfigData('type') == 'I') {
00068 $shippingPrice = ($request->getPackageQty() * $this->getConfigData('price')) - ($this->getFreeBoxes() * $this->getConfigData('price'));
00069 } else {
00070 $shippingPrice = false;
00071 }
00072
00073 $shippingPrice = $this->getFinalPriceWithHandlingFee($shippingPrice);
00074
00075 if ($shippingPrice !== false) {
00076 $method = Mage::getModel('shipping/rate_result_method');
00077
00078 $method->setCarrier('flatrate');
00079 $method->setCarrierTitle($this->getConfigData('title'));
00080
00081 $method->setMethod('flatrate');
00082 $method->setMethodTitle($this->getConfigData('name'));
00083
00084 if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
00085 $shippingPrice = '0.00';
00086 }
00087
00088
00089 $method->setPrice($shippingPrice);
00090 $method->setCost($shippingPrice);
00091
00092 $result->append($method);
00093 }
00094
00095 return $result;
00096 }
00097
00098 public function getAllowedMethods()
00099 {
00100 return array('flatrate'=>$this->getConfigData('name'));
00101 }
00102
00103 }