Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/253683-newbie-to-php-coding-need-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.