public function actionGetExtTypeService() { $result = array('status' => 'error', 'data' => ''); $data = array(); if (isset($_REQUEST['Shipment'])) { $shipment = new Shipment(); $shipment->setAttributes($_REQUEST['Shipment']); if ($shipment->customer_id != '') { $join = 'INNER JOIN product_service t2 ON t.id = t2.product_id INNER JOIN service_detail t3 ON t2.id = t3.product_service_id INNER JOIN rate_company_service t4 ON t4.id = t3.rate_company_service_id JOIN rate_company t5 ON t5.id = t4.rate_company_id JOIN customer_discount t6 ON t3.id = t6.service_id'; $select = 't4.id as service_id,t2.name as service_name,t2.code,t4.name as carrier_service,t5.name vendor_name,t6.use_rate'; } else { $join = 'INNER JOIN product_service t2 ON t.id = t2.product_id INNER JOIN service_detail t3 ON t2.id = t3.product_service_id INNER JOIN rate_company_service t4 ON t4.id = t3.rate_company_service_id JOIN rate_company t5 ON t5.id = t4.rate_company_id'; $select = 't4.id as service_id,t2.name as service_name,t2.code,t4.name as carrier_service,t5.name vendor_name'; } $cek_routing = RateCompany::model()->findByAttributes(array('code' => $shipment->destination_code)); $criteria = new CDbCriteria(); $criteria->join = $join; $criteria->select = $select; $criteria->addSearchCondition('t.name', $shipment->service_type); if ($shipment->customer_id != '') { $criteria->params[':customer_id'] = $shipment->customer_id; $criteria->addCondition('t6.customer_id =:customer_id AND use_rate = 1'); } if ($shipment->service_type == 'City Courier') { if ($cek_routing instanceof RateCompany) { $criteria->addSearchCondition('t5.code', $shipment->destination_code); } else { $criteria->addSearchCondition('t5.id', 5); } } if ($shipment->service_type == 'Domestic') { $criteria->addSearchCondition('t5.code', $shipment->destination_code); } if ($shipment->service_type == 'International') { $criteria->addSearchCondition('t5.code', $shipment->destination_code); if (ucfirst($shipment->receiver_country) != 'indonesia') { $criteria->addSearchCondition('t2.id', 10); } else { $criteria->addSearchCondition('t2.id', 11); } } $builder = new CDbCommandBuilder(Yii::app()->db->Schema); $command = $builder->createFindCommand('product', $criteria); $services = $command->queryAll(); if (!!$services) { $result = array('status' => 'success', 'data' => $services); } } echo CJSON::encode($result); Yii::app()->end(); }
public function actionGetExtRate() { if (Yii::app()->request->isAjaxRequest) { $result = array('status' => 'error', 'data' => ''); $data = array(); if (isset($_POST['Shipment'])) { $shipment = new Shipment(); $shipment->setAttributes($_POST['Shipment']); switch ($shipment->service_type) { case 'City Courier': $rate = RateCity::model()->findByAttributes(array('service_id' => $shipment->service_id)); if ($rate instanceof RateCity) { $price = $rate->price * RateCity::increment($shipment->package_weight, $rate->weight_inc); } else { $area = Area::getZoneID($shipment->receiver_postal); $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight); } $result = array('status' => 'success', 'data' => $price); break; case 'Domestic': $area = Area::getZoneID($shipment->receiver_postal); $price = RateDomestic::getRatePrice($shipment->service_id, 1, $area['district_id'], $area['zone_id'], $shipment->package_weight); $result = array('status' => 'success', 'data' => $price); break; case 'International': $zone = FALSE; if ($shipment->service_code == 'IEX') { $country = $shipment->receiver_country; } else { if ($shipment->service_code == 'IMX') { $country = $shipment->shipper_country; } } $zone = ZoneInternational::getZoneCountryData($country); if (!!$zone) { $price = RateInternational::getRatePrice($shipment->service_id, $shipment->package_weight, $shipment->type, $zone); $result = array('status' => 'success', 'data' => $price); } break; case '': continue; } } echo CJSON::encode($result); Yii::app()->end(); } }