i getting products categories, below code using want position of products . not getting how change code make optimize.
$products = mage::getmodel('catalog/product')->getcollection()->addattributetosort('position'); $prodids=$products->getallids(); if(count($prodids)>0) { $product = mage::getmodel('catalog/product'); $i=0; foreach($prodids $productid) { $ids= array(); $productcollection = mage::getmodel('catalog/product')->load($productid); $final['prodcat_list'][$i]['sku']= $productcollection ->getsku(); $final['prodcat_list'][$i]['product_id']= $productid; $final['prodcat_list'][$i]['name']= $productcollection ->getname(); $final['prodcat_list'][$i]['image']=$productcollection ->getthumbnailurl(); $final['prodcat_list'][$i]['description']=$productcollection ->getdescription(); $final['prodcat_list'][$i]['short_description']=$productcollection ->getshortdescription(); $final['prodcat_list'][$i]['weight']=$productcollection ->getweight(); $final['prodcat_list'][$i]['created_at']=$productcollection ->getcreatedat(); $final['prodcat_list'][$i]['updated_at']=$productcollection ->getupdatedat(); $final['prodcat_list'][$i]['price']=$productcollection ->getprice(); $final['prodcat_list'][$i]['special_price']=$productcollection ->getspecialprice(); $final['prodcat_list'][$i]['tax_class_id']=$productcollection ->gettaxclassid(); $final['prodcat_list'][$i]['cat_id']= implode(',',$productcollection ->getcategoryids()); $ids[$i]=$result[$i]['category_ids']; foreach($productcollection ->getcategoryids() $categoryid) { $category = mage::getmodel('catalog/category')->load($categoryid); $final['prodcat_list'][$i]['cat_name'][$categoryid]= $category->getname(); } $i++; }
i want add position of products in $final['prodcat_list'] variable.
you should consider cleaning code. anyway, below solution problem.
foreach($productcollection ->getcategoryids() $categoryid) { $category = mage::getmodel('catalog/category')->load($categoryid); $final['prodcat_list'][$i]['cat_name'][$categoryid]= $category->getname(); // new code starts here $positions = $category->getproductsposition(); if ($positions) { $final['prodcat_list'][$i]['cat_name'][$categoryid]['position'] = $positions[$productid]; } }
Comments
Post a Comment