agarmur Posted June 17, 2022 Share Posted June 17, 2022 Hello, I would like to add a carrier in my product, I found $product->setCarriers() but I do not know how to use it, if someone could help me Thanks Link to comment Share on other sites More sharing options...
Ress Posted June 17, 2022 Share Posted June 17, 2022 You must give an array of carrier references (`id_reference` from ps_carrier_table) as a function parameter. Link to comment Share on other sites More sharing options...
agarmur Posted June 17, 2022 Author Share Posted June 17, 2022 à l’instant, Ress a dit : Vous devez donner un tableau de références de transporteur (`id_reference` de ps_carrier_table) comme paramètre de fonction. like this ? $product->setCarriers([1]); Link to comment Share on other sites More sharing options...
Ress Posted June 17, 2022 Share Posted June 17, 2022 Yes. Link to comment Share on other sites More sharing options...
agarmur Posted June 17, 2022 Author Share Posted June 17, 2022 il y a 2 minutes, Ress a dit : Yes. It doesn't work, I have var_dump($product->setCarriers([1])); here is the answer : NULL Link to comment Share on other sites More sharing options...
Mediacom87 Posted June 17, 2022 Share Posted June 17, 2022 il y a 4 minutes, agarmur a dit : It doesn't work, I have var_dump($product->setCarriers([1])); here is the answer : NULL Do you have a carrier with this id_reference? Link to comment Share on other sites More sharing options...
agarmur Posted June 17, 2022 Author Share Posted June 17, 2022 (edited) il y a 8 minutes, Mediacom87 a dit : Do you have a carrier with this id_reference? Yes I have it Edited June 17, 2022 by agarmur (see edit history) Link to comment Share on other sites More sharing options...
Mediacom87 Posted June 17, 2022 Share Posted June 17, 2022 This is id_carrier and not id_reference Link to comment Share on other sites More sharing options...
agarmur Posted June 17, 2022 Author Share Posted June 17, 2022 il y a 2 minutes, Mediacom87 a dit : This is id_carrier and not id_reference Yes I know, but id_reference = id_carrier Link to comment Share on other sites More sharing options...
Mediacom87 Posted June 17, 2022 Share Posted June 17, 2022 il y a 6 minutes, agarmur a dit : Yes I know, but id_reference = id_carrier ok, but only for the first creation before any modifications. And i don't really know if you get any var_dump (prefered Tool::dieObject()) on this function because there is no return. Link to comment Share on other sites More sharing options...
agarmur Posted June 17, 2022 Author Share Posted June 17, 2022 il y a 11 minutes, Mediacom87 a dit : ok, but only for the first creation before any modifications. And i don't really know if you get any var_dump (prefered Tool::dieObject()) on this function because there is no return. effectively, there is no return in the function, but how to test to see if it works well? Link to comment Share on other sites More sharing options...
Tom Girou Posted June 17, 2022 Share Posted June 17, 2022 1 minute ago, agarmur said: effectively, there is no return in the function, but how to test to see if it works well? Just var_dump $product->getCarriers() after setting it. Link to comment Share on other sites More sharing options...
agarmur Posted June 17, 2022 Author Share Posted June 17, 2022 il y a 2 minutes, Tom Girou a dit : Just var_dump $product->getCarriers() after setting it. it works, but my product has no carrier selected 😤 Link to comment Share on other sites More sharing options...
agarmur Posted June 17, 2022 Author Share Posted June 17, 2022 I found a solution even if I don't like it, I run SQL in my php : INSERT INTO `ps_product_carrier` (`id_product`, `id_carrier_reference`, `id_shop`) VALUES ('176', '1', '1'); Link to comment Share on other sites More sharing options...
Tom Girou Posted June 17, 2022 Share Posted June 17, 2022 Just now, agarmur said: I found a solution even if I don't like it, I run SQL in my php : INSERT INTO `ps_product_carrier` (`id_product`, `id_carrier_reference`, `id_shop`) VALUES ('176', '1', '1'); Normally this is what $product->setCarriers() is supposed to do. If you want to debug further, you could var_dump $sql inside classes/db/Db.php at line 471 more or less. You can also debug $unique_array inside classes/Product.php at line 3487 more or less. Link to comment Share on other sites More sharing options...
agarmur Posted June 17, 2022 Author Share Posted June 17, 2022 I look at all this, a big thank you! Link to comment Share on other sites More sharing options...
Mediacom87 Posted June 17, 2022 Share Posted June 17, 2022 If you want to test a method, you have to work on the method and not on the return of it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now