Jump to content

Edit History

german

german

First of all, sorry if I'm not posting in the right place, I'm quite new when it comes to this developing world. 

The truth is that I'm a beginner (very) programmer and I got a job for a local business. I chose to develop their website on prestashop (1.7.4.2, and I'm doing somehow ok, even without understanding the guts of it. 

The reason I'm posting is that in Pages I have built a gallery where products are shown, using a php that gets the info from the database. Since the web is hosted on 1&1 (there are certain things that the owner wants this way) I had to change from php 5.6 to 7.2 since it has no longer support from them. After the change the code I built is no longer giving result. The rest of the website works without apparent problem, but just the code I built is not working. I tested it on online services that check the code and again, apparently, it shows no problem. So I need some community-human based help and I'm too inexperienced yet to know what to do in this case. 

 

I found that the object producto I'm instantiating from the class below is not being created. It happens just in 7.2

 

I paste you here the code from the php:

 

<?php

class producto implements JsonSerializable
{
    private $precio;
    private $nombre;
    private $imagen;

    /**
     * @return mixed
     */
    public function getPrecio()
    {
        return $this->precio;
    }

    /**
     * @param mixed $precio
     */
    public function setPrecio($precio)
    {
        $this->precio = $precio;
    }

    /**
     * @return mixed
     */
    public function getNombre()
    {
        return $this->nombre;
    }

    /**
     * @param mixed $nombre
     */
    public function setNombre($nombre)
    {
        $this->nombre = $nombre;
    }

    /**
     * @return mixed
     */
    public function getImagen()
    {
        return $this->imagen;
    }

    /**
     * @param mixed $imagen
     */
    public function setImagen($imagen)
    {
        $this->imagen = $imagen;
    }

    /**
     * @return mixed
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * @param mixed $url
     */
    public function setUrl($url)
    {
        $this->url = $url;
    }
    private $url;


    public function __construct($nombre,$precio,$imagen,$url)
    {
        $this->precio = $precio;
        $this->nombre = $nombre;
        $this->imagen = $imagen;
        $this->url = $url;
    }

    public function jsonSerialize()
    { return[
        'nombre'=>$this->nombre,
        'precio'=>$this->precio,
        'imagen'=>$this->imagen,
        'url'=>$this->url,
    ];
    }
}

 

german

german

First of all, sorry if I'm not posting in the right place, I'm quite new when it comes to this developing world. 

The truth is that I'm a beginner (very) programmer and I got a job for a local business. I chose to develop their website on prestashop (1.7.4.2, and I'm doing somehow ok, even without understanding the guts of it. 

The reason I'm posting is that in Pages I have built a gallery where products are shown, using a php that gets the info from the database. Since the web is hosted on 1&1 (there are certain things that the owner wants this way) I had to change from php 5.6 to 7.2 since it has no longer support from them. After the change the code I built is no longer giving result. The rest of the website works without apparent problem, but just the code I built is not working. I tested it on online services that check the code and again, apparently, it shows no problem. So I need some community-human based help and I'm too inexperienced yet to know what to do in this case. 

 

I found that the object producto I'm instantiating from the class below is not being created. It happens just in 7.2

 

I paste you here the code from the php:

 

<?php
/**
 * Created by IntelliJ IDEA.
 * User: Mario
 * Date: 15/03/2018
 * Time: 8:17
 */

class producto implements JsonSerializable
{
    private $precio;
    private $nombre;
    private $imagen;

    /**
     * @return mixed
     */
    public function getPrecio()
    {
        return $this->precio;
    }

    /**
     * @param mixed $precio
     */
    public function setPrecio($precio)
    {
        $this->precio = $precio;
    }

    /**
     * @return mixed
     */
    public function getNombre()
    {
        return $this->nombre;
    }

    /**
     * @param mixed $nombre
     */
    public function setNombre($nombre)
    {
        $this->nombre = $nombre;
    }

    /**
     * @return mixed
     */
    public function getImagen()
    {
        return $this->imagen;
    }

    /**
     * @param mixed $imagen
     */
    public function setImagen($imagen)
    {
        $this->imagen = $imagen;
    }

