Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento:从产品ID和当前类别ID获取相关产品_Magento_Magento 1.7 - Fatal编程技术网

Magento:从产品ID和当前类别ID获取相关产品

Magento:从产品ID和当前类别ID获取相关产品,magento,magento-1.7,Magento,Magento 1.7,在我的训练期间,我完全从Magento开始。我已经为一个项目工作了两个星期,有时我不知道如何进行 我将尝试表示我的类别树: - accessories * visors * communication systems * other - helmets * a lot of subcategories and subcategories... 我的实际问题是:我属于附件子类别之一(例如visors)。我添加了一个带有select的表单,允许选择头盔模型。提交se

在我的训练期间,我完全从Magento开始。我已经为一个项目工作了两个星期,有时我不知道如何进行

我将尝试表示我的类别树:

- accessories
    * visors
    * communication systems
    * other
- helmets
    * a lot of subcategories and subcategories...
我的实际问题是:我属于附件子类别之一(例如visors)。我添加了一个带有
select
的表单,允许选择头盔模型。提交
select
时,我想显示与所选头盔模型相关的visor列表(实际上是
虚拟产品

我可以获得当前类别ID(在本例中为visors)和虚拟产品ID(因此头盔模型)。但我不知道如何同时按产品ID和类别ID显示相关产品

我试过这样的东西:

$relatedProducts = Mage::getModel('catalog/product_link')
                         ->getCollection()
                         ->addCategoryFilter($myCurrentCat)
                         ->addFieldToFilter('product_id',$myVirtualProductId)
                         ->addFieldToFilter('link_type_id','1');
但它似乎不起作用

欢迎任何帮助。谢谢


编辑:在我问了这个问题10天后,我仍然不知道如何解决我的问题。如果有人能帮忙的话,哪怕是一点点,只是一个线索……

我现在无法测试,但你可以尝试这样做:


$collection = Mage::getSingleton('catalog/product_link')
    ->useRelatedLinks()
    ->getProductCollection()
    ->setIsStrongMode();
$product = Mage::getModel('catalog/product')->load($productId);
$collection->setProduct($product);
$collection->addCategoryFilter($category); //I'm not sure if this will work correctly

我要测试一下,到时候我会有更多的时间。

事实上,我只是自己解决了问题

以下是我的解决方案,如果它能帮助未来的任何人:

$mainProduct = Mage::getModel('catalog/category')->load($myCurrentCat->getId());
$mainProduct = $mainProduct->getProductCollection();
$mainProduct = $mainProduct->addAttributeToFilter('product_id', $myVirtualProductId);

foreach ($mainProduct as $product) {
    $related = $product->getRelatedProductIds();
    if ($this->array_contains($related, $myVirtualProductId)) {
        //TODO
    }
}

参考此代码并应用代码//添加或条件:$collection->addAttributeToFilter(数组(数组('attribute'=>'field\u name','in'=>array(1,2,3)),数组('attribute'=>'date\u field','from'=>'2000-09-10',);