代替getOptions()
请尝试getCustomOptions()
or getProductOptionsCollection()
or getProductOptionsCollection()->load()
.
Edit
我在一个我知道有选项的产品上尝试过这个。
<?php
require 'app/Mage.php';
Mage::app();
$product = Mage::getModel('catalog/product')->load($productId);
foreach ($product->getProductOptions() as $option) {
print_r($option->debug());
}
并得到这样的东西:
Array
(
[option_id] => 37
[product_id] => 8
[type] => multidate
[is_require] => 1
[sku] =>
[image_size_x] => 0
[image_size_y] => 0
[sort_order] => 1
[default_title] => Dates
[title] => Dates
)
然而,getOptions()
也为我工作,所以我不知道发生了什么事。
后期编辑
混乱是语义之一。一个简单的产品可以有“自定义选项”,它们允许创建一些表单字段,这些字段记录为订单的一部分。可配置产品使用“关联产品”来创建带有条件字段的表单。
例如,您可能销售大号绿色、小号绿色或大号蓝色的袜子,但不销售小号蓝色的袜子。对于一个简单的产品,您将有一个大/小字段和一个蓝色/绿色字段 - 这允许客户选择小蓝色,这是错误的。
因此,要查找可配置的组成部分,您可以执行以下操作:
if ($product->isConfigurable()) {
$configurable = $product->getTypeInstance();
$childProducts = $product->getUsedProducts($product);
foreach ($childProducts as $child) {
// You have a $child now
}
}
找到等价于getOptions()
你需要这个:
if ($product->isConfigurable()) {
$configurable = $product->getTypeInstance();
$attributes = $configurable->getConfigurableAttributes($product);
// $attributes is a Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Type_Configurable_Attribute_Collection
foreach ($attributes as $attribute) {
// $attribute is a Mage_Catalog_Model_Product_Type_Configurable_Attribute
print $attribute->getLabel();
}
}
Mage_Catalog_Model_Product_Type_Configurable_Attribute本身没有太多可透露的。