14
14
use Magento \Store \Model \StoreManagerInterface ;
15
15
use Magento \UrlRewrite \Model \Exception \UrlAlreadyExistsException ;
16
16
use Magento \CatalogUrlRewrite \Model \Product \Validator as ProductUrlRewriteValidator ;
17
+ use Magento \CatalogUrlRewrite \Model \ProductUrlPathGenerator ;
17
18
18
19
/**
19
20
* Product validate
@@ -59,6 +60,11 @@ class Validate extends Product implements HttpPostActionInterface, HttpGetAction
59
60
*/
60
61
private $ storeManager ;
61
62
63
+ /**
64
+ * @var ProductUrlPathGenerator
65
+ */
66
+ private $ productUrlPathGenerator ;
67
+
62
68
/**
63
69
* @var ProductUrlRewriteValidator
64
70
*/
@@ -73,6 +79,7 @@ class Validate extends Product implements HttpPostActionInterface, HttpGetAction
73
79
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
74
80
* @param \Magento\Catalog\Model\ProductFactory $productFactory
75
81
* @param ProductUrlRewriteValidator $productUrlRewriteValidator
82
+ * @param ProductUrlPathGenerator $productUrlPathGenerator
76
83
*/
77
84
public function __construct (
78
85
\Magento \Backend \App \Action \Context $ context ,
@@ -82,7 +89,8 @@ public function __construct(
82
89
\Magento \Framework \Controller \Result \JsonFactory $ resultJsonFactory ,
83
90
\Magento \Framework \View \LayoutFactory $ layoutFactory ,
84
91
\Magento \Catalog \Model \ProductFactory $ productFactory ,
85
- ProductUrlRewriteValidator $ productUrlRewriteValidator
92
+ ProductUrlRewriteValidator $ productUrlRewriteValidator ,
93
+ ProductUrlPathGenerator $ productUrlPathGenerator
86
94
) {
87
95
$ this ->_dateFilter = $ dateFilter ;
88
96
$ this ->productValidator = $ productValidator ;
@@ -91,6 +99,7 @@ public function __construct(
91
99
$ this ->layoutFactory = $ layoutFactory ;
92
100
$ this ->productFactory = $ productFactory ;
93
101
$ this ->productUrlRewriteValidator = $ productUrlRewriteValidator ;
102
+ $ this ->productUrlPathGenerator = $ productUrlPathGenerator ;
94
103
}
95
104
96
105
/**
@@ -140,7 +149,11 @@ public function execute()
140
149
$ resource ->getAttribute ('news_from_date ' )->setMaxValue ($ product ->getNewsToDate ());
141
150
$ resource ->getAttribute ('custom_design_from ' )->setMaxValue ($ product ->getCustomDesignTo ());
142
151
143
- $ this ->productUrlRewriteValidator ->validateUrlKey ($ product );
152
+ if (!$ product ->getUrlKey ()) {
153
+ $ urlKey = $ this ->productUrlPathGenerator ->getUrlKey ($ product );
154
+ $ product ->setUrlKey ($ urlKey );
155
+ }
156
+ $ this ->productUrlRewriteValidator ->validateUrlKeyConflicts ($ product );
144
157
$ this ->productValidator ->validate ($ product , $ this ->getRequest (), $ response );
145
158
} catch (\Magento \Eav \Model \Entity \Attribute \Exception $ e ) {
146
159
$ response ->setError (true );
0 commit comments