예제 #1
0
파일: cart.php 프로젝트: noorafree/makmakan
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\Cart;
$cart = new Cart();
if ($_POST) {
    $cart->update($_POST);
    Yii::$app->controller->refresh();
}
?>
<div class="container">
    <div class="row" id="starts">
        <div class="col-md-12 col-sm-12 col-xs-12 site-content">
            <div class="col-md-12 col-sm-12 col-xs-12" style="border-bottom: solid 1px #FF9999; padding-bottom: 20px; margin-bottom: 30px;">
                <?php 
echo Html::a('< Lanjutkan Belanja', ['site/product']);
?>
            </div>
            <div class="form">
                <div class="row">
                    <?php 
$form = ActiveForm::begin(['id' => 'cart-form', 'options' => ['class' => 'form-horizontal']]);
?>
                    <div class="col-md-8 col-sm-8 col-xs-12" style="padding: 0px 50px 0px;">
                        <table cellpadding="6" cellspacing="5" style="width:100%">
                            <tr>
                                <th></th>
                                <th></th>
                                <th>Jumlah & Waktu Pengiriman</th>
                                <th style="text-align:right">Sub-Total</th>
예제 #2
0
 public function save()
 {
     //Yii::getLogger()->log('start save photobook:'.$this->id, YII_DEBUG);
     $cart = Cart::findOne(['id' => $this->id]);
     if (empty($cart)) {
         $cart = new Cart();
         $cart->user_id = $this->user_id;
         $cart->title = $this->title;
         $cart->price = $this->price;
         $cart->quantity = $this->quantity;
         $cart->sub_total = $this->sub_total;
         $cart->product_type = $this->product_type;
         if (empty($this->product_info)) {
             $this->product_info = [];
         }
         $cart->product_info = json_encode($this->product_info);
         Yii::getLogger()->log('save:', YII_DEBUG);
         if ($cart->save()) {
             $this->id = $cart->id;
             return $cart;
         } else {
             Yii::getLogger()->log('save error', YII_DEBUG);
         }
     } else {
         $cart->user_id = $this->user_id;
         $cart->title = $this->title;
         $cart->price = $this->price;
         $cart->quantity = $this->quantity;
         $cart->sub_total = $this->sub_total;
         $cart->product_type = $this->product_type;
         if (empty($this->product_info)) {
             $this->product_info = [];
         }
         $cart->product_info = json_encode($this->product_info);
         Yii::getLogger()->log('update:', YII_DEBUG);
         if ($cart->update()) {
             return $cart;
         } else {
             Yii::getLogger()->log('update error:' . print_r($cart, true), YII_DEBUG);
         }
     }
     return null;
 }