Prestashop 退役或数量增加时出现ajax错误

问题描述 投票:0回答:2

我的大问题是,当我选择产品版本或更新数量时,我遇到 ajax 错误“查看控制台中的控制台,查询 ajax 的 url 参数令牌、id_product 和 id_customization 是重复的,如下所示:

https://xeof.com/index.php?controller=product?token=64c9f388aad0883a78f350addff907a8&id_product=81&id_customization=0&group%5B19%5D=291&qty=2&token=64c9f388aad0883a78f350addff907a8&id_product =119&id_customization=0&token=64c9f388aad0883a78f350addff907a8&id_product=74&id_customization=0

但这并不是 php 错误日志中的全部内容我有这个错误:

Undefined variable: find_best in G: \ Dropbox \ Sites \ xeof.com \ classes \ Product.php on line 6103

类中调用方法是这样的:

/**
 * Get an id_product_attribute by an id_product and one or more
 * id_attribute.
 *
 * e.g: id_product 8 with id_attribute 4 (size medium) and
 * id_attribute 5 (color blue) returns id_product_attribute 9 which
 * is the dress size medium and color blue.
 *
 * @param int $idProduct
 * @param int|int[] $idAttributes
 * @param bool $findBest
 * @return int
 * @throws PrestaShopException
 */
public static function getIdProductAttributeByIdAttributes($idProduct, $idAttributes, $findBest = false)
{
    $idProduct = (int) $idProduct;
    if (!is_array($idAttributes) && is_numeric($idAttributes)) {
        $idAttributes = array((int) $idAttributes);
    }
    if (!is_array($idAttributes) || empty($idAttributes)) {
        throw new PrestaShopException(sprintf('Invalid parameter $idAttributes with value: "%s"', print_r($idAttributes, true)));
    }
    $idAttributesImploded = implode(',', array_map('intval', $idAttributes));
    $idProductAttribute =  Db::getInstance()->getValue('
        SELECT 
            pac.`id_product_attribute`
        FROM 
            `' . _DB_PREFIX_ . 'product_attribute_combination` pac
            INNER JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON pa.id_product_attribute = pac.id_product_attribute
        WHERE 
            pa.id_product = ' . $idProduct . '
            AND pac.id_attribute IN (' . $idAttributesImploded . ')
        GROUP BY 
            pac.`id_product_attribute`
        HAVING 
            COUNT(pa.id_product) = ' . count($idAttributes)
    );
    if ($idProductAttribute === false && $findBest) {
        //find the best possible combination
        //first we order $idAttributes by the group position
        $orderred = array();
        $result = Db::getInstance()->executeS('
            SELECT 
                a.`id_attribute`
            FROM 
                `'._DB_PREFIX_.'attribute` a
                INNER JOIN `'._DB_PREFIX_.'attribute_group` g ON a.`id_attribute_group` = g.`id_attribute_group`
            WHERE 
                a.`id_attribute` IN (' . $idAttributesImploded . ')
            ORDER BY 
                g.`position` ASC'
        );
        foreach ($result as $row) {
            $orderred[] = $row['id_attribute'];
        }
        while ($idProductAttribute === false && count($orderred) > 0) {
            array_pop($orderred);
            $idProductAttribute =  Db::getInstance()->getValue('
                SELECT 
                    pac.`id_product_attribute`
                FROM 
                    `'._DB_PREFIX_.'product_attribute_combination` pac
                    INNER JOIN `'._DB_PREFIX_.'product_attribute` pa ON pa.id_product_attribute = pac.id_product_attribute
                WHERE 
                    pa.id_product = '.(int)$idProduct.'
                    AND pac.id_attribute IN ('.implode(',', array_map('intval', $orderred)).')
                GROUP BY 
                    pac.id_product_attribute
                HAVING 
                    COUNT(pa.id_product) = '.count($orderred)
            );
        }
    }
    if (empty($idProductAttribute)) {
        throw new PrestaShopObjectNotFoundException('Can not retrieve the id_product_attribute');
    }
    return $idProductAttribute;
}

我在第 6103 行替换了如下变量: 之前:

if ($idProductAttribute === false && $find_best)

之后:

if ($ idProductAttribute === false && $ findBest) 

但不幸的是,我有一个例外:

Can not retrieve the id_product_attribute at line 6143 in file classes / Product.php

我没有找到解决方案!

我注意到,当我更改经典主题而不必更改 php 代码时,这些设置不重复,并且我没有其他 php 错误。

php prestashop prestashop-1.7
2个回答
0
投票

更改此:

if ($ idProductAttribute === false && $ findBest) 

至:

$findBest = true;

if ($ idProductAttribute === false && $ findBest) 

0
投票

在 Prestashop 1.7.4 上我添加了这个 override/classes/Products.php 文件以解决 AJAX 调用期间的错误

<?php 
class Product extends ProductCore {


    public static function getIdProductAttributeByIdAttributes($idProduct, $idAttributes, $findBest = true)
    {
        return parent::getIdProductAttributeByIdAttributes($idProduct, $idAttributes, $findBest);
    }
    /**
     * @deprecated 1.7.3.1
     * @see Product::getIdProductAttributeByIdAttributes()
     */
    public static function getIdProductAttributesByIdAttributes($id_product, $id_attributes, $find_best = true)
    {
        return self::getIdProductAttributeByIdAttributes($id_product, $id_attributes, $find_best);
    }
}

现在组合可以正常工作了

© www.soinside.com 2019 - 2024. All rights reserved.