Skip to content

Commit 7694583

Browse files
DzemalBecirevicdvesh3
authored andcommitted
Update DefaultCustomerProvider.php
Enable DefaultCustomerProvider to have support for class overrides.
1 parent ff76844 commit 7694583

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/CustomerProvider/DefaultCustomerProvider.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ class DefaultCustomerProvider implements CustomerProviderInterface
4343
* @var Factory
4444
*/
4545
protected $modelFactory;
46+
47+
/**
48+
* @var bool
49+
*/
50+
protected $usesClassOverride = false;
51+
52+
/**
53+
* @var null|string
54+
*/
55+
protected $classNameWithoutNamespace = null;
4656

4757
/**
4858
* DefaultCustomerProvider constructor.
@@ -58,8 +68,16 @@ public function __construct($pimcoreClass, $parentPath, ObjectNamingSchemeInterf
5868
throw new \RuntimeException('Customer class is not defined');
5969
}
6070

61-
if (!class_exists('Pimcore\\Model\\DataObject\\' . $pimcoreClass)) {
62-
throw new \RuntimeException(sprintf('Configured CMF customer data object class "%s" does not exist.', $pimcoreClass));
71+
if (!class_exists($pimcoreClass)) {
72+
if (!class_exists('Pimcore\\Model\\DataObject\\' . $pimcoreClass)) {
73+
throw new \RuntimeException(sprintf('Configured CMF customer data object class "%s" does not exist.', $pimcoreClass));
74+
}
75+
} else {
76+
$this->usesClassOverride = true;
77+
78+
// Get ending of classname for listings.
79+
$explodedClassName = explode('\\', $pimcoreClass);
80+
$this->classNameWithoutNamespace = end($explodedClassName);
6381
}
6482

6583
$this->parentPath = $parentPath;
@@ -78,6 +96,10 @@ public function __construct($pimcoreClass, $parentPath, ObjectNamingSchemeInterf
7896
*/
7997
protected function getDiClassName()
8098
{
99+
if ($this->usesClassOverride) {
100+
return $this->pimcoreClass;
101+
}
102+
81103
return sprintf('Pimcore\Model\DataObject\%s', $this->pimcoreClass);
82104
}
83105

@@ -86,6 +108,11 @@ protected function getDiClassName()
86108
*/
87109
protected function getDiListingClassName()
88110
{
111+
if ($this->usesClassOverride) {
112+
// Check if Listing class exists in default namespace
113+
return sprintf('Pimcore\Model\DataObject\%s\Listing', $this->classNameWithoutNamespace);
114+
}
115+
89116
return sprintf('Pimcore\Model\DataObject\%s\Listing', $this->pimcoreClass);
90117
}
91118

0 commit comments

Comments
 (0)