Guest Posted September 17, 2018 Share Posted September 17, 2018 Hi, how can I add the entire tree of categories to an XML file as an example: <?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); include('../config/config.inc.php'); include('../config/settings.inc.php'); $shop_name = $_SERVER['HTTP_HOST']; $server = _DB_SERVER_; $name = _DB_NAME_; $user = _DB_USER_; $pass = _DB_PASSWD_; $prefix = _DB_PREFIX_; $xml = ""; $cat_tree = ""; $xml .= '<?xml version="1.0"?>'."\n"; $xml .= '<shop>'."\n"; $sql = 'SELECT c.id_parent, c.id_category, cl.name, clp.name as parent_name, cl.description, cl.link_rewrite,cs.position ,level_depth FROM '._DB_PREFIX_.'category c LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (c.id_category = cl.id_category AND id_lang = 1) LEFT JOIN '._DB_PREFIX_.'category_group cg ON (cg.id_category = c.id_category) LEFT JOIN '._DB_PREFIX_.'category_shop cs ON (c.id_category = cs.id_category) LEFT JOIN '._DB_PREFIX_.'category_lang clp ON (c.id_parent = clp.id_category) WHERE c.id_category > 1 AND cs.id_shop = 1 GROUP BY c.id_category ORDER BY c.id_parent ASC, level_depth ASC;'; $result = Db::getInstance()->executeS($sql); foreach($result as $row) { $id_parent = $row["id_parent"]; $id_category = $row["id_category"]; $category_name = $row["name"]; $category_parent_name = $row["parent_name"]; $category_image = 'http://'.$shop_name.'/img/c/'.$id_category.'.jpg'; $description = $row["description"]; $link_rewrite = $row["link_rewrite"]; $position = $row["position"]; $level_depth = $row["level_depth"]; $cat_tree = // example: Home/Men/T-shirt/long sleeve $xml .= ' <shopitem>'."\n"; $xml .= ' <cat_id>'.$id_category.'</cat_id>'."\n"; $xml .= ' <cat_name>'.$category_name.'</cat_name>'."\n"; $xml .= ' <cat_description>'.$description.'</cat_description>'."\n"; $xml .= ' <cat_image>'.$category_image.'</cat_image>'."\n"; $xml .= ' <cat_parent>'.$id_parent.'</cat_parent>'."\n"; $xml .= ' <cat_parent_name>'.$category_parent_name.'</cat_parent_name>'."\n"; $xml .= ' <cat_tree>'.$cat_tree.'</cat_tree>'."\n"; $xml .= ' <cat_level_depth>'.$level_depth.'</cat_level_depth>'."\n"; $xml .= ' </shopitem>'."\n"; } $xml .= '<shop>'."\n"; file_put_contents('./cat.xml', $xml); ?> Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now