如何获取 Magento 中可配置属性的选项?
我们希望通过另一个系统中的 Magento-API 导出/导入可配置产品。对我们来说重要的是可配置产品的价值,例如有 3 种颜色(红、绿、蓝)的 T 恤。
我们通过以下功能接收可配置属性:
public function options($productId, $store = null, $identifierType = null)
{
$product = $this->_getProduct($productId, $store, $identifierType);
if (!$product->getId()) {
$this->_fault('not_exists');
}
$configurableAttributeCollection = $product->getTypeInstance()->getConfigurableAttributes();
$result = array();
foreach($configurableAttributeCollection as $attribute){
$result[$attribute->getProductAttribute()->getAttributeCode()] = $attribute->getProductAttribute()->getFrontend()->getLabel();
//Attr-Code: $attribute->getProductAttribute()->getAttributeCode()
//Attr-Label: $attribute->getProductAttribute()->getFrontend()->getLabel()
//Attr-Id: $attribute->getProductAttribute()->getId()
}
return $result;
}
但是如何使用可配置属性中现在可用的标签/id 获取该产品中使用的选项(如果可配置属性是“颜色”,则为蓝色、绿色、红色)我们通过上面的函数得到了哪些?
非常感谢您的回答!
蒂姆
we want to export/import configurable products through the Magento-API in another system. What is important for us, are the values of the configurable products like a T-Shirt which has 3 colors (red, green and blue).
We receive the configurable attributes with the following function:
public function options($productId, $store = null, $identifierType = null)
{
$product = $this->_getProduct($productId, $store, $identifierType);
if (!$product->getId()) {
$this->_fault('not_exists');
}
$configurableAttributeCollection = $product->getTypeInstance()->getConfigurableAttributes();
$result = array();
foreach($configurableAttributeCollection as $attribute){
$result[$attribute->getProductAttribute()->getAttributeCode()] = $attribute->getProductAttribute()->getFrontend()->getLabel();
//Attr-Code: $attribute->getProductAttribute()->getAttributeCode()
//Attr-Label: $attribute->getProductAttribute()->getFrontend()->getLabel()
//Attr-Id: $attribute->getProductAttribute()->getId()
}
return $result;
}
But how is it possible to get the options used in that product (e.a. blue, green, red if the configurable attribute is "color") with the now available label/id from the configurable attribute which we got through the above function?
Answers are very appreciated!
Tim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于我们找不到更好的解决方案,这就是我想出的:
希望这对任何人都有帮助。
Since we couldn't find a better solution, this is what I came up with:
Hope this helps anybody.
我不是 100% 确定我理解这个问题...假设您想要特定产品的可配置选项的值和标签,我认为这会起作用(在版本 1.4.0.1 上测试),
再次不确定您到底在看什么for,但是
$attribute->getProductAttribute()->getSource()->getAllOptions()
函数为我提供了可用的选项标签和值。希望这有帮助。如果没有,请告诉我我误解的地方。谢谢!
I'm not 100% sure that I understand the question ... assuming you want the values and labels for the configurable options for a specific product I assume this would work (tested on version 1.4.0.1)
again not sure exactly what your looking for, but the
$attribute->getProductAttribute()->getSource()->getAllOptions()
function gave me the available options label and value.Hope this helps. if not, let me where I misunderstood. Thanks!