How do I dependency inject my “save product button”?

I’m creating an observer and I’m trying to connect it to saving a new product. If the product is new I’m trying to run a code, if not – skip.

Made an observer before save in creating a new product and after that I want to run the same code as shared catalog -> shared catalogs -> default -> set pricing and structure -> and just save without changing anything.

TLDR; I want the same effect as I hit save button on a new product and save button on shared catalogs.

This is my code:

<?php namespace CompanyNewProductReindexerObserver; use MagentoFrameworkEventObserver; use MagentoFrameworkEventObserverInterface; class NewProductObserver implements ObserverInterface { private $save; public function __construct(Save $save) { $this->save = $save; } public function saveFunction() { $this->save->execute(); } public function execute(Observer $observer) { $product = $observer->getProduct(); //$sku = $product->getSku(); $isProductNew = $product->isObjectNew(); if ($isProductNew == true) { $this->saveFunction(); } else { return; } } } 

submitted by /u/zokyffs
[link] [comments]