0

I have build a custom module for ExpressionEngine. It works perfectly on my local dev environment, but when I move it to my live server it freaks out and gives me errors, most notably: Invalid argument supplied for foreach.

I cant figure out what is going wrong, but have tried on two separate installs of ExpressionEngine, on two different domains and both give the same error. Code below:

    public function product_prices() {

    // Build module tags for EE output
    $tagdata = $this->EE->TMPL->tagdata;


    // Create CURL resource 
    $service_provider = curl_init(); 

    // Parse URL to CURL and create connection 
    curl_setopt($service_provider, CURLOPT_URL, "https://www.example.com"); 

    // Return responce as a string 
    curl_setopt($service_provider, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the returned string 
    $service_provider_output = curl_exec($service_provider); 

    // Close curl resource to free up system resources 
    curl_close($service_provider);     

    // Create Array from JSon array
    $sp_arr = json_decode($service_provider_output, true);



    // Create CURL resource 
    $service_details = curl_init(); 

    // Parse URL to CURL and create connection 
    curl_setopt($service_details, CURLOPT_URL, "https://www.example.com"); 

    // Return responce as a string 
    curl_setopt($service_details, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the returned string 
    $service_details_output = curl_exec($service_details); 

    // Close curl resource to free up system resources 
    curl_close($service_details);     

    // Create Array from JSon array
    $spdetails_arr = json_decode($service_details_output, true);



    // Create CURL resource 
    $price_details = curl_init(); 

    // Parse URL to CURL and create connection 
    curl_setopt($price_details, CURLOPT_URL, "https://www.example.com"); 

    // Return responce as a string 
    curl_setopt($price_details, CURLOPT_RETURNTRANSFER, 1); 

    // $output contains the returned string 
    $price_details_output = curl_exec($price_details); 

    // Close curl resource to free up system resources 
    curl_close($price_details);     

    // Create Array from JSon array
    $price_details_arr = json_decode($price_details_output, true);

    $detailed_product = array();

    // Insert query results into variables
    foreach ($spdetails_arr["data"] as $val_detail) {
        $detailed_product_name = $val_detail['name'];
        $detailed_product_sp_id = $val_detail['service_provider'];
        $detailed_product_s_discripton = $val_detail['short_description'];
        $detailed_product_s_discripton = $val_detail['description'];
        $detailed_product_id = $val_detail['id'];
        $detailed_service_id = $val_detail['service'];


            // Replace Service Provider ID with Full Name
            foreach ($sp_arr["data"] as $val) {
                $sp_name = $val['name'];
                $sp_id = $val['id'];

                if ($detailed_product_sp_id == $sp_id) {
                    $sp_full_name = $sp_name;
                }
            }

            // Pull Price and associate with service
            foreach ($price_details_arr["data"] as $val_price) {
                $service_id = $val_price['service'];
                $service_price = $val_price['price'];
                $service_type = $val_price['type'];

                if ($detailed_service_id == $service_id && $service_type == "Monthly") {
                    $service_price_monthly = $service_price;

                    if ($service_price_monthly == "0.00") {
                        $service_price_monthly = "No Price Found";
                    }
                }

                if ($detailed_service_id == $service_id && $service_type == "Start") {
                    $service_price_start = $service_price;
                }

            }

        $detailed_product[] = array(
            "service_name" => $detailed_product_name,
            "service_provider" => $sp_full_name,
            "monthly_price" => $service_price_monthly,
            "connection_fee" => $service_price_start,
            "type" => $service_type,
            "service_id" => $detailed_service_id,
            "s_discription" => $detailed_product_s_discripton,
            "l_discription" => $detailed_product_s_discripton
        );
    }

    // Return tag pair
    return $this->EE->TMPL->parse_variables($tagdata, $detailed_product);
}

Am I doing something very wrong here? I have a feeling it might be something to do with Codeigniter, but can't be sure as I am still a junior programmer.

Thanks alot

0

Try outputting the result of CURL request directly into browser. It is probably that one of the requests does not return valid JSON, therefore you don't get valid URL to loop through.

Purely guess though, as you did not mention to what line the error message is pointing.

| improve this answer | |
  • Thanks man, this helped me to figure out the issue at hand. I appreciate the assistance – Sydcpt Nov 23 '15 at 8:13
  • You're welcome. If the issue is resolved, please accept the appropriate answer by clicking the icon next to it. – Yuri Salimovskiy Nov 23 '15 at 14:18
0

I managed to figure it out:

Firstly, I enabled debugging by using the curl_getinfo

From this I was able to determined that the HTTP response was returning 0. This was due to an issue with the SSL certificate not getting verified on the server side.

To fix, I added a pem certificate and linked to it.

Issue resolved.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.