0

I'm not sure if this is even possible but say for example i have a category called X with 100 products in it, can i add say 3 products to all them 100 products in that particular category without manually going through every single product selecting which product(s) i would like to cross sell.

1
  • means you want to set cross products randomly any 3 to each product Feb 8, 2017 at 15:28

1 Answer 1

0

You can try below code:

$categoryId= 123;
$categoryProducts = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection();
foreach($categoryProducts as $product){
     $param = array();
     $crosssells = $product->getCrossSellProducts();
     foreach ($crosssells as $item) {
           $param[$item->getId()] = array('position' =>$item->getPosition());
     }
    $newCrossSellProductsIds=array(4,5,6);
    foreach ($newCrossSellProductsIds as $productID) {
     if (!isset($param[$productID])){ 
          $param[$productID]= array(
                                    'position'=>1
                                   );
      }
     }
   $product->setCrossSellLinkData($param);
   $product->save();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.