public function actionIndex() { $this->htmlOption = array('class' => 'icon-head head-products', 'header' => "货运设置", 'button' => array(array('class' => 'scalable save', 'id' => 'form-save', 'header' => '保存'))); $carrier = $this->loadModel(); if ($_POST['SHIPPING']) { configuration::updateItems($_POST['SHIPPING']); } if ($_POST['feeAdd']) { foreach ($_POST['feeAdd'] as $key => $row) { if ($row != 0) { $arr = explode('-', $key); $delivery = new delivery(); $delivery->carrier_ID = $_POST['carrier_ID']; $delivery->zone_ID = $arr[0]; $delivery->weight_range_ID = $arr[1]; $delivery->price = $row; $delivery->save(); } } } if ($_POST['feeUpdate']) { foreach ($_POST['feeUpdate'] as $key => $row) { $delivery = delivery::model()->findByPk($key); if ($row != 0 && $row != $delivery->price) { $delivery->price = $row; $delivery->save(); } else { if ($row == 0) { $delivery->delete(); } } } } $config = configuration::item('SHIPPING', 'SHIPPING_FREE_PRICE'); $this->constructScript('index'); $this->render('index', array('config' => $config, 'carrier' => $carrier)); }
/** * Return shipping total * * @param integer $Carrier_ID Carrier ID (default : current carrier) * @return float Shipping total */ public function getOrderShippingCost($carrier_ID = NULL) { if ($this->isFreeshipping()) { return 0; } // Get id zone if (isset($this->cart_address_ID) and $this->cart_address_ID) { $id_zone = address_entity::model()->findByPk($this->cart_address_ID)->getZoneId(); } else { $id_zone = 1; } //if no carrier selectd,chosen default one if (!$carrier_ID) { $carrier_ID = $this->cart_carrier_ID; } if (empty($carrier_ID)) { return 0; } if (!($carrier = carrier_entity::model()->findByPk($carrier_ID))) { throw new CHttpException(500, 'No Carrier Chosen'); } if ($carrier->carrier_shipping_handing != 1) { return 0; } if (!($weightID = weight_range::validateCarrier($this->getWeightTotal(), $carrier_ID))) { return 'Out'; } $shippingCost = 0; if ($delivery = delivery::model()->findByAttributes(array('carrier_ID' => $carrier_ID, 'zone_ID' => $id_zone, 'weight_range_ID' => $weightID))) { $shippingCost = $delivery->price; } return $shippingCost; }
<?php echo "<tr>"; echo CHtml::activeDropDownList($carrier, 'carrier_ID', carrier_entity::items(), array('class' => 'required-entry required-entry input-select', 'id' => 'carrier', 'name' => 'carrier_ID')); echo "</tr>"; echo ' <tr class="headings"> <th style="padding:4px 6px;">区域 / 范围</th>'; foreach ($carrier->weight as $row) { $l1 = floatval($row->delimiter1); $l2 = floatval($row->delimiter2); echo "<th style='font-size: 11px; padding:4px 6px;'>{$l1}kg to {$l2}kg</th>"; } echo '</tr>'; foreach ($carrier->zones as $row) { echo "<tr class='filter'><th style='height: 30px; padding:4px 6px;'>{$row->name}</th>"; foreach ($carrier->weight as $item) { $delivery = delivery::model()->findByAttributes(array('carrier_ID' => $carrier->carrier_ID, 'zone_ID' => $row->zone_ID, 'weight_range_ID' => $item->weight_ID)); if ($delivery) { $fee = $delivery->price; $name = "feeUpdate[{$delivery->delivery_ID}]"; } else { $fee = '0.00'; $name = "feeAdd[{$row->zone_ID}-{$item->weight_ID}]"; } echo "<td class='center'>\$ <input type='text' class='required-entry required-entry input-text' style='width: 45px; height:18px;' value='{$fee}' name='{$name}' ></td>"; } echo '</tr>'; } ?> </tbody> </table>