示例#1
0
 /**
  * Function change cart to order
  * @param  array $product_info  infomation of product
  * @param  array $customer_info infomation of customer
  * @return boolean
  */
 public function createOrder($product_info, $customer_info)
 {
     if (empty($product_info)) {
         return false;
     }
     $order = new Order();
     $product_text = [];
     foreach ($product_info as $id => $info) {
         $title = ArrayHelper::getValue($info, 'title', null);
         if (!empty($title)) {
             $product_text[] = $title;
         }
     }
     $order->product_text = !empty($product_text) ? implode($product_text, ',') : null;
     $order->product = $product_info;
     $order->note_customer = ArrayHelper::getValue($customer_info, 'note_customer', null);
     if (isset($customer_info['note_customer'])) {
         unset($customer_info['note_customer']);
     }
     $order->customer = $customer_info;
     $order->status = Module::STATUS_NEW;
     $order->payment = 'pay_at_home';
     $order->shipping = '0';
     $order->quote_id = $this->getCartId();
     $saveOrder = $order->save();
     if ($saveOrder) {
         Yii::$app->session->remove('numberItemCart');
         Yii::$app->session->remove('quote_id');
     }
     return $saveOrder;
 }