Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // require magento core
- require_once 'app/Mage.php';
- // execute on admin store
- Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
- $products = Mage::getModel('catalog/product')->getCollection();
- foreach($products as $product) {
- echo $product->getName() . '<br/>';
- // save the product
- $product->save();
- }
- echo 'Congratulations!!! Product resaved';
- ?>
- namespace SwiftOtterShareButtonsSetup;
- use MagentoFrameworkAppState;
- use MagentoCatalogModelResourceModelProductCollection;
- use MagentoFrameworkSetup{UpgradeDataInterface, ModuleDataSetupInterface, ModuleContextInterface};
- class UpgradeData implements UpgradeDataInterface
- {
- protected $productCollection;
- protected $state;
- public function __construct(Collection $productCollection, State $state) {
- $this->productCollection = $productCollection;
- $this->state = $state;
- }
- public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- $setup->startSetup();
- $this->state->setAreaCode('frontend');
- $products = $this->productCollection->load();
- $i = 0;
- foreach ($products as $product) {
- if ($i > 4) {
- break;
- }
- $product->save();
- $i++;
- }
- $setup->endSetup();
- }
- }
- <?xml version="1.0" ?>
- <config>
- <module name="SwiftOtter_ShareButtons" setup_version="0.1.7" />
- </config>
- use MagentoFrameworkComponentComponentRegistrar;
- ComponentRegistrar::register(ComponentRegistrar::MODULE, 'SwiftOtter_ShareButtons', __DIR__);
- $objectManager = MagentoFrameworkAppObjectManager::getInstance();
- $productCollection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
- $productCollection->load();
- foreach($productCollection as $product)
- {
- ................
- ................
- ............
- $product->save();
- }
Add Comment
Please, Sign In to add comment