【问题标题】:Obtain product custom field value in Virtuemart在 Virtuemart 中获取产品自定义字段值
【发布时间】:2012-10-28 02:14:25
【问题描述】:

我正在尝试获取产品自定义字段的值。我只有那个产品的 ID。我知道自定义字段的标题。

如何获取该自定义字段的值?

请帮忙。

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

【问题讨论】:

    标签: joomla2.5 joomla-extensions virtuemart


    【解决方案1】:

    这适用于 VM2.x

    VM 正在 #__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'];
    

    您也可以尝试使用内部子查询。

    【讨论】:

      【解决方案2】:
          $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
          }
      

      【讨论】:

        猜你喜欢
        • 2012-11-14
        • 1970-01-01
        • 1970-01-01
        • 2021-06-24
        • 1970-01-01
        • 1970-01-01
        • 2021-06-11
        • 1970-01-01
        • 2012-04-24
        相关资源
        最近更新 更多