-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupdateProduct.php
48 lines (36 loc) · 1.53 KB
/
updateProduct.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require dirname(__FILE__) . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
class Outslide extends \Magento\Framework\App\Http
implements \Magento\Framework\AppInterface {
public function launch()
{
// $this->_state->setAreaCode('frontend');
$this->_state->setAreaCode('adminhtml');
// $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_FRONTEND);
// $this->_state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
$productRepository = $this->_objectManager->create('Magento\Catalog\Model\ProductRepository');
// YOU WANT TO LOAD BY ID?
$id = "YOUR ID HERE";
// YOU WANT TO LOAD BY SKU?
$sku = "YOUR SKU HERE";
if($id) {
$product = $productRepository->getById($id);
}
if($sku) {
$product = $productRepository->get($sku);
}
$shortDescriptionAttributeCode = "short_description";
$descriptionAttributeCode = "description";
$shortDescriptionAttributeValue = "YOUR NEW VALUE";
$descriptionAttributeValue = "YOUR NEW VALUE";
$product->addAttributeUpdate($shortDescriptionAttributeCode, $shortDescriptionAttributeValue, 0);
$product->addAttributeUpdate($descriptionAttributeCode, $descriptionAttributeValue, 0);
echo 'Done!';
//the method must end with this line
return $this->_response;
}
}
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Outslide');
$bootstrap->run($app);