cancel
Showing results for 
Search instead for 
Did you mean: 

Export Category path in xml product catalog Magento 1.9.2

Export Category path in xml product catalog Magento 1.9.2

Hello!

I have the script below for exporting product xml feed for magento 1.9.2 
The problem is that I cannot export the category path for each product

The scipt is:

 

<?php
require 'app/Mage.php';
Mage::app();
$storename = 'default';
$file = "products.xml";
if (file_exists($file)) {
    unlink($file);
}
try {
    $products = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToSelect('*')
        ->setPageSize(20)
        ->setCurPage(1)
        ->setOrder('id', 'ASC')
        ->addAttributeToFilter('status', array('eq' => '1'));
    $doc = new DOMDocument();
    $doc->encoding = 'utf-8';
    $doc->formatOutput = true;
    $root = $doc->createElement("root");
    $doc->appendChild($root);
    $productsX = $doc->createElement("catalog");
    $root->appendChild($productsX);
     foreach ($products as $_product) {
            $product = $doc->createElement("product");
            $id = $doc->createElement("id");
            $id->appendChild(
                $doc->createTextNode($_product->getId())
            );
            $product->appendChild($id);
            $url = $doc->createElement("url");
            $url->appendChild(
                $doc->createTextNode(trim($_product->getData('url_key')))
            );
            $product->appendChild($imageURL);
            $imageURL = $doc->createElement("image");
            $imageURL->appendChild(
                $doc->createTextNode($_product->getImageURL())
            );
            $product->appendChild($url);
            $urlPath = $doc->createElement("url_path");
            $urlPath->appendChild(
                $doc->createTextNode(trim($_product->getProductUrl()))
            );
            $product->appendChild($urlPath);
            $title = $doc->createElement("title");
            $title->appendChild(
                $doc->createTextNode(trim($_product->getName()))
            );
             $product->appendChild($short_description);
            $short_description = $doc->createElement("description");
            $short_description->appendChild(
                $doc->createTextNode(trim($_product->getShort_description()))
            );
            $product->appendChild($title);
            $sku = $doc->createElement("sku");
            $sku->appendChild(
                $doc->createTextNode($_product->getSku())
            );
            $product->appendChild($category);
            $category = $doc->createElement("category");
            $category->appendChild(
                $doc->createTextNode(trim($_product->getCategoryName()))
            );
            $product->appendChild($sku);
            $formatedpriceprice = $doc->createElement("price");
            $formatedpriceprice->appendChild(
                $doc->createTextNode(trim((int)$_product->getFormattedPrice()))
            );
            $product->appendChild($price);
            $formatedprice = $doc->createElement("price_with_vat");
            $formattedPrice = Mage::helper('core')->currency($_product->getPrice(), true, false);
            $formatedprice->appendChild(
                $doc->createTextNode(trim($formattedPrice))
            );
            $product->appendChild($formatedprice);
            $productsX->appendChild($product);
    }
    file_put_contents($file, $doc->saveXML(), FILE_APPEND);
} catch (Exception $e) {
    echo 'Eroror : - ';
    echo $e->getMessage();
}
1 REPLY 1

Re: Export Category path in xml product catalog Magento 1.9.2

Debug the code that, into your script do you get the category path of the product or not.

Co-Founder Of Magecomp.com