Example #1
0
 public function getCustomerSales()
 {
     return $this->hasOne(Kiwi::getCustomerSalesClass(), ['key' => 'key']);
 }
Example #2
0
 public function saveOrder()
 {
     $ShoppingCart = Kiwi::getShoppingCart();
     $this->user_id = Yii::$app->user->id;
     $this->total_price = $ShoppingCart->getTotal();
     /**@TODO attributes  * */
     $this->shipping_fee = $ShoppingCart->getShippingFee();
     $this->payment_fee = 0;
     $this->status = 1;
     $cartItems = $ShoppingCart->cartItems;
     $orderItems = [];
     foreach ($cartItems as $cartItem) {
         $key = $cartItem->data['key'];
         /** @var \extensions\sales\models\CustomerSales $customer_sale */
         $customerSaleClass = Kiwi::getCustomerSalesClass();
         $customer_sale = $customerSaleClass::find()->where(['key' => $key])->one();
         $orderItem = Kiwi::getOrderItem();
         $orderItem->item_id = $cartItem->item->item_id;
         $orderItem->price = $customer_sale->sale_price;
         $orderItem->qty = $cartItem->qty;
         $orderItem->name = $cartItem->item->name;
         $orderItem->data = $cartItem->data;
         /**@TODO picture can not null * */
         $orderItem->picture = is_null($cartItem->item->pictures) ? $cartItem->item->pictures : 'default';
         $orderItems[] = $orderItem;
     }
     $this->orderItems = $orderItems;
     if ($this->save()) {
         $ShoppingCart->clearAll();
         return true;
     }
     return false;
 }
Example #3
0
            <div class="box-title container_24">商品列表</div>
            <div class="box-content cart container_24">
                <table id="list-div-box" class="table">
                    <tr style="background:#F3F3F3;">
                        <th class="col-xs-3">图片</th>
                        <th class="col-xs-3">名称</th>
                        <!--                <th class="col-xs-3">属性</th>-->
                        <th class="col-xs-1">价格</th>
                        <th class="col-xs-1">数量</th>
                        <th class="col-xs-1">小计</th>
                    </tr>
                    <?php 
foreach ($cartItems as $cartItem) {
    $key = $cartItem->data['key'];
    /** @var \extensions\sales\models\CustomerSales $customer_sale */
    $customerSaleClass = Kiwi::getCustomerSalesClass();
    $customer_sale = $customerSaleClass::find()->where(['key' => $key])->one();
    $item = $cartItem->item;
    if (isset($item)) {
        $pictures = explode(',', $item->pictures);
        ?>
                            <tr><?php 
        if ($item->pictures) {
            $picUrl = is_array($pictures) ? $pictures[0] : $pictures;
            ?>
                                <td><?php 
            echo Html::img($picUrl, ['style' => "width : 80px; height:80px"]);
        } else {
            echo Yii::t('leather', '该商品没有上传图片');
        }
        ?>
Example #4
0
 /**
  * @param int $item_id
  * @return number|string
  */
 public function getSubTotal($item_id = 0)
 {
     //@TODO need to add event
     if ($item_id) {
         $cartItem = $this->cartItems[$item_id];
         $key = $cartItem->data['key'];
         /** @var \extensions\sales\models\CustomerSales $customer_sale */
         $customerSaleClass = Kiwi::getCustomerSalesClass();
         $customer_sale = $customerSaleClass::find()->where(['key' => $key])->one();
         return $customer_sale->sale_price * $cartItem->qty;
         //            return $cartItem->item->price * $cartItem->qty;
     }
     $subTotals = [];
     foreach ($this->cartItems as $item_id => $carItem) {
         $subTotals[$item_id] = $this->getSubTotal($item_id);
     }
     return array_sum($subTotals);
 }