Prestashop quantity in database is 0 but actual quantities shows in BO

I have a fully mysterious issue with Prestashop 1.7.7.

In database, in ps_product table, all quantities are set to 0. However, in BO, I can see actual quantities.

EDIT: I found the table ps_stock_availabe. Quantities are here. I added this code in my controller:

$champion->loadStockData(); // This is a Product instance.
$chevalier->loadStockData(); // This is a Product instance.
$porter->loadStockData(); // This is a Product instance.
$potions->loadStockData(); // This is a Product instance.
$pepites->loadStockData(); // This is a Product instance.

With no luck.

How could I get stock informations in my product instance in controller please ?

Thanks for your time.

Upvotes: 1

Views: 571

Answers (1)

I found the way to come across my issue.

$champion = new Product(27);
$chevalier = new Product(28);
$porter = new Product(24);
$potions = new Product(25);
$pepites = new Product(26);
$champion->quantity = Product::getQuantity($champion->id); // Get the actual quantity
$chevalier->quantity = Product::getQuantity($chevalier->id);
$porter->quantity = Product::getQuantity($porter->id);
$potions->quantity = Product::getQuantity($potions->id);
$pepites->quantity = Product::getQuantity($pepites->id);
$champion->price = $champion->getPrice(true, null, 2); // Get the actual price with tax
$chevalier->price = $chevalier->getPrice(true, null, 2);
$porter->price = $porter->getPrice(true, null, 2);
$potions->price = $potions->getPrice(true, null, 2);
$pepites->price = $pepites->getPrice(true, null, 2);

Upvotes: 1

Related Questions