Home > Blockchain >  Prestashop - Field 'quantity' is deprecated
Prestashop - Field 'quantity' is deprecated

Time:06-07

I need to display the quantity but when I implement it, it tells me that the field is obsolete, I do not understand the error

My code :

$id_lang = (int)Context::getContext()->language->id;
$start = 0;
$limit = 100;
$order_by = 'id_product';
$order_way = 'DESC';
$all_products = Product::getProducts($id_lang, $start, $limit, $order_by, $order_way);
foreach ($all_products as $products) {
    $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('product', 'product');
    $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('id', 'id');
    $this->output .= $products['id_product'];
    $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('id', '/id');
    $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('id_category_default ', 'id_category_default ');
    $this->output .= $products['id_category_default'];
    $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('id_category_default ', '/id_category_default ');
    $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('name', 'name');
    $this->output .= $products['name'];
    $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('name', '/name');
    $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('price', 'price');
    $this->output .= $products['price'];
    $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('price', '/price');
    $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('description', 'description');
    $this->output .= $products['description'];
    $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('description', '/description');
    $this->output .= $this->objOutput->getObjectRender()->renderNodeHeader('quantity', 'quantity');
    $this->output .= $products['quantity'];
    $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('quantity', '/quantity');
    $this->output .= $this->objOutput->getObjectRender()->renderNodeFooter('product', '/product');
}

Thank you for helping me

CodePudding user response:

Quantity field in product had been deprecated from long time, in order to retrieve product stock you should use the static method :

StockAvailable::getQuantityAvailableByProduct($idProduct, $idProductAttribute));
  • Related