MAGENTO:我如何导出sku,数量和价格?

时间:2012-12-06 11:42:00

标签: mysql magento

我想导出所有产品。 我用这个函数得到了所有的skus。

function _getConnection($type = 'core_read') {
    return Mage::getSingleton('core/resource')->getConnection($type);
}

function _getTableName($tableName) {
    return Mage::getSingleton('core/resource')->getTableName($tableName);
}
function _getSku() {
    $connection = _getConnection('core_read');
    $sql = "SELECT sku
                FROM " . _getTableName('catalog_product_entity') . "";
    return $connection->fetchAll($sql);
}

/* * ************* CREATE FILE CSV ************************* */
$_skus = _getSku();
foreach ($_skus as $_sku) {
    $string = $_sku['sku'] . "\n";
    file_put_contents($file, $string, FILE_APPEND);
}

如何更改查询以便我导出SKU,QTY和PRICE?

1 个答案:

答案 0 :(得分:4)

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('price');

foreach($productCollection as $product) {
    $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
    $string = $product->getSku() . " - " . $product->getPrice() . " - " . $stockItem->getQty()  . "\n";
    file_put_contents($file, $string, FILE_APPEND);
}
相关问题