我需要获取Prestahop商店中存在的所有属性,无论是什么或分配了什么产品我只想生成这些属性的数组,然后在ProductController.php类中使用它们。我检查文件类/ Product.php,并且存在一个名为getDefaultAttribute($ id_product,$ minimumQuantity = 0)的方法,但我认为这仅适用于分配给特定产品的属性,而不是根据需要全部返回。有帮助吗?我是Prestashop的新手,需要学习很多东西
答案 0 :(得分:4)
检查文件classes/Attribute.php
。您可以使用静态函数Attribute::getAttributes($id_lang, $not_null = false)
。它返回给定语言的所有属性。
答案 1 :(得分:0)
您可以使用此SQL查询获取所有属性:
$atbt = "SELECT a.id_attribute_group , a.name
FROM " . _DB_PREFIX_ . "attribute_group_lang a
where id_lang='".$id_lang."'";
$res = Db::getInstance()->ExecuteS($atbt);
$product_result = array();
$i=0;
foreach ($res as $key => $row) {
$sql = 'SELECT pal.name AS label,pal.id_attribute AS value,0 AS status'
. ' FROM ' . _DB_PREFIX_ . 'attribute AS pa
RIGHT JOIN ' . _DB_PREFIX_ . 'attribute_group_lang AS pagl ON (pagl.id_attribute_group =pa.id_attribute_group)
LEFT JOIN ' . _DB_PREFIX_ . 'attribute_lang AS pal ON (pal.id_attribute =pa.id_attribute)
JOIN ' . _DB_PREFIX_ . 'product_attribute_combination AS pacl ON (pacl.id_attribute =pal.id_attribute)
JOIN ' . _DB_PREFIX_ . 'product_attribute AS pat ON (pat.id_product_attribute =pacl.id_product_attribute)
JOIN ' . _DB_PREFIX_ . 'product AS prot ON (prot.id_product =pat.id_product)
WHERE pagl.id_lang="'.$id_lang.'" AND pal.id_lang="'.$id_lang.'" AND pagl.id_attribute_group=' . $row['id_attribute_group'].' AND prot.id_category_default = "'.$id_category.'" GROUP BY pacl.id_attribute';
$result = Db::getInstance()->ExecuteS($sql);
}