rippergr Posted December 22, 2011 Share Posted December 22, 2011 Hello all I am triyng to get all products from virtuemart and export them as xml I am stuck in the part that I must export all the path of the category. The category should be returning in function GetCategoryPath($product_id) in the code that I will give below. Instead I have an error Fatal error: Class 'JFactory' not found in C:\wamp\www\xml.php on line 71 I took this code from another script that does this job but I can use it function GetCategoryPath($product_id) { $db = JFactory::getDBO(); $result = mysql_query("SELECT #__vm_product.product_id, #__vm_product.product_parent_id, category_name,#__vm_category_xref.category_parent_id " ."FROM #__vm_category, #__vm_product, #__vm_product_category_xref,#__vm_category_xref " ."WHERE #__vm_product.product_id='".$product_id."' " ."AND #__vm_category_xref.category_child_id=#__vm_category.category_id " ."AND #__vm_category_xref.category_child_id = #__vm_product_category_xref.category_id " ."AND #__vm_product.product_id = #__vm_product_category_xref.product_id"); $db->setQuery($q); $rows = $db->loadObjectList(); echo $result; $k = 1; $category_path = ""; foreach ($rows as $row) { $category_name = Array(); /** Check for product or item **/ if ( $row->category_name ) { $category_parent_id = $row->category_parent_id; $category_name[] = $row->category_name; } else { /** must be an item * So let's search for the category path of the * parent product **/ $q = "SELECT product_parent_id FROM #__vm_product WHERE product_id='".$product_id."'"; $db->setQuery($q); $ppi = $db->loadResult(); $q = "SELECT #__vm_product.product_id, #__vm_product.product_parent_id, category_name,#__vm_category_xref.category_parent_id " ."FROM #__vm_category, #__vm_product, #__vm_product_category_xref,#__vm_category_xref " ."WHERE #__vm_product.product_id='".$ppi."' " ."AND #__vm_category_xref.category_child_id=#__vm_category.category_id " ."AND #__vm_category_xref.category_child_id = #__vm_product_category_xref.category_id " ."AND #__vm_product.product_id = #__vm_product_category_xref.product_id"; $db->setQuery($q); $cat_details = $db->loadObject(); $category_parent_id = $cat_details->category_parent_id; $category_name[] = $cat_details->category_name; } if( $category_parent_id == "") $category_parent_id = "0"; while ($category_parent_id != "0") { $q = "SELECT category_name, category_parent_id " ."FROM #__vm_category, #__vm_category_xref " ."WHERE #__vm_category_xref.category_child_id=#__vm_category.category_id " ."AND #__vm_category.category_id='".$category_parent_id."'"; $db->setQuery($q); $cat_details = $db->loadObject(); $category_parent_id = $cat_details->category_parent_id; $category_name[] = $cat_details->category_name; } if ( sizeof( $category_name ) > 1 ) { for ($i = sizeof($category_name)-1; $i >= 0; $i--) { $category_path .= $category_name[$i]; if( $i >= 1) $category_path .= "/"; } } else $category_path .= $category_name[0]; if( $k++ < sizeof($rows) ) $category_path .= "|"; } return $category_path; } GetCategoryPath('2'); /** * Creates the category path */ function CreateCategoryPath() { $db = JFactory::getDBO(); $catpaths = array(); while (JRequest::getVar('catid') > 0) { $q = "SELECT category_parent_id, category_name FROM #__vm_category_xref x, #__vm_category c WHERE x.category_child_id = c.category_id AND category_child_id = ".JRequest::getVar('catid'); $db->setQuery($q); $path = $db->loadObject(); $catpaths[] = $path->category_name; JRequest::setVar('catid', $path->category_parent_id); } $catpaths = array_reverse($catpaths); $catpath = ''; foreach ($catpaths as $id => $catname) { $catpath .= $catname."/"; } return $catpath = substr($catpath, 0, -1); } If someone could give me a little help I would appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/253683-newbie-to-php-coding-need-help/ Share on other sites More sharing options...
trq Posted December 22, 2011 Share Posted December 22, 2011 You might want to let us know what application it is your actually using. Quote Link to comment https://forums.phpfreaks.com/topic/253683-newbie-to-php-coding-need-help/#findComment-1300652 Share on other sites More sharing options...
rippergr Posted December 23, 2011 Author Share Posted December 23, 2011 What do you mean what application I am using? If you mean what application is running is joomla and the tables I am trying to get is from virtuemart. both are using mysql Quote Link to comment https://forums.phpfreaks.com/topic/253683-newbie-to-php-coding-need-help/#findComment-1300793 Share on other sites More sharing options...
trq Posted December 23, 2011 Share Posted December 23, 2011 You posted your question in the "PHP Applications" board. Hence, you need to tell people what application it is your working with so that people who have worked with said application can offer to help. Quote Link to comment https://forums.phpfreaks.com/topic/253683-newbie-to-php-coding-need-help/#findComment-1300804 Share on other sites More sharing options...
rippergr Posted December 27, 2011 Author Share Posted December 27, 2011 I am using wamp and mysql . I am writing code with simple editor and the data I wan tis from virtuemart tables in joomla. Quote Link to comment https://forums.phpfreaks.com/topic/253683-newbie-to-php-coding-need-help/#findComment-1301546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.