    /**
     * @return mixed
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * @param mixed $url
     */
    public function setUrl($url)
    {
        $this->url = $url;
    }
    private $url;


    public function __construct($nombre,$precio,$imagen,$url)
    {
        $this->precio = $precio;
        $this->nombre = $nombre;
        $this->imagen = $imagen;
        $this->url = $url;
    }

    public function jsonSerialize()
    { return[
        'nombre'=>$this->nombre,
        'precio'=>$this->precio,
        'imagen'=>$this->imagen,
        'url'=>$this->url,
    ];
    }
}

 

german

german

First of all, sorry if I'm not posting in the right place, I'm quite new when it comes to this developing world. 

The truth is that I'm a beginner (very) programmer and I got a job for a local business. I chose to develop their website on prestashop (1.7.4.2, and I'm doing somehow ok, even without understanding the guts of it. 

The reason I'm posting is that in Pages I have built a gallery where products are shown, using a php that gets the info from the database. Since the web is hosted on 1&1 (there are certain things that the owner wants this way) I had to change from php 5.6 to 7.2 since it has no longer support from them. After the change the code I built is no longer giving result. The rest of the website works without apparent problem, but just the code I built is not working. I tested it on online services that check the code and again, apparently, it shows no problem. So I need some community-human based help and I'm too inexperienced yet to know what to do in this case. 

 

I paste you here the code from the php:

 

<?php 
require_once dirname($_SERVER['DOCUMENT_ROOT']) . '/new/config/config.inc.php';
require_once dirname($_SERVER['DOCUMENT_ROOT']) . '/new/init.php';
require 'producto.php';
require 'Conjunto.php';
$array_referencias = json_decode(stripslashes($_POST['seleccionProductos']));
$imagenes_principales = [
    "https://germanmedina.es/themes/MegaShop/assets/img/expvec/jardin.jpg",
    "https://germanmedina.es/themes/MegaShop/assets/img/expvec/ceramicas1.jpg"
];
$host_name = 'host';
$database = 'db';
$user_name = 'user';
$password = 'pass';

$conn = new mysqli($host_name, $user_name, $password, $database);
if ($conn->connect_error) {
    die("Se ha producido un error de conexión SQL: " . $conn->connect_error);
}
$id_got = array();
$x = 0;
while ($array_referencias[$x] != null) {
    $y = 0;
    while ($array_referencias[$x][$y] != null) {
        $current_ref = "";
        $stmt = $conn->prepare("SELECT p.id_product FROM ps_product p where p.reference = ?");
        $stmt->bind_param('i',$current_ref);
        $current_ref= $array_referencias[$x][$y];
        $stmt->execute();
        $resultados = $stmt->get_result();
       while ($row = $resultados->fetch_assoc()) {
            $id_got[$x][$y] = $row['id_product'];
        }

//        $sql = mysqli_query($conn, "SELECT p.id_product FROM ps_product p where p.reference = '$current_ref'");
        $y++;
        $stmt->close();
    }
    $x++;
}
$conn->close();
$conjuntos = array();
$n = 0;
while ($id_got[$n] != null) {
    $o = 0;
    $unidad_prod = array();
    while ($id_got[$n][$o] != null) {
        $id_a_usar = $id_got[$n][$o];
        $id_lang = Context::getContext()->language->id;
        $product = new Product($id_a_usar, false, $id_lang);
        $img = $product->getCover($product->id);
        $image_type = 'small_default'; //Mirar el ftp para ver otros tipos
        $producto = new producto();
        $producto->setNombre(strtoupper($product->name));
        $producto->setPrecio($product->price);
        $producto->setImagen($link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int)$img['id_image'], $image_type));
        $producto->setUrl(Context::getContext()->link->getProductLink($id_a_usar));
        $unidad_prod[] = $producto;
        $o++;
    }
    $conjunto = new Conjunto();
    $conjunto->setImagenprincipal($imagenes_principales[$n]);
    $conjunto->setProductos($unidad_prod);
    $conjuntos[] = $conjunto;
    $n++;
}
$res = json_encode($conjuntos);
echo $res;

 

×
×
  • Create New...