Example #1
0
 /**
  * Return CashOnDelivery Surcharge Value
  *
  * @param Varien_Object
  *
  * @return float
  */
 public function getCashOnDeliverySurcharge(Varien_Object $request)
 {
     $adapter = $this->_getReadAdapter();
     $bind = array(':website_id' => (int) $request->getWebsiteId(), ':country_id' => $request->getDestCountryId(), ':region_id' => $request->getDestRegionId(), ':postcode' => $request->getDestPostcode(), ':weight' => (double) $request->getPackageWeight(), ':price' => (double) $request->getData('zitec_table_price'), ':method' => $request->getMethod());
     $select = $adapter->select()->from($this->getMainTable(), array('cashondelivery_surcharge', 'cod_min_surcharge'))->where('website_id=:website_id')->order(array('dest_country_id DESC', 'dest_region_id DESC', 'dest_zip DESC', 'method DESC', 'price_vs_dest DESC', 'weight DESC'));
     // render destination condition
     $orWhere = '(' . implode(') OR (', array("dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = :postcode", "dest_country_id = :country_id AND dest_region_id = :region_id AND dest_zip = ''", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = ''", "dest_country_id = :country_id AND dest_region_id = 0 AND dest_zip = :postcode", "dest_country_id = '0' AND dest_region_id = 0 AND dest_zip = ''")) . ')';
     $select->where($orWhere);
     $select->where('((weight <= :weight and price_vs_dest = 0) or (weight <= :price and price_vs_dest = 1))');
     $select->where('method = :method');
     $rate = $adapter->fetchRow($select, $bind);
     if (empty($rate) && $this->isRateDefinedForMethod($request)) {
         $rate = null;
     }
     return $rate;
 }