我的最大问题是,当我选择产品的版本或更新数量时,我遇到了一个错误的ajax“在控制台中的控制台上,查询ajax的网址中参数令牌,id_product和id_customization都像这样重复:
但这不是日志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行中替换了这样的变量: 之前:
如果($ 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错误。
答案 0 :(得分:0)
更改此内容:
if ($ idProductAttribute === false && $ findBest)
收件人:
$findBest = true;
if ($ idProductAttribute === false && $ findBest)
答案 1 :(得分:0)
在Prestashop 1.7.4上,我添加了这个override / classes / Products.php文件以解决AJAX调用期间的错误
// std::vector<T> being passed to std::bind
std::function<void(std::vector<int>)> funcA = std::bind(foo<int>,a);
myClass.addFunc( funcA );
myClass.caller(0)(a); // Again std::vector<T> being passed but to `std::function`'s operator because the stored function requires this parameter.
现在组合可以正常使用