Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

SyntaxError: JSON Parse error: Unrecognized token '<' OK


Recommended Posts

помогите разобраться, при оформлении заказа появляется вот икое ругательство:

SyntaxError: JSON Parse error: Unrecognized token '<' OK Notice: Undefined index: products in /var/www/u0522611/data/www/ххх/catalog/controller/extension/module/notificationTelegram.php on line 105Notice: Undefined index: products in /var/www/u0522611/data/www/ххх/catalog/controller/extension/module/notificationTelegram.php on line 105Notice: Undefined index: products in /var/www/u0522611/data/www/ххх/catalog/controller/extension/module/notificationTelegram.php on line 105{"redirect":"http://ххх/index.php?route=checkout/success"}

код:

 

<?php
class ControllerExtensionModuleNotificationTelegram extends Controller {
        
    public function sendOrderAlert(&$route, &$data, &$output) {

        $order_id = $data[0];
        $this->load->model('checkout/order');
        $order_info = $this->model_checkout_order->getOrder($order_id);

        $this->load->model('setting/setting');
        $setting = $this->model_setting_setting->getSetting('module_notificationTelegram');

        if (isset($setting['module_notificationTelegram_order_alert'])) {
            
            $this->load->model('account/order');
            if (count($this->model_account_order->getOrderHistories($order_id)) <= 1) {
                $message = $this->replaceMessage($setting['module_notificationTelegram_meassage'],$order_info);
//                  $message .= $this->buldArray($order_info);

                $this->sendMessagetoTelegam($message);

                if (strpos(strtolower($setting['module_notificationTelegram_meassage']), '{products}') !== false) {
                    $order_products = $this->model_checkout_order->getOrderProducts($order_id);
                    $products = $this->bulidProducts($order_products);
                    $this->sendMessagetoTelegam($products);

                }
            }
            
        }
        
    }
    
    public function sendAccountAlert(&$route, &$data, &$output) {
        $this->load->model('setting/setting');
        $setting = $this->model_setting_setting->getSetting('module_notificationTelegram');
        if (isset($setting['module_notificationTelegram_customer_alert'])) {

            $message = $this->replaceMessage($setting['module_notificationTelegram_new_account_meassage'],$data[0]);
            $this->sendMessagetoTelegam( $message);
            
        }
    }
    
    public function sendReturnProductAlert(&$data,&$output) {
        $this->load->model('setting/setting');
        $setting = $this->model_setting_setting->getSetting('module_notificationTelegram');
        if (isset($setting['module_notificationTelegram_return_alert'])) {
            
            $message = "Return request \n ";
            $this->sendMessagetoTelegam( $message);
        }
    }
    
    
    //Send  message To notificationTelegram
    public function sendMessagetoTelegam($msg) {
        
        $this->load->model('setting/setting');
        $setting = $this->model_setting_setting->getSetting('module_notificationTelegram');
        
        //print_r($setting);
        $botToken = $setting['module_notificationTelegram_boot_token'];
        $website = "https://api.telegram.org/bot" . $botToken;
        $chatIds = $setting['module_notificationTelegram_chat_ids'];  //Receiver Chat Id
        
        if (is_array($chatIds)) {
            foreach ($chatIds as $val) {
                $this->initMessage($botToken, $val, $msg);
            }
        } else {
            $this->initMessage($botToken, $chatIds, $msg);
        }
    }
    private function initMessage($botToken, $chatID, $msg) {
        
        $website = "https://api.telegram.org/bot" . $botToken;
        
        $params = [
            'chat_id' => $chatID,
            'text' => $msg,
        ];
        $ch = curl_init($website . '/sendMessage');
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);
        curl_close($ch);            
    }
    
    public function buldArray($arr) {
        if (is_array($arr)) {
            $dataAttributes = array_map(function ($value, $key) {
                return @"$key ---> $value  \n";
            }, array_values($arr), array_keys($arr));
            
            return $dataAttributes = implode(' ', $dataAttributes);
        }
    }
    
    public function replaceMessage($string,$arr) {
        return   $str = preg_replace_callback('/{(\w+)}/', function($match) use($arr) {
            return $arr[$match[1]];
        }, $string );
        
    }
    
    protected function  bulidProducts($products){

        $pr = array();

        foreach ($products as $product){
            $pr[] = "Name : $product[name]  \n    Price: $product[price] \n qty : $product[quantity] ";
        }

        return implode("------- \n",$pr);
        
    }
        
}

Link to comment
Share on other sites


Спойлер

 

52 минуты назад, lenadzhamalieva сказал:

помогите разобраться, при оформлении заказа появляется вот икое ругательство:

SyntaxError: JSON Parse error: Unrecognized token '<' OK Notice: Undefined index: products in /var/www/u0522611/data/www/ххх/catalog/controller/extension/module/notificationTelegram.php on line 105Notice: Undefined index: products in /var/www/u0522611/data/www/ххх/catalog/controller/extension/module/notificationTelegram.php on line 105Notice: Undefined index: products in /var/www/u0522611/data/www/ххх/catalog/controller/extension/module/notificationTelegram.php on line 105{"redirect":"http://ххх/index.php?route=checkout/success"}

код:

 

<?php
class ControllerExtensionModuleNotificationTelegram extends Controller {
        
