Jump to content


Photo

Prestashop php script purpose

prestashop php

  • Please log in to reply
7 replies to this topic

#1 Elektra

Elektra
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 February 2017 - 03:08 PM

Hi, I am not a coder, but I have this issue with my ecommerce platform which is based on Prestashop.

So could You please explain to me what is the purpose of this php script below? Whap is gonna to happen if I delete it (this script is giving me an error)?

<?php
        
$host = "http://localhost:8080";
$company = "BlueSky";
$email = "lisa.penvenen@gmail.com";
$price = "1000";
$offerNumber = "958";
$description = "My invoice";
$street = "Baker street 221B";
$city = "London";
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_USERPWD, "lisa.penvenen:mypass");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPAUTH, TRUE);
 
$id = send($ch, $host, $company, $description, $price, $offerNumber, $street, $city);
sendEmail($ch, $host, $company, $id, $email);
 
curl_close($ch);
 
function send($ch, $host, $company, $description, $price, $offerNumber, $street, $city) {
  curl_setopt($ch, CURLOPT_URL, $host . "/c/" . $company . "/invoice-issued.json");
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  $invoice = array(
    "winstrom" => array(
       "invoice-issued" => array(
          "documentType" => "code:INVOICE",
          "mine" => "code:WINSTROM",
          "description" => $popis,
          "total" => $price,
          "noItems" => "true",
          "offerNumber" => $offerNumber,
          "street" => $ulice,
          "city" => $mesto,
       )
    )
  );
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($invoice));
  $output = curl_exec($ch);
 
  if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200 && curl_getinfo($ch, CURLINFO_HTTP_CODE) != 201) {
     printf("Error occurred during the operation (HTTP %d): %sn", curl_getinfo($ch, CURLINFO_HTTP_CODE), $output);
  } else {
     $id = get_id($output);
     printf("Success (1) s ID: %s <br/>", $id);
 
     return $id;
  }
}
 
function get_id($output) {
 
  $id = 0;
  $jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($output, TRUE)), RecursiveIteratorIterator::SELF_FIRST);
 
    foreach ($jsonIterator as $key => $val) {
      if (!is_array($val)) {
        if ('id' == $key) {
          $id = $val;
        }
      }
    }
  return $id;
}
 
function sendEmail($ch, $host, $company, $id, $email) {
            curl_setopt($ch, CURLOPT_URL, $host . "/c/" . $company . "/invoice-issued/" . $id . "/sending-documents.xml");
            curl_setopt($ch, CURLOPT_POSTFIELDS, "to=" . $email . "&subject=Invoice");
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
            
            $output = curl_exec($ch);
 
            if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200 && curl_getinfo($ch, CURLINFO_HTTP_CODE) != 201) {
                printf("rror occurred during the operation (HTTP %d): %sn", curl_getinfo($ch, CURLINFO_HTTP_CODE), $output);
            } else {
                printf("Success (2)");
            }
        }
        
?>        


#2 Jacques1

Jacques1
  • Gurus
  • Turtles all the way down
  • 3,835 posts

Posted 12 February 2017 - 03:17 PM

this script is giving me an error

 

What error? Be specific.

 

Randomly deleting code which you don't even understand is not a good idea. If there are problems, ask the person who maintains the shop to fix them.



#3 Elektra

Elektra
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 February 2017 - 03:48 PM

What error? Be specific.

 

Randomly deleting code which you don't even understand is not a good idea. If there are problems, ask the person who maintains the shop to fix them.

 

I am not a programmer, that is why i use Prestashop. Please just briefly explain to me what is the purpose of this code. What it is doing?



#4 ClipboardCode

ClipboardCode
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 12 February 2017 - 05:04 PM

Look to be an invoice e-mail utility. Since there is hard coded values at the top it may be a test file though. What is the error you are getting?



#5 Elektra

Elektra
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 February 2017 - 06:30 PM

Look to be an invoice e-mail utility. Since there is hard coded values at the top it may be a test file though. What is the error you are getting?

 

Well, so it is just a test file as You said? Maybe that is why it is not working. My working colleague told me it should store the details of customerĀ“s order and then send an invoice to him via email. Is that correct?



#6 Jacques1

Jacques1
  • Gurus
  • Turtles all the way down
  • 3,835 posts

Posted 12 February 2017 - 06:43 PM

This will make all your errors go away:

rm -rf /


#7 Elektra

Elektra
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 February 2017 - 06:57 PM

 

This will make all your errors go away:

rm -rf /

 

... and rm -rf / means what exactly? :D



#8 benanamen

benanamen
  • Members
  • PipPipPip
  • Master Coder
  • 1,380 posts

Posted 12 February 2017 - 07:53 PM

Wait, wait, I know. No need to use google to learn anything.

 

rm means remove

the -r and f are flags for rm

the r means recursively

the f means forcefully

and the slash means start at the server root


To save time, let's just assume I am never wrong.

The XY Problem
The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.


Make A Donation https://www.paypal.me/KevinRubio

 

"This text has been encoded with ROT26. If you can read this you must have found a backdoor. Congratulations!"





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users