Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 private function generateNote($note)
 {
     $patterns = ['/{follow}/', '/{of}/', '/{from}/', '/{to}/', '/({delete}|{Delete})/', '/({create}|{Create})/'];
     $replace = [Yii::t('ecommerce', 'width change follow') . ': ', Yii::t('ecommerce', 'of'), Yii::t('ecommerce', 'from'), Yii::t('ecommerce', 'to'), Yii::t('yii', 'Delete'), Yii::t('ecommerce', 'Create')];
     // Search and replace attribute in ecommerce
     $attributes = Order::attributes();
     foreach ($attributes as $attribute) {
         $patterns[] = '/{attribute_' . $attribute . '}/';
         $replace[] = ucfirst(Order::getAttributeLabel($attribute));
     }
     // Search and replace language in ecommerce
     preg_match_all('/{ecommerce_(\\w)+}/', $note, $matches);
     //        var_dump($matches[0]);die;
     if (isset($matches[0])) {
         foreach ($matches[0] as $match) {
             if (strstr($match, 'ecommerce_')) {
                 $patterns[] = '/' . $match . '/';
                 $replace[] = Yii::t('ecommerce', Order::getAttributeLabel(preg_replace(['/{ecommerce_/', '/}/'], '', $match)));
             }
         }
     }
     return preg_replace($patterns, $replace, $note);
 }