Save all products through php/shell script Planned maintenance scheduled April 23, 2019 at...

How does light 'choose' between wave and particle behaviour?

Why are vacuum tubes still used in amateur radios?

Did any compiler fully use 80-bit floating point?

An adverb for when you're not exaggerating

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

What is Adi Shankara referring to when he says "He has Vajra marks on his feet"?

Where is the Data Import Wizard Error Log

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

AppleTVs create a chatty alternate WiFi network

Sliceness of knots

A letter with no particular backstory

What initially awakened the Balrog?

Lagrange four-squares theorem --- deterministic complexity

Why we try to capture variability?

What does it mean that physics no longer uses mechanical models to describe phenomena?

Why does 14 CFR have skipped subparts in my ASA 2019 FAR/AIM book?

How can I set the aperture on my DSLR when it's attached to a telescope instead of a lens?

Draw 4 of the same figure in the same tikzpicture

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

How to write capital alpha?

Customizing QGIS plugins

Do wooden building fires get hotter than 600°C?

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

How does a spellshard spellbook work?



Save all products through php/shell script



Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Programmatically trigger admin save action on productRemoving all Related ProductsCreate invoice and shipment in magento via cron based on store view and order ageMagento programmatically force all products to saveCreate categories through installerImport csv file through a shell scriptHow to create/update bulk of products at a time programmaticallyadd to cart products with max qty of products error with run scriptNeed to save all simple products via admin or programaticallyShell script slows down to crawl until caches are clearedExport Category name in xml feed Magento 1.9.2





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I'm in the process of cleaning up my existing magento install by moving the DB and using a new install so I can do away with all the unnecessary extensions taking up space.



Everything seems to have been setup fine, however some product attributes are not showing up in the admin, but doing a save brings the values back. However I have over 7000 products and cant save them individually. All the products are simple products.



So I've used this script from this article.



<?php
require 'app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
foreach ($products as $product) {
$product->load();
echo 'Product: ' . $product->getId() . ' - ' . $product->getName() . "xA";

$product->setShortDescription('N/A');
$product->save();
}
?>


But I need to run this script via the browser and if the internet cuts out, I have to start again going over the ones that were already saved.




  1. Instead, how can I convert this to a shell script and run if via SSH?


  2. Also I have one store that doesn't have the same values as the default (all store views) how/where do I specify that the script run for only that store?



Thanks in advance.










share|improve this question
















