如何导出产品csv与完整的产品网址 [英] How to export product csv with full url of product

查看:437
本文介绍了如何导出产品csv与完整的产品网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要汇出含完整产品网址的产品CSV,包括基本网址(我不想手动执行)。

I want to export a product CSV with full product url i.e including base url (I don't want to do it manually).

代码,以便产品导出具有完整的URL?

Is it possible to customize the code so that the product export has the full url?

推荐答案

<?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>";
}


?>

这篇关于如何导出产品csv与完整的产品网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