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.
(http://static.xscreenshot.com/2012/03/21/10/screen_2c1dca8b43345e97d0ec87ea4a892ec4) (http://view.xscreenshot.com/2c1dca8b43345e97d0ec87ea4a892ec4)
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:
(http://static.xscreenshot.com/2012/03/21/10/screen_db5a6cd354e91f21e67c2cc8373e8926) (http://view.xscreenshot.com/db5a6cd354e91f21e67c2cc8373e8926)
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:
(http://static.xscreenshot.com/2012/03/21/17/screen_ca4d6b1c445dc69d56f345bdb2095238) (http://view.xscreenshot.com/ca4d6b1c445dc69d56f345bdb2095238)
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.
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.