bumped to the homepage by Community 7 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















    2















    I'm in the process of cleaning up my existing magento install by moving the DB and using a new install so I can do away with all the unnecessary extensions taking up space.



    Everything seems to have been setup fine, however some product attributes are not showing up in the admin, but doing a save brings the values back. However I have over 7000 products and cant save them individually. All the products are simple products.



    So I've used this script from this article.



    <?php
    require 'app/Mage.php';
    Mage::app();
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

    $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
    foreach ($products as $product) {
    $product->load();
    echo 'Product: ' . $product->getId() . ' - ' . $product->getName() . "xA";

    $product->setShortDescription('N/A');
    $product->save();
    }
    ?>


    But I need to run this script via the browser and if the internet cuts out, I have to start again going over the ones that were already saved.




    1. Instead, how can I convert this to a shell script and run if via SSH?


    2. Also I have one store that doesn't have the same values as the default (all store views) how/where do I specify that the script run for only that store?



    Thanks in advance.










    share|improve this question
















    bumped to the homepage by Community 7 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      2












      2








      2


      0






      I'm in the process of cleaning up my existing magento install by moving the DB and using a new install so I can do away with all the unnecessary extensions taking up space.



      Everything seems to have been setup fine, however some product attributes are not showing up in the admin, but doing a save brings the values back. However I have over 7000 products and cant save them individually. All the products are simple products.



      So I've used this script from this article.



      <?php
      require 'app/Mage.php';
      Mage::app();
      Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

      $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
      foreach ($products as $product) {
      $product->load();
      echo 'Product: ' . $product->getId() . ' - ' . $product->getName() . "xA";

      $product->setShortDescription('N/A');
      $product->save();
      }
      ?>


      But I need to run this script via the browser and if the internet cuts out, I have to start again going over the ones that were already saved.




      1. Instead, how can I convert this to a shell script and run if via SSH?


      2. Also I have one store that doesn't have the same values as the default (all store views) how/where do I specify that the script run for only that store?



      Thanks in advance.










      share|improve this question
















      I'm in the process of cleaning up my existing magento install by moving the DB and using a new install so I can do away with all the unnecessary extensions taking up space.



      Everything seems to have been setup fine, however some product attributes are not showing up in the admin, but doing a save brings the values back. However I have over 7000 products and cant save them individually. All the products are simple products.



      So I've used this script from this article.



      <?php
      require 'app/Mage.php';
      Mage::app();
      Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

      $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
      foreach ($products as $product) {
      $product->load();
      echo 'Product: ' . $product->getId() . ' - ' . $product->getName() . "xA";

      $product->setShortDescription('N/A');
      $product->save();
      }
      ?>


      But I need to run this script via the browser and if the internet cuts out, I have to start again going over the ones that were already saved.




      1. Instead, how can I convert this to a shell script and run if via SSH?


      2. Also I have one store that doesn't have the same values as the default (all store views) how/where do I specify that the script run for only that store?



      Thanks in advance.







      magento-1.9 php simple-product shell ssh






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 13 '17 at 12:55









      Community

      1




      1










      asked Mar 8 '17 at 16:16









      user2240778user2240778

      293316




      293316





      bumped to the homepage by Community 7 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 7 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Working shell script here: run it from shell directory php productupdate.php --stores <id,...>




          shell/productupdate.php




          <?php
          require_once 'abstract.php';

          class Your_Shell_Productupdate extends Mage_Shell_Abstract
          {
          protected $_stores = array();

          public function __construct() {
          parent::__construct();
          set_time_limit(0);

          if ($this->getArg('stores')) {
          $this->_stores = array_merge(
          $this->_stores,
          array_map(
          'trim',
          explode(',', $this->getArg('stores'))
          )
          );
          } else {
          $this->_stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
          }
          }

          public function run()
          {
          try {
          printf(
          'Selected stores: %s'."n",
          '"'.implode('", "', $this->_stores).'"'
          );

          foreach ($this->_stores as $storeId) {
          $products = Mage::getModel('catalog/product')->getCollection();
          Mage::getSingleton('core/resource_iterator')->walk(
          $products->getSelect(),
          array(array($this, '_saveShortDescription')),
          array('store_id' => $storeId)
          );

          printf(
          'Done processing.'."n"
          .'Total processed products count for store %d: %d'."n",
          $storeId, $products->getSize()
          );
          }
          } catch (Exception $e) {
          echo $e->getMessage().'@'.time();
          }
          }

          public function _saveShortDescription($args)
          {
          Mage::getSingleton('catalog/product_action')->updateAttributes(
          array($args['row']['entity_id']),
          array('short_description' => 'N/A'),
          $args['store_id']
          );
          }

          public function usageHelp()
          {
          return <<<USAGE
          Usage: php -f productupdate.php

          --stores <ids> Process only these stores (comma-separated)

          help This help

          USAGE;
          }
          }

          $shell = new Your_Shell_Productupdate();
          $shell->run();





          share|improve this answer


























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f163462%2fsave-all-products-through-php-shell-script%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Working shell script here: run it from shell directory php productupdate.php --stores <id,...>




            shell/productupdate.php




            <?php
            require_once 'abstract.php';

            class Your_Shell_Productupdate extends Mage_Shell_Abstract
            {
            protected $_stores = array();

            public function __construct() {
            parent::__construct();
            set_time_limit(0);

            if ($this->getArg('stores')) {
            $this->_stores = array_merge(
            $this->_stores,
            array_map(
            'trim',
            explode(',', $this->getArg('stores'))
            )
            );
            } else {
            $this->_stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
            }
            }

            public function run()
            {
            try {
            printf(
            'Selected stores: %s'."n",
            '"'.implode('", "', $this->_stores).'"'
            );

            foreach ($this->_stores as $storeId) {
            $products = Mage::getModel('catalog/product')->getCollection();
            Mage::getSingleton('core/resource_iterator')->walk(
            $products->getSelect(),
            array(array($this, '_saveShortDescription')),
            array('store_id' => $storeId)
            );

            printf(
            'Done processing.'."n"
            .'Total processed products count for store %d: %d'."n",
            $storeId, $products->getSize()
            );
            }
            } catch (Exception $e) {
            echo $e->getMessage().'@'.time();
            }
            }

            public function _saveShortDescription($args)
            {
            Mage::getSingleton('catalog/product_action')->updateAttributes(
            array($args['row']['entity_id']),
            array('short_description' => 'N/A'),
            $args['store_id']
            );
            }

            public function usageHelp()
            {
            return <<<USAGE
            Usage: php -f productupdate.php

            --stores <ids> Process only these stores (comma-separated)

            help This help

            USAGE;
            }
            }

            $shell = new Your_Shell_Productupdate();
            $shell->run();





            share|improve this answer






























              0














              Working shell script here: run it from shell directory php productupdate.php --stores <id,...>




              shell/productupdate.php




              <?php
              require_once 'abstract.php';

              class Your_Shell_Productupdate extends Mage_Shell_Abstract
              {
              protected $_stores = array();

              public function __construct() {
              parent::__construct();
              set_time_limit(0);

              if ($this->getArg('stores')) {
              $this->_stores = array_merge(
              $this->_stores,
              array_map(
              'trim',
              explode(',', $this->getArg('stores'))
              )
              );
              } else {
              $this->_stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
              }
              }

              public function run()
              {
              try {
              printf(
              'Selected stores: %s'."n",
              '"'.implode('", "', $this->_stores).'"'
              );

              foreach ($this->_stores as $storeId) {
              $products = Mage::getModel('catalog/product')->getCollection();
              Mage::getSingleton('core/resource_iterator')->walk(
              $products->getSelect(),
              array(array($this, '_saveShortDescription')),
              array('store_id' => $storeId)
              );

              printf(
              'Done processing.'."n"
              .'Total processed products count for store %d: %d'."n",
              $storeId, $products->getSize()
              );
              }
              } catch (Exception $e) {
              echo $e->getMessage().'@'.time();
              }
              }

              public function _saveShortDescription($args)
              {
              Mage::getSingleton('catalog/product_action')->updateAttributes(
              array($args['row']['entity_id']),
              array('short_description' => 'N/A'),
              $args['store_id']
              );
              }

              public function usageHelp()
              {
              return <<<USAGE
              Usage: php -f productupdate.php

              --stores <ids> Process only these stores (comma-separated)

              help This help

              USAGE;
              }
              }

              $shell = new Your_Shell_Productupdate();
              $shell->run();





              share|improve this answer




























                0












                0








                0







                Working shell script here: run it from shell directory php productupdate.php --stores <id,...>




                shell/productupdate.php




                <?php
                require_once 'abstract.php';

                class Your_Shell_Productupdate extends Mage_Shell_Abstract
                {
                protected $_stores = array();

                public function __construct() {
                parent::__construct();
                set_time_limit(0);

                if ($this->getArg('stores')) {
                $this->_stores = array_merge(
                $this->_stores,
                array_map(
                'trim',
                explode(',', $this->getArg('stores'))
                )
                );
                } else {
                $this->_stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
                }
                }

                public function run()
                {
                try {
                printf(
                'Selected stores: %s'."n",
                '"'.implode('", "', $this->_stores).'"'
                );

                foreach ($this->_stores as $storeId) {
                $products = Mage::getModel('catalog/product')->getCollection();
                Mage::getSingleton('core/resource_iterator')->walk(
                $products->getSelect(),
                array(array($this, '_saveShortDescription')),
                array('store_id' => $storeId)
                );

                printf(
                'Done processing.'."n"
                .'Total processed products count for store %d: %d'."n",
                $storeId, $products->getSize()
                );
                }
                } catch (Exception $e) {
                echo $e->getMessage().'@'.time();
                }
                }

                public function _saveShortDescription($args)
                {
                Mage::getSingleton('catalog/product_action')->updateAttributes(
                array($args['row']['entity_id']),
                array('short_description' => 'N/A'),
                $args['store_id']
                );
                }

                public function usageHelp()
                {
                return <<<USAGE
                Usage: php -f productupdate.php

                --stores <ids> Process only these stores (comma-separated)

                help This help

                USAGE;
                }
                }

                $shell = new Your_Shell_Productupdate();
                $shell->run();





                share|improve this answer















                Working shell script here: run it from shell directory php productupdate.php --stores <id,...>




                shell/productupdate.php




                <?php
                require_once 'abstract.php';

                class Your_Shell_Productupdate extends Mage_Shell_Abstract
                {
                protected $_stores = array();

                public function __construct() {
                parent::__construct();
                set_time_limit(0);

                if ($this->getArg('stores')) {
                $this->_stores = array_merge(
                $this->_stores,
                array_map(
                'trim',
                explode(',', $this->getArg('stores'))
                )
                );
                } else {
                $this->_stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
                }
                }

                public function run()
                {
                try {
                printf(
                'Selected stores: %s'."n",
                '"'.implode('", "', $this->_stores).'"'
                );

                foreach ($this->_stores as $storeId) {
                $products = Mage::getModel('catalog/product')->getCollection();
                Mage::getSingleton('core/resource_iterator')->walk(
                $products->getSelect(),
                array(array($this, '_saveShortDescription')),
                array('store_id' => $storeId)
                );

                printf(
                'Done processing.'."n"
                .'Total processed products count for store %d: %d'."n",
                $storeId, $products->getSize()
                );
                }
                } catch (Exception $e) {
                echo $e->getMessage().'@'.time();
                }
                }

                public function _saveShortDescription($args)
                {
                Mage::getSingleton('catalog/product_action')->updateAttributes(
                array($args['row']['entity_id']),
                array('short_description' => 'N/A'),
                $args['store_id']
                );
                }

                public function usageHelp()
                {
                return <<<USAGE
                Usage: php -f productupdate.php

                --stores <ids> Process only these stores (comma-separated)

                help This help

                USAGE;
                }
                }

                $shell = new Your_Shell_Productupdate();
                $shell->run();






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 17 '18 at 17:53

























                answered May 24 '17 at 11:25









                sv3nsv3n

                10k62557




                10k62557






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f163462%2fsave-all-products-through-php-shell-script%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                    How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                    夢乃愛華...