Jump to content

Method update on class product


Recommended Posts

Hello, i'm trying to make a very simple script, to update product prices via PHP.

<?php

    include(dirname(__FILE__) . '/config/config.inc.php');
 
    $cod_articulo = 'B39821';
    
    $mysqli = mysqli_connect($localhost, $user, $pass, $database) or die(mysql_error());
    
    function getIdByReference($reference)
    {
        if (empty($reference)) {
            return 0;
        }

        if (!Validate::isReference($reference)) {
            return 0;
        }

        $query = new DbQuery();
        $query->select('p.id_product');
        $query->from('product', 'p');
        $query->where('p.reference = \'' . pSQL($reference) . '\'');

        return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
    }
    
        $id_articulo = getIdByReference($cod_articulo);
        
        echo($id_articulo.'<br/>');
//check

        new Product($product);
        $product->price = '10';
        echo($product->price.'<br/>');
        $product->update();
// line 48
        echo ('Producto con ref: '.$reference.' actualizado a '.$product->price.' euros');
?>

It returns this error

PHP message: PHP Fatal error:  Uncaught Error: Call to undefined method stdClass::update() in [***/testprecio.php:48

Stack trace:\n#0 {main}\n  thrown in [***/testprecio.php on line 48'


PS version 1.7.5.2

Do you know what i'm missing??

Thanks!! have a nice day

Link to comment
Share on other sites

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
×
×
  • Create New...