Advertisement
Guest User

Magento Update Up-Sells

a guest
Aug 10th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1.     foreach($collection as $p) {
  2.         $upsell = $p->getUpSellProductIds();
  3.                            
  4.         if ( count($upsell) > 0 ) {
  5.             $toUpdate = false;
  6.    
  7.             foreach ($upsell as $k => $u) {
  8.    
  9.                 // Check if the entity_id is among the discontinued products
  10.                 if ( isset($discontinued[ $u ]) ) {
  11.                     // Remove the discontinued entity from the up-sells list
  12.                     unset($upsell[$k]);
  13.                     $toUpdate = true;
  14.                 }
  15.             }
  16.    
  17.             if ($toUpdate) {
  18.                 $upsellToSave = array();
  19.    
  20.                 foreach ($upsell as $u) // Formatting the data
  21.                     $upsellToSave[ $u ] = array('position'=>'');
  22.    
  23.                 try {
  24.                     $p->setUpSellLinkData($upsellToSave)->save();
  25.                 } catch (Exception $e) {
  26.                     echo "Problem saving up-sell data.\n";
  27.                 }
  28.             }
  29.         }
  30.     }
  31.  
  32. // http://magento.stackexchange.com/posts/130802
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement