Magento 获取子产品变体

发布于 2024-11-25 17:25:36 字数 822 浏览 2 评论 0原文

我觉得 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌梦深 2024-12-02 17:25:36

这可能对您有帮助:

    $product = Mage::getModel('catalog/product')->load($id);
    
    $childIds = Mage::getModel('catalog/product_type_grouped')
    ->getChildrenIds($product->getId());
    
    $i = 1;
    
    foreach ($childIds as $key => $val){
        
        foreach($vals as $keyy => $vall){
            $arr[$i] = $vall;
            $i++;
        }
        
    }

$id ->是组产品的产品 ID。

$arr->包含子产品 ID 的数组。

        $collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToSelect('price')
    ->addFieldToFilter('entity_id',array('in' =>array($arr)));

上面的代码片段显示了如何检索子产品。

This might help you:

    $product = Mage::getModel('catalog/product')->load($id);
    
    $childIds = Mage::getModel('catalog/product_type_grouped')
    ->getChildrenIds($product->getId());
    
    $i = 1;
    
    foreach ($childIds as $key => $val){
        
        foreach($vals as $keyy => $vall){
            $arr[$i] = $vall;
            $i++;
        }
        
    }

$id -> is the product id of the group product.

$arr -> array which contains the id's of child products.

        $collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToSelect('price')
    ->addFieldToFilter('entity_id',array('in' =>array($arr)));

above code snippet shows how the way to retrieve the child products.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文