Guest User

Untitled

a guest
Nov 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. // require magento core
  2. require_once 'app/Mage.php';
  3.  
  4. // execute on admin store
  5. Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
  6.  
  7. $products = Mage::getModel('catalog/product')->getCollection();
  8. foreach($products as $product) {
  9. echo $product->getName() . '<br/>';
  10. // save the product
  11. $product->save();
  12. }
  13.  
  14. echo 'Congratulations!!! Product resaved';
  15. ?>
  16.  
  17. namespace SwiftOtterShareButtonsSetup;
  18.  
  19. use MagentoFrameworkAppState;
  20. use MagentoCatalogModelResourceModelProductCollection;
  21. use MagentoFrameworkSetup{UpgradeDataInterface, ModuleDataSetupInterface, ModuleContextInterface};
  22.  
  23. class UpgradeData implements UpgradeDataInterface
  24. {
  25. protected $productCollection;
  26. protected $state;
  27.  
  28. public function __construct(Collection $productCollection, State $state) {
  29. $this->productCollection = $productCollection;
  30. $this->state = $state;
  31. }
  32.  
  33. public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
  34. {
  35. $setup->startSetup();
  36. $this->state->setAreaCode('frontend');
  37.  
  38. $products = $this->productCollection->load();
  39. $i = 0;
  40.  
  41. foreach ($products as $product) {
  42. if ($i > 4) {
  43. break;
  44. }
  45.  
  46. $product->save();
  47. $i++;
  48. }
  49.  
  50. $setup->endSetup();
  51. }
  52. }
  53.  
  54. <?xml version="1.0" ?>
  55. <config>
  56. <module name="SwiftOtter_ShareButtons" setup_version="0.1.7" />
  57. </config>
  58.  
  59. use MagentoFrameworkComponentComponentRegistrar;
  60.  
  61. ComponentRegistrar::register(ComponentRegistrar::MODULE, 'SwiftOtter_ShareButtons', __DIR__);
  62.  
  63. $objectManager = MagentoFrameworkAppObjectManager::getInstance();
  64.  
  65. $productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
  66.  
  67. $productCollection->load();
  68.  
  69. foreach($productCollection as $product)
  70. {
  71.  
  72. ................
  73.  
  74. ................
  75.  
  76. ............
  77.  
  78. $product->save();
  79.  
  80. }
Add Comment
Please, Sign In to add comment