X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Issue in Curl calling in xcart page (https://forum.x-cart.com/showthread.php?t=75118)

ajeetsingh 03-22-2017 07:59 AM

Issue in Curl calling in xcart page
 
Hello,

I have an issue in calling the curl to send a notification message in admin area using code below:
PHP Code:

$url 'https://updates.push.services.mozilla.com/wpush/v1/';
        
$headers = array(
          
'Content-Type: application/json',
          
'TTL: 600000'
        
);
        foreach (
$sub_ids as $key => $value) {

            
$final_url=$url.$value;
            
//echo $finCURLOPT_POSTCURLOPT_POSTCURLOPT_POSTCURLOPT_POSTCURLOPT_POSTCURLOPT_POSTal_url;
            
$ch curl_init();  
            
// Set the url, number of POST vars, POST data
            
curl_setopt($chCURLOPT_URL$final_url);
            
curl_setopt($ch, , true);
            
curl_setopt($chCURLOPT_HTTPHEADER$headers);
            
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

            
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
            
curl_close($ch); 

Here $sub_ids is the subscription is which i get from browser for a client.
Please anyone can suggest me that what is wrong.

qualiteam 03-23-2017 10:58 AM

Re: Issue in Curl calling in xcart page
 
Instead of a direct Curl call try to use the ready-made \XLite\Core\HTTP\Request class.
You can find examples of using this class in the source code.

ajeetsingh 03-24-2017 06:20 AM

Re: Issue in Curl calling in xcart page
 
Hello
qualiteam,

Actually i do not get any types of class that are using source code for \XLite\Core\HTTP\Request.

So please suggest me in right way that's way i will be able to solve mu issue.

qualiteam 03-31-2017 12:02 AM

Re: Issue in Curl calling in xcart page
 
Please check how the class is used in the source code:
https://github.com/xcart/xcart5/search?p=3&q=%5CXLite%5CCore%5CHTTP%5CRequest&type =&utf8=%E2%9C%93

For example, here:
https://github.com/xcart/xcart5/blob/cf1f28cec010ef7044cc8bbfe2fe39eac0e30196/src/classes/XLite/Module/CDe.../Core/AAPI.php

ajeetsingh 04-01-2017 02:34 AM

Re: Issue in Curl calling in xcart page
 
Hello ,

I am not getting a wright solution for my problem. Again i am explaining my problem below:

I just want to call a notification message in a xcart backend page on clicking a button on that page for Mozila FireFox browser, And for that purpose i am using the curl request and the code for which i am using for the function is as below.

PHP Code:

public function sendPushMozila($sub_ids){
        
$url 'https://updates.push.services.mozilla.com/wpush/v1/';
        
$headers = array(
          
'Content-Type: application/json',
          
'TTL: 600000'
        
);
        foreach (
$sub_ids as $key => $value) {
            
$final_url=$url.$value;
            
$ch curl_init();  
            
// Set the url, number of POST vars, POST data
            
curl_setopt($chCURLOPT_URL$final_url);
            
curl_setopt($chCURLOPT_POSTtrue);
            
curl_setopt($chCURLOPT_HTTPHEADER$headers);
            
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

            
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
            
/*curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));*/
            
$result curl_exec($ch);
            
//var_dump($result); die;
            
curl_close($ch);
        }
    } 


In the above code the $sub_ids is the subscription ids of more then one user.

So please help me.

Thanks in Advance.

qualiteam 04-02-2017 10:50 PM

Re: Issue in Curl calling in xcart page
 
I'm sorry, but I don't understand what the problem is.
Please describe in steps what you want to implement and explain which steps you have problems with.
Have you added the button already? Is the problem that you don't know how to call your sendPushMozila() function on the server when a user clicks that button in the browser? How and where did you added sendPushMozila() function?

ajeetsingh 04-03-2017 12:58 AM

Re: Issue in Curl calling in xcart page
 
1 Attachment(s)
Hello qualiteam,


I am explaining step by step below: Please try to understand my problem.

1. At x-cart backend, I have create a page where n number of records are listed and there is a notify button for each record as shown in attachment.

2. I just want that when i click on the Notify Button i just want to show a notification in mozila firefox as like other eCommerce site send a notification for their new products or any other information when i subscribed their notification service.

3. So for that purpose on the click on that notification button i will call an ajax and the targer of that ajax is Notiftmplt and action is Notify.

4. Then Under the Notify function of that controller class Notiftemplt, i just call that finction sendPushMozila() which have the following code below:
PHP Code:

public function sendPushMozila($sub_ids){
        
$url 'https://updates.push.services.mozilla.com/wpush/v1/';
        
$headers = array(
          
'Content-Type: application/json',
          
'TTL: 600000'
        
);
        foreach (
$sub_ids as $key => $value) {
            
$final_url=$url.$value;
            
$ch curl_init();  
            
// Set the url, number of POST vars, POST data
            
curl_setopt($chCURLOPT_URL$final_url);
            
curl_setopt($chCURLOPT_POSTtrue);
            
curl_setopt($chCURLOPT_HTTPHEADER$headers);
            
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

            
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
            
/*curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));*/
            
$result curl_exec($ch);
            
//var_dump($result); die;
            
curl_close($ch);
        }
    } 


In the above code the $sub_ids is the subscription ids of more users.

IF any further clarification, Please let me know.

qualiteam 04-04-2017 12:50 AM

Re: Issue in Curl calling in xcart page
 
You said "I have an issue in calling the curl to send a notification message".
What is the issue?

You explained what you do, but you didn't say what is not working in the code that you have implemented. Do you see an error message? Or what?

If it is the curl call that causes a issue, try to use the \XLite\Core\HTTP\Request class as I have suggested. You can find examples of how to use this class in the source code of X-Cart itself.


All times are GMT -8. The time now is 08:29 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.