![](/img/trans.png)
[英]Magento: Need to get Catalog_Product_Option ID for product options
[英]Get Product Options for each Product in the Catalog in Magento
这是使用Magento 1.9。
我正在尝试构建一个脚本,将目录中每个产品的所有产品选项输出到CSV文件中。
我尝试使用此页上的代码: http : //www.atwix.com/magento/configurable-product-attributes/
对于此代码:
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color');
foreach ($attribute->getSource()->getAllOptions(true) as $option) {
echo $option['value'] . ' ' . $option['label'] . "\n";
}
我什么也没得到。
对于此代码:
$productAttributeOptions = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
$attributeOptions = array();
foreach ($productAttributeOptions as $productAttribute) {
foreach ($productAttribute['values'] as $attribute) {
$attributeOptions[$productAttribute['label']][$attribute['value_index']] = $attribute['store_label'];
}
}
我收到此错误:
Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray() in /home/tws2/public_html/getopts.php on line 71
我无法在互联网上找到其他任何东西来获取带有PHP代码的产品的产品选项。
有人可以向我解释如何使用PHP获取目录中每个产品的所有产品选项数据,因此我可以将所有这些数据输出到CSV文件中。
这样做的目的是将产品选件数据转移到具有相同目录的相同Magento服务器中,只是缺少产品选件数据。 获得所有产品选项的CSV文件后,我将制作另一个脚本以将它们写入相同的Magento服务器。 建议我在内部执行此任务,如果您有更好的建议,请告诉我。
要获取整个目录的可配置选项,请尝试以下操作
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($collection as $product) {
foreach ($product->getProductOptionsCollection() as $o) {
$values = $o->getValues();
foreach ($values as $v) {
$v['product_id'] = $product->getEntityId();
echo "<pre>";print_r($v->getData());
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.