2012-11-07 36 views
3

我正在嘗試獲取產品自定義字段的值。我只有該產品的ID。我知道自定義字段的標題。在Virtuemart中獲取產品自定義字段值

如何獲得該自定義字段的值?

請幫助。

PS:我很瞭解PHP,但我是Joomla/Virtuemart的新手。

回答

-1
$db = JFactory::getDBO(); 
    $query = $db->getQuery(true); 
    $query->select('virtuemart_product_id,custom_value'); 
    $query->from('#__virtuemart_product_customfields'); 
    $db->setQuery((string)$query); 
    $results = $db->loadObjectList(); 
    if ($results){ 
    foreach($results as $result) 
    { 
     // do your stuff here 
    } 
0

這將爲VM2.x

工作

虛擬機存儲在#__virtuemart_customs

產品和自定義字段之間的關係在#__virtuemart_product_customfields維護定製字段值

你有標題和產品ID,所以你可以試試這個

$db = &JFactory::getDBO(); 
$sql = "SELECT F.custom_value #__virtuemart_customs AS C LEFT JOIN #__virtuemart_product_customfields AS F ON F.virtuemart_customfield_id = C.virtuemart_custom_id where (C.custom_title='$your_customtitle' and F.virtuemart_product_id = '$product_id')"; 
$db->setQuery($sql); 
$db->query(); 
$res = $db->loadAssoc(); 
echo $res['custom_value']; 

你也嘗試與內部子查詢。

相關問題