Created
December 10, 2018 14:06
-
-
Save tshabatyn/506cd1ca10ac81da5b167f569a36adaf to your computer and use it in GitHub Desktop.
Magento save Product vs saveAttribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Magento\Framework\App\Bootstrap; | |
| require __DIR__ . '/app/bootstrap.php'; | |
| $bootstrap = Bootstrap::create(BP, $_SERVER); | |
| $objectManager = $bootstrap->getObjectManager(); | |
| $state = $objectManager->get('Magento\Framework\App\State'); | |
| $state->setAreaCode('frontend'); | |
| $product_id = 4; | |
| $product = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id); | |
| $start = microtime(true); | |
| $productResource = $objectManager->create('\Magento\Catalog\Model\ResourceModel\Product'); | |
| $product->setName('new product name 1'); | |
| $productResource->saveAttribute($product, 'name'); | |
| echo "Save attribute duration: ".(microtime(true) - $start)." seconds\n"; | |
| $starttime = microtime(true); | |
| $product->setName('new product name 2'); | |
| $product->save(); | |
| echo "Save product duration: ".(microtime(true) - $start)." seconds\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment