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\UrlPath; |
10
|
|
|
use Tkotosz\CatalogRouter\Model\EntityData; |
11
|
|
|
|
12
|
|
|
class CategoryUrlPathChecker implements UrlPathUsedChecker |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var CategoryResolverInterface |
16
|
|
|
*/ |
17
|
|
|
private $categoryResolver; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var StoreManagerInterface |
21
|
|
|
*/ |
22
|
|
|
private $storeManager; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param CategoryResolverInterface $categoryResolver |
26
|
|
|
* @param StoreManagerInterface $storeManager |
27
|
|
|
*/ |
28
|
|
|
public function __construct(CategoryResolverInterface $categoryResolver, StoreManagerInterface $storeManager) |
29
|
|
|
{ |
30
|
|
|
$this->categoryResolver = $categoryResolver; |
31
|
|
|
$this->storeManager = $storeManager; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param UrlPath $urlPath |
36
|
|
|
* @param int $storeId |
37
|
|
|
* |
38
|
|
|
* @return EntityData[] |
39
|
|
|
*/ |
40
|
|
|
public function check(UrlPath $urlPath, int $storeId) : array |
41
|
|
|
{ |
42
|
|
|
$parentCategoryId = $this->resolveParentCategoryId($urlPath, $storeId); |
43
|
|
|
|
44
|
|
|
return $this->categoryResolver->resolveAllByUrlKey($urlPath->getLastPart(), $storeId, $parentCategoryId); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param UrlPath $urlPath |
49
|
|
|
* @param int $storeId |
50
|
|
|
* |
51
|
|
|
* @return int |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
private function resolveParentCategoryId(UrlPath $urlPath, int $storeId) : int |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$parentCategoryId = $this->storeManager->getStore($storeId)->getRootCategoryId(); |
56
|
|
|
|
57
|
|
|
foreach ($urlPath->getBeginningParts() as $urlKey) { |
58
|
|
|
$parentCategoryId = $this->categoryResolver->resolveByUrlKey($urlKey, $storeId, $parentCategoryId)->getId(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $parentCategoryId; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.