gpt4 book ai didi

mysql - MAGENTO:如何导出 sku、数量和价格?

转载 作者:太空宇宙 更新时间:2023-11-03 11:03:34 25 4
gpt4 key购买 nike

我想导出所有产品。我用这个函数来获取所有的 SKU。

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?

最佳答案

$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);
}

关于mysql - MAGENTO:如何导出 sku、数量和价格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13742876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com