News:

Support the VirtueMart project and become a member

Main Menu

Custom fields childs are not shown

Started by Gruz, March 21, 2012, 16:55:29 PM

Previous topic - Next topic

Gruz

J 2.5.3
VM SVN, 2.0.3.E

When I add a parent custom field and a subparent custom fields - the subparent fields are never shown.


I have tree of custom fields like this:

  • Test parent top level [type P]



    • Test editor [type X]


    • Test subparent [type P]



      • Test string in subparent  [type S]




    When trying to add the fields group I cannot finde my subparents:



    This is because the SQL query doesn't include them here:
    administrator/components/com_virtuemart/views/product/view.json.php

    So here is my solution patch:

Index: .
===================================================================
--- . (revision 5696)
+++ . (working copy)
@@ -79,14 +79,18 @@
{
$fieldTypes= $this->model->getField_types() ;

+ //get top parent element
$query = "SELECT *,custom_value as value FROM #__virtuemart_customs
- WHERE (`virtuemart_custom_id`=".$id." or `custom_parent_id`=".$id.")";
- $query .=" order by custom_parent_id asc";
+ WHERE `virtuemart_custom_id`=".$id;
+ $query .=" order by ordering, custom_parent_id asc";
$this->db->setQuery($query);
- $rows = $this->db->loadObjectlist();
+ $this->rows = $this->db->loadObjectlist();
+ if ($this->rows[0]->field_type == 'P') {
+ $this->getChildCustomfieldList($id);
+ }

$html = array ();
- foreach ($rows as $field) {
+ foreach ($this->rows as $field) {
if ($field->field_type =='C' ){
$this->json['table'] = 'childs';
$q='SELECT `virtuemart_product_id` FROM `#__virtuemart_products` WHERE `published`=1
@@ -191,5 +195,28 @@
}
}

+ /**
+ * Gets the list of custom field childs and subchilds, full tree
+ *
+ * @author Gruz <arygroup@gmail.com>
+ *
+ * @param integer $id The parent fields ID
+ * @return void
+ */
+ function getChildCustomfieldList ($id) {
+ $query = "SELECT *,custom_value as value FROM #__virtuemart_customs
+ WHERE `custom_parent_id`=".$id;
+ $query .=" order by ordering, custom_parent_id asc";
+ $this->db->setQuery($query);
+ $rows = $this->db->loadObjectlist();
+ $this->rows = (object) array_merge((array)$this->rows,(array)$rows);
+ foreach ($rows as $row) {
+ if ($row->field_type == 'P')  {
+ $this->getChildCustomfieldList($row->virtuemart_custom_id);
+ }
+ }
+ }
+
+
}
// pure php no closing tag

http://paste.opensuse.org/11021488

I've add a fuction which recoursively looks for the child fields.

Result illustration:


Please, let me know if this bug is going to be solved. I can't use custom fields because of this one and this http://forum.virtuemart.net/index.php?topic=99847.0
And there is no reaction from the dev team, if they consider this is a problem.

Thanks.
Your installable language for VM2: http://gruz.org.ua/virtuemart-language-files.html

Studio 42

Sorry Gruz,
But we have all 3 main members the Joomla day in france and can not add and look for it this week.
The parent was only here to "group" and set the custom in parent in one time in product and for searching in FE.
But be sure we look all suggestion and try to add it if this fith with the general usability of Virtuemart.

Gruz

The other problem connected with this one is that fields cannot have the same names. It's not ok, when I want to have the same names in different custom field groups.

I.e. I have "Subwoofer description" and "Satellite description" groups and both need to have  a  Power field in both groups.

Your installable language for VM2: http://gruz.org.ua/virtuemart-language-files.html