1515use Magento \Framework \Stdlib \DateTime \Filter \Date ;
1616
1717/**
18- * Save CMS Tag action.
18+ * Save Lof Tag action.
1919 */
2020class Save extends \Lof \ProductTags \Controller \Adminhtml \Tag implements HttpPostActionInterface
2121{
@@ -51,18 +51,28 @@ public function execute()
5151
5252 /** @var \Lof\ProductTags\Model\Tag $model */
5353 $ model = $ this ->TagFactory ->create ();
54-
5554 $ id = $ this ->getRequest ()->getParam ('tag_id ' );
5655 if ($ id ) {
5756 try {
58- $ model = $ this -> tagRepository -> getById ($ id );
57+ $ model = $ model -> load ($ id );
5958 } catch (LocalizedException $ e ) {
6059 $ this ->messageManager ->addErrorMessage (__ ('This tag no longer exists. ' ));
6160 return $ resultRedirect ->setPath ('*/*/ ' );
6261 }
6362 }
6463 $ model ->setData ($ data );
65- try {
64+ if (isset ($ data ['tag_products ' ])
65+ && is_string ($ data ['tag_products ' ])) {
66+ $ products = json_decode ($ data ['tag_products ' ], true );
67+ $ model ->setPostedProducts ($ products );
68+ }
69+ $ this ->_eventManager ->dispatch (
70+ 'lof_producttags_prepare_save ' ,
71+ ['tag ' => $ model , 'request ' => $ this ->getRequest ()]
72+ );
73+ $ products = $ model ->getPostedProducts ();
74+
75+ try {
6676 $ model ->save ($ model );
6777 $ this ->messageManager ->addSuccessMessage (__ ('You saved the tag. ' ));
6878 $ this ->dataPersistor ->clear ('lof_productags_tag ' );
@@ -81,7 +91,6 @@ public function execute()
8191 private function processBlockReturn ($ model , $ data , $ resultRedirect )
8292 {
8393 $ redirect = $ data ['back ' ] ?? 'close ' ;
84-
8594 if ($ redirect ==='continue ' ) {
8695 $ resultRedirect ->setPath ('*/*/edit ' , ['tag_id ' => $ model ->getId ()]);
8796 } else if ($ redirect === 'close ' ) {
0 commit comments