Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

magento update attribute value without using object manager

        <?php
    namespace vendormoduleObserver;
    
    class ProductSaveAfter implements MagentoFrameworkEventObserverInterface
    {
        public function __construct(
            MagentoBackendModelAuthSession $authSession,
            MagentoCatalogModelProductFactory $productFactory
        ) {
            $this->authSession = $authSession;
            $this->productFactroy = $productFactory;
        }
        public function execute(MagentoFrameworkEventObserver $observer)
        {
            $user = $this->authSession->getUser()->getUsername();
            $productId = (int) $observer->getProduct()->getId();
            $product = $this->productFactroy->create()->load($productId);
            $product->addAttributeUpdate("updated_by", $user, 0);//attribute,value,storeid
        }
    }
 
PREVIOUS NEXT
Tagged: #magento #update #attribute #object #manager
ADD COMMENT
Topic
Name
9+1 =