|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tkotosz\CatalogRouter\Model\Service\UrlPathUsedChecker; |
|
4
|
|
|
|
|
5
|
|
|
use Magento\Store\Model\StoreManagerInterface; |
|
6
|
|
|
use Tkotosz\CatalogRouter\Api\CategoryResolverInterface; |
|
7
|
|
|
use Tkotosz\CatalogRouter\Api\ProductResolverInterface; |
|
8
|
|
|
use Tkotosz\CatalogRouter\Api\UrlPathUsedChecker; |
|
9
|
|
|
use Tkotosz\CatalogRouter\Model\EntityData; |
|
10
|
|
|
use Tkotosz\CatalogRouter\Model\Service\CatalogUrlPathResolver; |
|
11
|
|
|
use Tkotosz\CatalogRouter\Model\UrlPath; |
|
12
|
|
|
|
|
13
|
|
|
class CategoryUrlPathChecker implements UrlPathUsedChecker |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var CategoryResolverInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
private $categoryResolver; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var StoreManagerInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $storeManager; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var CatalogUrlPathResolver |
|
27
|
|
|
*/ |
|
28
|
|
|
private $catalogUrlPathResolver; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param CategoryResolverInterface $categoryResolver |
|
32
|
|
|
* @param StoreManagerInterface $storeManager |
|
33
|
|
|
* @param CatalogUrlPathResolver $catalogUrlPathResolver |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct( |
|
36
|
|
|
CategoryResolverInterface $categoryResolver, |
|
37
|
|
|
StoreManagerInterface $storeManager, |
|
38
|
|
|
CatalogUrlPathResolver $catalogUrlPathResolver |
|
39
|
|
|
) { |
|
40
|
|
|
$this->categoryResolver = $categoryResolver; |
|
41
|
|
|
$this->storeManager = $storeManager; |
|
42
|
|
|
$this->catalogUrlPathResolver = $catalogUrlPathResolver; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param UrlPath $urlPath |
|
47
|
|
|
* @param int $storeId |
|
48
|
|
|
* |
|
49
|
|
|
* @return EntityData[] |
|
50
|
|
|
*/ |
|
51
|
|
|
public function check(UrlPath $urlPath, int $storeId) : array |
|
52
|
|
|
{ |
|
53
|
|
|
$parentCategoryId = $this->catalogUrlPathResolver->resolveParentCategoryId($urlPath, $storeId); |
|
54
|
|
|
|
|
55
|
|
|
return $this->categoryResolver->resolveAllByUrlKey($urlPath->getLastPart(), $storeId, $parentCategoryId); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|