cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9 xml feed output

Magento 1.9 xml feed output

Hey!

Got an issue with Magento XML feed output.

All the filters to which products to export have been set but still all of the products on the webshop are exported into the feed.

Any idea what could be wrong?
XML feed output format below.

2 REPLIES 2

Re: Magento 1.9 xml feed output

Hello @thomasanderson_ 

 

You can use the custom script to export the product data like this

https://magento.stackexchange.com/questions/30812/magento-product-feed-extension

 

Or you can use third-party extension to export the product feed.

https://marketplace.magento.com/xtento-16512.html

https://www.xtento.com/magento-extensions/magento-product-feed-export-module.html

 

 

Was my answer helpful? You can accept it as a solution.
200+ Premium Magento 2 Extensions Need help? Hire Magento Developer

Re: Magento 1.9 xml feed output

Hello @thomasanderson_ 

 

Please refer to the following code to export products in XML with specific attributes and filters:

<?php
require 'app/Mage.php';
Mage::app();
$storename = 'default';
$file = "products-top10.xml";
if (file_exists($file)) {
    unlink($file);
}
try {
    $products = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToSelect('*')
        ->setPageSize(200)
        ->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($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($title);
            $sku = $doc->createElement("sku");
            $sku->appendChild(
                $doc->createTextNode($_product->getSku())
            );
            $product->appendChild($sku);
            $price = $doc->createElement("price");
            $price->appendChild(
                $doc->createTextNode(trim((int)$_product->getPrice()))
            );
            $product->appendChild($price);
            $formatedprice = $doc->createElement("formated_price");
            $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();
}

Hope it helps.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"