dongxia8656 2016-06-16 13:14
浏览 26
已采纳

根据交换机案例在数据库中添加新数量

I have this in my controller

$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();

If user choose Normal Delivery price is +0 and I save $order->price = Input::get('price'); this is only the product/s price.

How can I make here condition if user choose Express Delivery addition amount to be added to product price here $order->price = Input::get('price'); something like

if (Settings::SETTINGS_SHIPPING_EXPRES)
{ $order->price = Input::get('price') + shipping_express_price; }
else  { $order->price = Input::get('price'); }
  • 写回答

1条回答 默认 最新

  • du127953 2016-06-16 13:18
    关注

    Try this:

    if (Input::get('shipping_method') == Settings::SETTINGS_SHIPPING_EXPRESS)
    {
        $order->price = Input::get('price') + shipping_express_price;
    }
    else
    {
        $order->price = Input::get('price');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大