    public function sendOrderAlert(&$route, &$data, &$output) {

        $order_id = $data[0];
        $this->load->model('checkout/order');
        $order_info = $this->model_checkout_order->getOrder($order_id);

        $this->load->model('setting/setting');
        $setting = $this->model_setting_setting->getSetting('module_notificationTelegram');

        if (isset($setting['module_notificationTelegram_order_alert'])) {
            
            $this->load->model('account/order');
            if (count($this->model_account_order->getOrderHistories($order_id)) <= 1) {
                $message = $this->replaceMessage($setting['module_notificationTelegram_meassage'],$order_info);
//                  $message .= $this->buldArray($order_info);

                $this->sendMessagetoTelegam($message);

                if (strpos(strtolower($setting['module_notificationTelegram_meassage']), '{products}') !== false) {
                    $order_products = $this->model_checkout_order->getOrderProducts($order_id);
                    $products = $this->bulidProducts($order_products);
                    $this->sendMessagetoTelegam($products);

                }
            }
            
        }
        
    }
    
    public function sendAccountAlert(&$route, &$data, &$output) {
        $this->load->model('setting/setting');
        $setting = $this->model_setting_setting->getSetting('module_notificationTelegram');
        if (isset($setting['module_notificationTelegram_customer_alert'])) {

            $message = $this->replaceMessage($setting['module_notificationTelegram_new_account_meassage'],$data[0]);
            $this->sendMessagetoTelegam( $message);
            
        }
    }
    
    public function sendReturnProductAlert(&$data,&$output) {
        $this->load->model('setting/setting');
        $setting = $this->model_setting_setting->getSetting('module_notificationTelegram');
        if (isset($setting['module_notificationTelegram_return_alert'])) {
            
            $message = "Return request \n ";
            $this->sendMessagetoTelegam( $message);
        }
    }
    
    
    //Send  message To notificationTelegram
    public function sendMessagetoTelegam($msg) {
        
        $this->load->model('setting/setting');
        $setting = $this->model_setting_setting->getSetting('module_notificationTelegram');
        
        //print_r($setting);
        $botToken = $setting['module_notificationTelegram_boot_token'];
        $website = "https://api.telegram.org/bot" . $botToken;
        $chatIds = $setting['module_notificationTelegram_chat_ids'];  //Receiver Chat Id
        
        if (is_array($chatIds)) {
            foreach ($chatIds as $val) {
                $this->initMessage($botToken, $val, $msg);
            }
        } else {
            $this->initMessage($botToken, $chatIds, $msg);
        }
    }
    private function initMessage($botToken, $chatID, $msg) {
        
        $website = "https://api.telegram.org/bot" . $botToken;
        
        $params = [
            'chat_id' => $chatID,
            'text' => $msg,
        ];
        $ch = curl_init($website . '/sendMessage');
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);
        curl_close($ch);            
    }
    
    public function buldArray($arr) {
        if (is_array($arr)) {
            $dataAttributes = array_map(function ($value, $key) {
                return @"$key ---> $value  \n";
            }, array_values($arr), array_keys($arr));
            
            return $dataAttributes = implode(' ', $dataAttributes);
        }
    }
    
    public function replaceMessage($string,$arr) {
        return   $str = preg_replace_callback('/{(\w+)}/', function($match) use($arr) {
            return $arr[$match[1]];
        }, $string );
        
    }
    
    protected function  bulidProducts($products){

        $pr = array();

        foreach ($products as $product){
            $pr[] = "Name : $product[name]  \n    Price: $product[price] \n qty : $product[quantity] ";
        }

        return implode("------- \n",$pr);
        
    }
        
}

 

 

 

Спасипотому что за код.

Link to comment
Share on other sites

2 часа назад, Otvet сказал:

не высивляйте код модулей 

 

1 час назад, buslikdrev сказал:

Спасипотому что за код.

 

ну модуль то фришный.

https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=34325

 

2 часа назад, lenadzhamalieva сказал:

помогите разобраться, при оформлении заказа появляется вот икое ругательство:

 

Если нужен нормальный рилилий модуль для уведомлений в телеграм, прощу.

 

Link to comment
Share on other sites

14 часов назад, lenadzhamalieva сказал:

/var/www/u0522611/data/www/ххх/catalog/controller/extension/module/notificationTelegram.php

У меня не стоит икой модуль. по привегденному коду

protected function  bulidProducts($products){ //в функцию передается массив товаров

этот массив передается отсюда

                    $order_products = $this->model_checkout_order->getOrderProducts($order_id);
                    $products = $this->bulidProducts($order_products);

нужно проверить, приходит ли массив ($order_products) из могдели mode/checkout/order.php

 

Link to comment
Share on other sites

16 минут назад, esculapra сказал:

У меня не стоит икой модуль. по привегденному коду

protected function  bulidProducts($products){ //в функцию передается массив товаров

этот массив передается отсюда

                    $order_products = $this->model_checkout_order->getOrderProducts($order_id);
                    $products = $this->bulidProducts($order_products);

нужно проверить, приходит ли массив ($order_products) из могдели mode/checkout/order.php

 

спасипотому что, сейчас попробую разобраться

Link to comment
Share on other sites


5 минут назад, lenadzhamalieva сказал:

спасипотому что, сейчас попробую разобраться

я не изменяла model/checkout/order.php им все по умолчанию, ничего не могу понять

Link to comment
Share on other sites


  • 7 months later...

В админке модуля уберите перелисление продуктов, а именно {products}
в телегу не бугдет приходить список продуктов но и ошибка исчезнет

Link to comment
Share on other sites


  • 8 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.