Skip to content

Commit

Permalink
ref #89546 Добавлена возможность кастомизации генерации каталога (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocmonavtik authored Jul 24, 2023
1 parent 56ab4b4 commit 8832287
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 64 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2023-07-21 v.6.3.19
- Добавлена возможность кастомизации генерации каталога

## 2023-07-20 v.6.3.18
- Исправлена передача брошенных корзин

Expand Down
160 changes: 100 additions & 60 deletions intaro.retailcrm/RetailcrmClasspathBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class RetailcrmClasspathBuilder
*/
protected $notIncluded = [];

protected $directories = [];

/**
* These classes can be customized, in which case they would be replaced with files from
* directory <root>/bitrix/php_interface/retailcrm
Expand All @@ -75,19 +77,31 @@ class RetailcrmClasspathBuilder
* ]
*/
protected static $customizableClasses = [
'RestNormalizer' => 'RestNormalizer.php',
'Logger' => 'Logger.php',
'RetailCrm\ApiClient' => 'ApiClient_v5.php',
'RetailCrm\Http\Client' => 'Client.php',
'RCrmActions' => 'RCrmActions.php',
'RetailCrmUser' => 'RetailCrmUser.php',
'RetailCrmICML' => 'RetailCrmICML.php',
'RetailCrmInventories' => 'RetailCrmInventories.php',
'RetailCrmPrices' => 'RetailCrmPrices.php',
'RetailCrmCollector' => 'RetailCrmCollector.php',
'RetailCrmUa' => 'RetailCrmUa.php',
'RetailCrmEvent' => 'RetailCrmEvent.php',
'RetailCrmCorporateClient' => 'RetailCrmCorporateClient.php'
'classes' => [
'RestNormalizer' => 'RestNormalizer.php',
'Logger' => 'Logger.php',
'RetailCrm\ApiClient' => 'ApiClient_v5.php',
'RetailCrm\Http\Client' => 'Client.php',
'RCrmActions' => 'RCrmActions.php',
'RetailCrmUser' => 'RetailCrmUser.php',
'RetailCrmICML' => 'RetailCrmICML.php',
'RetailCrmInventories' => 'RetailCrmInventories.php',
'RetailCrmPrices' => 'RetailCrmPrices.php',
'RetailCrmCollector' => 'RetailCrmCollector.php',
'RetailCrmUa' => 'RetailCrmUa.php',
'RetailCrmEvent' => 'RetailCrmEvent.php',
'RetailCrmCorporateClient' => 'RetailCrmCorporateClient.php'
],
'lib/icml' => [
'Intaro\RetailCrm\Icml\XmlOfferBuilder' => 'xmlofferbuilder.php',
'Intaro\RetailCrm\Icml\XmlOfferDirector' => 'xmlofferdirector.php',
'Intaro\RetailCrm\Icml\IcmlWriter' => 'icmlwriter.php',
'Intaro\RetailCrm\Icml\QueryParamsMolder' => 'queryparamsmolder.php',
'Intaro\RetailCrm\Icml\SettingsService' => 'settingsservice.php',
'Intaro\RetailCrm\Icml\XmlCategoryDirector' => 'xmlcategorydirector.php',
'Intaro\RetailCrm\Icml\XmlCategoryFactory' => 'xmlcategoryfactory.php',
'Intaro\RetailCrm\Icml\IcmlDirector' => 'icmldirector.php'
]
];

/**
Expand All @@ -101,37 +115,46 @@ class RetailcrmClasspathBuilder
* ]
*/
protected static $versionedClasses = [
'RetailCrm\ApiClient' => ['ApiClient.php', 'ApiClient_%s.php'],
'RetailCrmOrder' => ['RetailCrmOrder.php', 'RetailCrmOrder_%s.php'],
'RetailCrmHistory' => ['RetailCrmHistory.php', 'RetailCrmHistory_%s.php'],
'RetailCrmCart' => ['RetailCrmCart.php', 'RetailCrmCart_%s.php']
'classes' => [
'RetailCrm\ApiClient' => ['ApiClient.php', 'ApiClient_%s.php'],
'RetailCrmOrder' => ['RetailCrmOrder.php', 'RetailCrmOrder_%s.php'],
'RetailCrmHistory' => ['RetailCrmHistory.php', 'RetailCrmHistory_%s.php'],
'RetailCrmCart' => ['RetailCrmCart.php', 'RetailCrmCart_%s.php']
],
'lib/icml' => []
];

/**
* These classes will be ignored while loading from original files
*/
protected static $ignoredClasses = [
'ApiClient_v4.php',
'ApiClient_v5.php',
'RetailCrmOrder_v4.php',
'RetailCrmOrder_v5.php',
'RetailCrmHistory_v4.php',
'RetailCrmHistory_v5.php',
'RetailCrmCart_v5.php',
'classes' => [
'ApiClient_v4.php',
'ApiClient_v5.php',
'RetailCrmOrder_v4.php',
'RetailCrmOrder_v5.php',
'RetailCrmHistory_v4.php',
'RetailCrmHistory_v5.php',
'RetailCrmCart_v5.php',
],
'lib/icml' => []
];

/**
* These namespaces are hardcoded.
*/
protected static $hardcodedNamespaces = [
'RetailCrm\Response\ApiResponse' => 'ApiResponse.php',
'RetailCrm\Exception\InvalidJsonException' => 'InvalidJsonException.php',
'RetailCrm\Exception\CurlException' => 'CurlException.php'
'classes' => [
'RetailCrm\Response\ApiResponse' => 'ApiResponse.php',
'RetailCrm\Exception\InvalidJsonException' => 'InvalidJsonException.php',
'RetailCrm\Exception\CurlException' => 'CurlException.php'
],
'lib/icml' => []
];

