Php Magento获得子产品变体
我觉得Magento的灵活性可以解决我的问题,但到目前为止我还没有发现任何问题 所以本质上我需要获取可配置产品的子产品的属性值。到目前为止,我只能在view.phtml文件中执行以下操作:Php Magento获得子产品变体,php,image,magento,mage,Php,Image,Magento,Mage,我觉得Magento的灵活性可以解决我的问题,但到目前为止我还没有发现任何问题 所以本质上我需要获取可配置产品的子产品的属性值。到目前为止,我只能在view.phtml文件中执行以下操作: if ($_product->getTypeId() == 'configurable') { $confAttributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product
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'); ?>
}
if($\u product->getTypeId()=='configurable')
$\u child\u products=$\u configurable\u model->getUsedProducts(null,$\u product);
对于($i=0;$i
但现在这是从子产品的角度来看的范围。我需要以某种方式将子产品与它所具有的属性值关联起来(用于jQuery和图像处理)
那么,是否有任何方法可以从儿童产品的角度获得一些信息,将其链接到属性?如果我对问题的理解是正确的,希望此代码可以帮助您
$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)));
上面的代码片段显示了如何检索子产品。我不确定是否得到了您确切需要的内容。截取的第二段代码有什么问题?第二段代码只获取子产品图像。我需要一种方法让这些图像知道它们来自什么变化。第一个代码片段为我提供了一系列适用的变体,但我无法将图像URL与变体链接起来……您是否尝试过将$\u child\u products[$I]加载为magento模型?或者集合?上面的第二个代码片段将
$\u子产品
作为$\u可配置的\u模型->getUsedProducts(null,$\u产品)代码>。我对Magento不是很熟悉,但我相信这是一个模型。如果不是,请纠正我
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('price')
->addFieldToFilter('entity_id',array('in' =>array($arr)));