Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Products feeds for multiple store views and websites
 
daparky
Jr. Member
 
Total Posts:  2
Joined:  2009-07-05
 

Hi there,

I’ve done a product data feed for a shop running Magento and i’m having trouble loading a store view or website.

For example:-

There are multiple store views and websites within the one Magento installation and it looks like this:-

-Default Values
--Website 1
---Store view for website 1
--Website 2
---Store view for website 2

Basically the feed keep reading the data from Default Values when i want it to read from a specific store view. The code i’m using is below…

<?php
    define
('SAVE_FEED_LOCATION','all.csv');

    
set_time_limit(0);
    
error_reporting(E_ALL);

    require_once 
'../app/Mage.php';
    
Mage::app('default');
    
        
    
try{
        $handle 
fopen(SAVE_FEED_LOCATION'w');

        
        
$feed_line 'Category,Manufacturer,Title,Description,Product URL,Image URL,SKU,Unique Number,EAN / UPC,Delivery time,Ship Cost,Price,In Stock'."\r\n";
        
fwrite($handle$feed_line);

        
$products Mage::getModel('catalog/product')->getCollection();
        
$products->addAttributeToFilter('status'1);//enabled
        
$products->addAttributeToFilter('visibility'4);//catalog, search
        
$products->addAttributeToFilter('type_id''simple');//simple only (until fix is made)
        
$products->addAttributeToSelect('*');
        
$prodIds=$products->getAllIds();
        
        
        foreach(
$prodIds as $productId)
        
{
            $product 
Mage::getModel('catalog/product');            
            
$product->load($productId);
            
            
$product_data = array();
            
            
$product_data['category''';
            foreach(
$product->getCategoryIds() as $_categoryId)
            
{
                $category 
Mage::getModel('catalog/category')->load($_categoryId);
                
$product_data['category'].=$category->getName().' / ';
            
}
            $product_data[
'category']=rtrim($product_data['category'],' / '); 
            
$product_data['manufacturer'= ($product->getAttributeText('manufacturer') == '' 'Beyond Television' $product->getAttributeText('manufacturer'));
            
$product_data['title''"'.str_replace(',','',str_replace('"','""',$product->getName())).'"';
            
$product_data['description''"'.strip_tags(str_replace(',','',str_replace('"','""',$product->getShortDescription()))).'"';
            
$product_data['link']=$product->getProductUrl();
            
$product_data['image_link']=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();
            
$product_data['sku'$product->getSku();
            
$product_data['model'$product->getSku();
            
$product_data['ean'$product->getEan();
            
$product_data['lead_time''1';
            
$product_data['shipping_costs'0;
            
            echo 
$product->getFormatedPrice().'<br />';
            echo 
$product->getSku().'<br />';
            echo 
$product->getPrice().'<br />';
            echo 
$product->getFinalPrice().'<br />';
            echo 
$product->getSpecialPrice().'<br />';
            exit();

            if(
$product->getSpecialPrice())
            
{
                $product_data[
'price'number_format($product->getSpecialPrice(),2'.''');
            
}
            
else
            
{
                $product_data[
'price'number_format($product->getPrice(),2'.''');
            
}
            
            $product_date[
'price'number_format($product->getFinalPrice(),2,'.','');
            
            
$product_data['in_stock'= ($product->isSalable() ? 'Yes' 'No');


            
//sanitize data    
            
foreach($product_data as $k=>$val){
            $bad
=array("\r\n","\n","\r","\t");
            
$good=array(" "," "," ","");
            
$product_data[$k] str_replace($bad,$good,$val);
            
}
            

            $feed_line 
implode(","$product_data)."\r\n";
            
fwrite($handle$feed_line);
            
fflush($handle);
            
        
}

        
//---------------------- WRITE THE FEED    
        
fclose($handle);
        
        echo 
'<p>All product feed generated succesfully. Download:</p>';
        echo 
'<p><a href="/feeds/all.csv">all.csv</a></p>';
        
        
    
}
    
catch(Exception $e){
        
die($e->getMessage());
    

    
?>

I’ve tried doing this:-

Mage::app(’STORE NAME’);
Mage::app(’WEBSITE NAME’);

Doesn’t have any effect and keeps reading the default values. This is creating a problem because the prices are changing for both stores (websites) so i need to create a feed reading the correct prices and information rather than from default values.

Any help appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
daparky
Jr. Member
 
Total Posts:  2
Joined:  2009-07-05
 

Doesn’t matter now, i’ve solved it smile

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Tweakmag
Guru
 
Avatar
Total Posts:  307
Joined:  2007-08-31
London, UK
 

what was the fix? Always nice to put the solution for others smile

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top