2013-02-14 56 views
2

我想導出產品CSV與完整的產品網址,即包括基地址(我不想手動)。如何導出產品csv與完整的產品網址

是否可以自定義代碼以使產品導出具有完整的網址?

+2

在谷歌第一個結果 - > http://t3jsot.blogspot.co.uk/2011/08/magento-export-products-with-full-urls.html – McNab 2013-02-14 14:00:16

回答

4
<?php 

// Load the Magento core 

require_once 'app/Mage.php'; 
umask(0); 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
$userModel = Mage::getModel('admin/user'); 
$userModel->setUserId(0); 

// Load the product collection 

$collection = Mage::getModel('catalog/product') 
->getCollection() 
->addAttributeToSelect('*') //Select everything from the table 
->addUrlRewrite(); //Generate nice URLs 

/* 
For this example I am generating a CSV file, 
but you can change this to suit your needs. 
*/ 

echo "title,sku,id,url\n" ."<br>"; 

foreach($collection as $product) { 
//Load the product categories 
$categories = $product->getCategoryIds(); 
//Select the last category in the list 
$categoryId = end($categories); 
//Load that category 
$category = Mage::getModel('catalog/category')->load($categoryId); 

echo '"'.$product->getTitle().'","'. 
    $product->getSku().'",'. 
    $product->getId().',"'. 
    //This will the proper URL, the base url is optional, though make sure you remove the trailing export.php (or whatever you name this file) 
    str_replace('export.php/','',Mage::getBaseUrl()).$product->getUrlPath($category).'"'. 
    "\n" ."<br>"; 
} 


?> 
+0

我們應該從哪裏寫代碼? – Narayan 2017-10-24 05:03:54

1
Create export.csv on root ..write a code to export csv the new thing is that you have to hardcode base url in the path of the product.. 

for example ..existing path category/product/ 

base url/category/product/ 

But remember to keep the code correct..