protected function buildCustomizableClasspath()
{
foreach (static::$customizableClasses as $className => $fileName) {
foreach (static::$customizableClasses[$this->path] as $className => $fileName) {
if (file_exists($this->documentRoot . $this->customizedFilesPath . $fileName)) {
$this->result[$className] = $this->customizedClassesPath . $fileName;
} else {
Expand All @@ -142,7 +165,7 @@ protected function buildCustomizableClasspath()

protected function buildVersionedClasspath()
{
foreach (static::$versionedClasses as $className => $fileNames) {
foreach (static::$versionedClasses[$this->path] as $className => $fileNames) {
if (file_exists($this->documentRoot . $this->customizedFilesPath . $fileNames[0])) {
$this->result[$className] = $this->customizedClassesPath . $fileNames[0];
} else {
Expand All @@ -157,39 +180,45 @@ protected function buildVersionedClasspath()
*/
public function build(): self
{
$directory = new RecursiveDirectoryIterator(
$this->getSearchPath(),
RecursiveDirectoryIterator::SKIP_DOTS
);
$fileIterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::LEAVES_ONLY);

$this->buildCustomizableClasspath();
$this->buildVersionedClasspath();
$notIncludedClasses = array_flip($this->notIncluded);
$hardcodedNamespaces = array_flip(static::$hardcodedNamespaces);

/** @var \SplFileObject $file */
foreach ($fileIterator as $file) {
$fileNameWithoutExt = str_ireplace('.' . $this->fileExt, '', $file->getFilename());

if ($file->getExtension() !== $this->fileExt) {
continue;
}
foreach ($this->directories as $path) {
$this->path = $path;

$directory = new RecursiveDirectoryIterator(
$this->getSearchPath(),
RecursiveDirectoryIterator::SKIP_DOTS
);

$fileIterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::LEAVES_ONLY);

$this->buildCustomizableClasspath();
$this->buildVersionedClasspath();

if (in_array($file->getFilename(), static::$customizableClasses)
|| in_array($file->getFilename(), static::$ignoredClasses)
) {
if (in_array($file->getFilename(), $this->notIncluded)) {
$this->result[$notIncludedClasses[$file->getFilename()]] = $this->getImportPath($file->getPathname());
$notIncludedClasses = array_flip($this->notIncluded);
$hardcodedNamespaces = array_flip(static::$hardcodedNamespaces[$path]);

/** @var \SplFileObject $file */
foreach ($fileIterator as $file) {
$fileNameWithoutExt = str_ireplace('.' . $this->fileExt, '', $file->getFilename());

if ($file->getExtension() !== $this->fileExt) {
continue;
}

continue;
}
if (in_array($file->getFilename(), static::$customizableClasses[$path])
|| in_array($file->getFilename(), static::$ignoredClasses[$path])
) {
if (in_array($file->getFilename(), $this->notIncluded)) {
$this->result[$notIncludedClasses[$file->getFilename()]] = $this->getImportPath($file->getPathname());
}

if (in_array($file->getFilename(), static::$hardcodedNamespaces)) {
$this->result[$hardcodedNamespaces[$file->getFilename()]] = $this->getImportPath($file->getPathname());
} else {
$this->result[$this->getImportClass($fileNameWithoutExt, $file->getPath())] = $this->getImportPath($file->getPathname());
continue;
}

if (in_array($file->getFilename(), static::$hardcodedNamespaces[$path])) {
$this->result[$hardcodedNamespaces[$file->getFilename()]] = $this->getImportPath($file->getPathname());
} else {
$this->result[$this->getImportClass($fileNameWithoutExt, $file->getPath())] = $this->getImportPath($file->getPathname());
}
}
}

Expand Down Expand Up @@ -223,16 +252,27 @@ public function setDocumentRoot(string $documentRoot): RetailcrmClasspathBuilder
/**
* Sets the $path property
*
* @param string $path Top path to load files
* @param array $path Top path to load files
*
* @return \RetailcrmClasspathBuilder
*/
public function setPath(string $path)
public function setPath(array $path)
{
$this->path = $path;
return $this;
}

/**
* @param array $directories
* @return \RetailcrmClasspathBuilder
*/
public function setDirectories(array $directories)
{
$this->directories = $directories;

return $this;
}

/**
* @param mixed $disableNamespaces
*
Expand Down
2 changes: 1 addition & 1 deletion intaro.retailcrm/description.ru
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Исправлена передача брошенных корзин
- Добавлена возможность кастомизации генерации каталога
2 changes: 1 addition & 1 deletion intaro.retailcrm/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$builder->setDisableNamespaces(true)
->setDocumentRoot($server)
->setModuleId($retailcrmModuleId)
->setPath('classes')
->setDirectories(['classes', 'lib/icml'])
->setVersion($version)
->build();

Expand Down
4 changes: 2 additions & 2 deletions intaro.retailcrm/install/version.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$arModuleVersion = [
'VERSION' => '6.3.18',
'VERSION_DATE' => '2023-07-20 14:00:00'
'VERSION' => '6.3.19',
'VERSION_DATE' => '2023-07-21 11:30:00'
];

0 comments on commit 8832287

Please sign in to comment.