Jump to content

Force ID for Product on backend creation


Recommended Posts

Hi!

 

I have been looking at the code on Product.php, AdminProductsController.php but I can't find the way to override the saving function to manually assign an id_product on manually creating a product from the backend (without CSV importing it).

Obviously id_product field on ps_product needs to be set autoincrement = off, but when I try to save the product, it saves with id_product = 0 (I already modified the adminproduct template to show the id_product on a exiting product {$product->id}).

 

Anyone can point me in the right direction? I think it wont be that difficult but i can't find there exactly the product is written on the database when click on save.

 

Thanks & Best Regards.

 

Link to comment
Share on other sites

it's not possible, it will affect database consistency (not at the begining but i bet that in the future)

 

you can define id of product in add() function in Product.php class

just add there something like $this->id_product=X;

Link to comment
Share on other sites

  • 4 years later...

 

On 7/4/2014 at 2:25 PM, vekia said:

it's not possible, it will affect database consistency (not at the begining but i bet that in the future)

 

you can define id of product in add() function in Product.php class

just add there something like $this->id_product=X;

Hello.

I know it has been long since this topic was created but I am facing this doubt with PS 1.7.5.

I'm trying to create products via php file, with this code

<?php

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');
include(dirname(__FILE__).'/classes/Product.php';

$default_lang = Configuration::get('PS_LANG_DEFAULT');
 
$product = new Product();
$product->name = [$default_lang => 'Test'];
 
$product->add()

?>

and the product is created with no problem and its ID is sequencial, as it should be.

But I need to define its ID, in this code. I have tried $this->id_product=X but, for some reason I don't know, maybe put on the wrong local of the code, it didn't work.

@vekia could you be more specific where could I include this code?

Thank you for your time.

Link to comment
Share on other sites

  • 1 year later...

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...