Magento 获取子产品变体
我觉得 Magento 的灵活性可以解决我的问题,但到目前为止我还没有找到任何东西。
因此,本质上我需要获取可配置产品的子产品的属性值。到目前为止,我所能做的就是在 view.phtml 文件中:
if ($_product->getTypeId() == 'configurable')
{
$confAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
print_r($confAttributes);
}
但那是来自事物的父范围。基本上我的问题是我需要获取子产品的图像,但是当我经历这样的循环时......
if ($_product->getTypeId() == 'configurable')
$_child_products = $_configurable_model->getUsedProducts(null, $_product);
for ($i = 0; $i < count ($_child_products); $i++){
<?php echo $this->helper('catalog/image')->init($_child_products[$i], 'image'); ?>
}
但现在这是从子产品的角度来看的范围。我需要以某种方式将子产品与其所采用的属性值关联起来(用于 jQuery 和图像处理)。
那么有什么方法可以从 child_product 的角度获取一些信息,并将其链接到属性吗?
I feel like the flexibility of Magento would allow for my problem to be fixed but I haven't found anything as of yet.
So essentially I need to get the attribute value for a child product of a configurable product. So far all I can do is in the view.phtml file:
if ($_product->getTypeId() == 'configurable')
{
$confAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
print_r($confAttributes);
}
But that is from the parent scope of things. Basically my problem is that I need to get the images of the child products but when I go through a loop like this...
if ($_product->getTypeId() == 'configurable')
$_child_products = $_configurable_model->getUsedProducts(null, $_product);
for ($i = 0; $i < count ($_child_products); $i++){
<?php echo $this->helper('catalog/image')->init($_child_products[$i], 'image'); ?>
}
But now that is the scope from the perspective of the child product. I need to somehow correlate the child product with the attribute value that it takes on (for use with jQuery and image manipulation).
So is there any way that I can get some information from the child_product's perspective that can link it to the attribute?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能对您有帮助:
$id ->是组产品的产品 ID。
$arr->包含子产品 ID 的数组。
上面的代码片段显示了如何检索子产品。
This might help you:
$id -> is the product id of the group product.
$arr -> array which contains the id's of child products.
above code snippet shows how the way to retrieve the child products.