我在控制器中有这个
$shipping = array(
'quantity' => 1,
'image' => '/img/noimage.png',
'description' => '',
'title' => 'FIX ME', // this should never occur,
'price' => 100000 // this should never occur
);
switch (Input::get('shipping_method')) {
case Settings::SETTINGS_SHIPPING_NORMAL:
$shipping['title'] = 'Normal Delivery';
$shipping['price'] = 0;
break;
case Settings::SETTINGS_SHIPPING_EXPRESS:
$shipping['title'] = sprintf('Express Delivery - $%.2f', Settings::getOption('express_shipping_cost'));
$shipping['price'] = doubleval(Settings::getOption('express_shipping_cost'));
break;
}
$cart['shipping'] = $shipping;
$order = new Order();
$order->data = json_encode($cart, true);
$order->address = Input::get('shipping_address');
$order->info = Input::get('additional_info');
$order->price = Input::get('price');
$order->save();
如果用户选择Normal Delivery
价格为+0且我保存$order->price = Input::get('price');
,则这只是产品价格。
如果用户在此处选择Express Delivery
添加金额添加到产品价格,我该如何制作条件
$order->price = Input::get('price');
类似
if (Settings::SETTINGS_SHIPPING_EXPRES)
{ $order->price = Input::get('price') + shipping_express_price; }
else { $order->price = Input::get('price'); }
答案 0 :(得分:0)
试试这个:
if (Input::get('shipping_method') == Settings::SETTINGS_SHIPPING_EXPRESS)
{
$order->price = Input::get('price') + shipping_express_price;
}
else
{
$order->price = Input::get('price');
}