Example #1
0
 public static function order($name, $email = '', $phone = '', $address = '', $comment = '', $notifyGroup = 'admin', $notifyCustomer = true)
 {
     global $db;
     $user = \cf\User::getLoggedIn();
     $productList = '';
     $products = \cf\api\cart\getList();
     if (count($products) < 2) {
         return false;
     }
     for ($i = 1; $i < count($products); ++$i) {
         $productList .= "{$products[$i]['id']} {$products[$i]['name']} [{$products[$i]['price']}] - {$products[$i]['amount']} <br>";
     }
     $productList .= "<br><strong>Итого</strong>: {$products[0]['total_price']}";
     execQuery("\n\t\t\tINSERT INTO cf_orders (created,customer_name, customer_email, customer_phone, customer_address, customer_comments, comments)\n\t\t\tVALUES(NOW(),:name, :email, :phone, :address, :comments, :products)", array('name' => $name, 'email' => $email, 'phone' => $phone, 'address' => $address, 'comments' => $comment, 'products' => $productList));
     $orderId = $db->lastInsertId();
     \cf\api\cart\clear();
     $msgParams = array('name' => $name, 'email' => $email, 'phone' => $phone, 'address' => $address, 'comment' => $comment, 'order' => $orderId, 'total' => array_shift($products), 'products' => $products);
     if ($notifyGroup) {
         $emails = query2vector("SELECT email FROM cf_users INNER JOIN cf_user_roles ON cf_users.id=cf_user_roles.user_id WHERE cf_user_roles.role_id=:id", array('id' => $notifyGroup));
         if (!empty($emails)) {
             $tpl = new MailTemplate('admin_purchase_notify');
             $mail = new \PHPMailer();
             $mail->CharSet = 'UTF-8';
             $mail->Subject = $tpl->parseSubject($msgParams);
             $mail->MsgHTML($tpl->parseBody($msgParams));
             foreach ($emails as $a) {
                 $mail->AddAddress($a);
             }
             $mail->Send();
         }
     }
     if ($notifyCustomer && $email) {
         $tpl = new MailTemplate('user_purchase_notify');
         $mail = new \PHPMailer();
         $mail->CharSet = 'UTF-8';
         $mail->Subject = $tpl->parseSubject($msgParams);
         $mail->MsgHTML($tpl->parseBody($msgParams));
         $mail->AddAddress($email);
         @$mail->Send();
     }
     return $orderId;
 }
Example #2
0
 public static function loadOptions($id)
 {
     static $q = null;
     createStaticQuery($q, "\r\n\t\t\tSELECT option_id\r\n\t\t\tFROM cf_product_options\r\n\t\t\tWHERE product_id=:id\r\n\t\t\tORDER BY sort_order ASC\r\n\t\t");
     $res = query2vector($q, array('id' => $id));
     $options = array();
     foreach ($res as $oid) {
         $options[$oid] = new Product($oid);
     }
     return $options;
 }