什么是更新magento 2产品的更好方法?

时间:2018-10-20 08:05:21

标签: php model magento2

我正在使用此代码更新magento 2中的产品。 是否有更好的方法,例如是否有某种特定的模型代替产品管理器来使用产品,而该模型无论如何都会更快或更好?

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
 $product = $objectManager->create('\Magento\Catalog\Model\Product')->load(3);;

 $product->setName('Sample Simple Product'); // Name of Product
 $product->setAttributeSetId(4); // Attribute set id
 $product->setStatus(1); // Status on product enabled/ disabled 1/0
 $product->setWeight(10); // weight of product
 $product->setVisibility(4); // visibilty of product (catalog / search / catalog, search / Not visible individually)
 $product->setTaxClassId(0); // Tax class id
 $product->setTypeId('simple'); // type of product (simple/virtual/downloadable/configurable)
 $product->setPrice(131); // price of product
 $product->setStockData(
                    array(
                        'use_config_manage_stock' => 0,
                        'manage_stock' => 1,
                        'is_in_stock' => 1,
                        'qty' => 99
                    )
                );
 $product->save();

0 个答案:

没有答案