Jump to content

php warning on product page. prestashop 8.2 php 8.1


vincent

Recommended Posts

Does anyone know about this bug? and any fix?

 

PHP Warning: Undefined array key "cart_quantity" in /public_html/controllers/front/ProductController.php on line 1329

 

    /**
     * @param array $product
     *
     * @return int
     */
    protected function getRequiredQuantity($product)
    {
        $requiredQuantity = (int) Tools::getValue('quantity_wanted', $this->getProductMinimalQuantity($product));
        if ($requiredQuantity < $product['minimal_quantity']) {
            $requiredQuantity = $product['minimal_quantity'];
        }

        if ($product['cart_quantity'] >= $requiredQuantity) {
            return 0;
        }

        return $requiredQuantity;

Link to comment
Share on other sites

  • 5 months later...

Hola, tengo el mismo error al ingresar a la hoja de producto, aunque desactivo debug, sigue apareciendo, lo pudiste resolver?

On 12/19/2024 at 5:11 PM, vincent said:

Does anyone know about this bug? and any fix?

 

PHP Warning: Undefined array key "cart_quantity" in /public_html/controllers/front/ProductController.php on line 1329

 

    /**
     * @param array $product
     *
     * @return int
     */
    protected function getRequiredQuantity($product)
    {
        $requiredQuantity = (int) Tools::getValue('quantity_wanted', $this->getProductMinimalQuantity($product));
        if ($requiredQuantity < $product['minimal_quantity']) {
            $requiredQuantity = $product['minimal_quantity'];
        }

        if ($product['cart_quantity'] >= $requiredQuantity) {
            return 0;
        }

        return $requiredQuantity;

 

Link to comment
Share on other sites

  • 2 months later...

1) У getTemplateVarProduct() (прибл. рядок ~1211) замініть пряме звернення до масиву з результату getProductQuantity(...) на безпечне присвоєння:

// було (спрощено):
$product['cart_quantity'] = $this->context->cart->getProductQuantity(
    (int) $product['id_product'],
    (int) $product['id_product_attribute']
)['quantity'];

// стало (безпечний варіант):
$qtyInfo = $this->context->cart
    ? $this->context->cart->getProductQuantity(
        (int) $product['id_product'],
        (int) $product['id_product_attribute']
      )
    : null;
$product['cart_quantity'] = isset($qtyInfo['quantity']) ? (int)$qtyInfo['quantity'] : 0;

2) У displayAjaxRefresh() (прибл. рядок ~514) підстрахуйте умову:
 

// було:
if ($product['cart_quantity'] >= $minimalProductQuantity) {

// стало:
if ((int)($product['cart_quantity'] ?? 0) >= $minimalProductQuantity) {

3) У getRequiredQuantity() (рядок 1333) теж додайте дефолт:
 

// було:
if ($product['cart_quantity'] >= $requiredQuantity) {

// стало:
if ((int)($product['cart_quantity'] ?? 0) >= $requiredQuantity) {

 

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