简体   繁体   English

Magento 获取子产品变体

[英]Magento Get Child Product Variation

I feel like the flexibility of Magento would allow for my problem to be fixed but I haven't found anything as of yet.我觉得 Magento 的灵活性可以解决我的问题,但我还没有找到任何东西。

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:到目前为止,我所能做的就是在 view.phtml 文件中:

if ($_product->getTypeId() == 'configurable')
{
    $confAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product);
    print_r($confAttributes);
}

But that is from the parent scope of things.但那是来自父 scope 的东西。 Basically my problem is that I need to get the images of the child products but when I go through a loop like this...基本上我的问题是我需要获取子产品的图像但是当我通过这样的循环 go...

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.但是现在从子产品的角度来看是scope。 I need to somehow correlate the child product with the attribute value that it takes on (for use with jQuery and image manipulation).我需要以某种方式将子产品与其具有的属性值相关联(用于 jQuery 和图像处理)。

So is there any way that I can get some information from the child_product's perspective that can link it to the attribute?那么有什么方法可以从 child_product 的角度获取一些可以将其链接到属性的信息?

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. $id -> 是组产品的产品 ID。

$arr -> array which contains the id's of child products. $arr -> 包含子产品 id 的数组。

        $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.上面的代码片段显示了如何检索子产品的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM