i am looking for code which can help me get parent product id from child product Id and this both products are related using upsell feature
so far i was able to retrieve child products id from parent id by using below code
//Get product detail using product id (Suppose you have product id is : $product_id)
$_product = Mage::getModel('catalog/product')->load($product_id);
// Fetch list of upsell product using query.
$upsell_product = $_product->getUpSellProductCollection();
but i want to do reverse
This solution also worked
$childProductId = 17;//edit this value, or get it by $product->getId()
$productsLinkedAsUpsell = Mage::getModel('catalog/product_link')->getCollection()
->addFieldToFilter('linked_product_id', $childProductId)
->addFieldToFilter('link_type_id', Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL);
foreach ($productsLinkedAsUpsell as $upsell) {
$parentId = $upsell->getProductId();
}