-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d0790c
commit 0fc0d29
Showing
33 changed files
with
1,583 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
return [ | ||
/** | ||
* | ||
*/ | ||
'exchange_path' => 'exchange-1c', | ||
/** | ||
* | ||
*/ | ||
'import_dir' => storage_path('app/exchange-1c'), | ||
/** | ||
* | ||
*/ | ||
'login' => env('EXCHANGE_1C_LOGIN', 'admin'), | ||
/** | ||
* | ||
*/ | ||
'password' => env('EXCHANGE_1C_PASSWORD', 'admin'), | ||
/** | ||
* | ||
*/ | ||
'use_zip' => false, | ||
/** | ||
* | ||
*/ | ||
'file_part' => 0, | ||
/** | ||
* | ||
*/ | ||
'models' => [ | ||
\Altynbek07\Exchange1C\Interfaces\GroupInterface::class => \App\Models\Category::class, | ||
\Altynbek07\Exchange1C\Interfaces\ProductInterface::class => \App\Models\Product::class, | ||
\Altynbek07\Exchange1C\Interfaces\OfferInterface::class => \App\Models\Offer::class, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
$path = config('exchange-1c.exchange_path', 'exchange-1c'); | ||
|
||
Route::group(['middleware' => [\Illuminate\Session\Middleware\StartSession::class]], function () use ($path) { | ||
Route::match(['get', 'post'], $path, Altynbek07\Exchange1C\Controllers\ImportController::class.'@request'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<?php | ||
|
||
namespace Altynbek07\Exchange1C; | ||
|
||
/** | ||
* Class Config. | ||
*/ | ||
class Config | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $importDir = 'import_dir'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $login = 'admin'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $password = 'admin'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $useZip = false; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $filePart = 0; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $models = [ | ||
\Altynbek07\Exchange1C\Interfaces\GroupInterface::class => null, | ||
\Altynbek07\Exchange1C\Interfaces\ProductInterface::class => null, | ||
\Altynbek07\Exchange1C\Interfaces\OfferInterface::class => null, | ||
]; | ||
|
||
/** | ||
* Config constructor. | ||
* | ||
* @param array $config | ||
*/ | ||
public function __construct(array $config = []) | ||
{ | ||
$this->configure($config); | ||
} | ||
|
||
/** | ||
* Overrides default configuration settings. | ||
* | ||
* @param array $config | ||
*/ | ||
private function configure(array $config = []): void | ||
{ | ||
foreach ($config as $param => $value) { | ||
$property = $this->toCamelCase($param); | ||
if (property_exists(self::class, $property)) { | ||
$this->$property = $value; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getImportDir(): string | ||
{ | ||
return $this->importDir; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLogin(): string | ||
{ | ||
return $this->login; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPassword(): string | ||
{ | ||
return $this->password; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isUseZip(): bool | ||
{ | ||
return $this->useZip; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getFilePart(): int | ||
{ | ||
return $this->filePart; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getModels(): array | ||
{ | ||
return $this->models; | ||
} | ||
|
||
/** | ||
* @param string $modelName | ||
* | ||
* @return null|string | ||
*/ | ||
public function getModelClass(string $modelName): ?string | ||
{ | ||
if (isset($this->models[$modelName])) { | ||
return $this->models[$modelName]; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param string $filename | ||
* | ||
* @return string | ||
*/ | ||
public function getFullPath(string $filename): string | ||
{ | ||
return $this->getImportDir() . DIRECTORY_SEPARATOR . $filename; | ||
} | ||
|
||
/** | ||
* Translates a string with underscores into camel case (e.g. first_name -> firstName). | ||
* | ||
* @param string $str String in underscore format | ||
* | ||
* @return string $str translated into camel caps | ||
*/ | ||
private function toCamelCase($str): string | ||
{ | ||
$func = function ($c) { | ||
return strtoupper($c[1]); | ||
}; | ||
|
||
return preg_replace_callback('/_([a-z])/', $func, $str); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Altynbek07\Exchange1C\Controllers; | ||
|
||
use Altynbek07\Exchange1C\Exceptions\Exchange1CException; | ||
use Altynbek07\Exchange1C\Services\CatalogService; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Routing\Controller; | ||
|
||
/** | ||
* Class ImportController. | ||
*/ | ||
class ImportController extends Controller | ||
{ | ||
/** | ||
* @param Request $request | ||
* @param CatalogService $service | ||
* | ||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response | ||
*/ | ||
public function request(Request $request, CatalogService $service) | ||
{ | ||
$mode = $request->get('mode'); | ||
$type = $request->get('type'); | ||
|
||
try { | ||
if ($type == 'catalog') { | ||
if (!method_exists($service, $mode)) { | ||
throw new Exchange1CException('not correct request, class ExchangeCML not found'); | ||
} | ||
|
||
$response = $service->$mode(); | ||
\Log::debug('exchange_1c: $response='."\n".$response); | ||
|
||
return response($response, 200, ['Content-Type', 'text/plain']); | ||
} else { | ||
throw new \LogicException(sprintf('Logic for method %s not released', $type)); | ||
} | ||
} catch (Exchange1CException $e) { | ||
\Log::error("exchange_1c: failure \n".$e->getMessage()."\n".$e->getFile()."\n".$e->getLine()."\n"); | ||
|
||
$response = "failure\n"; | ||
$response .= $e->getMessage()."\n"; | ||
$response .= $e->getFile()."\n"; | ||
$response .= $e->getLine()."\n"; | ||
|
||
return response($response, 500, ['Content-Type', 'text/plain']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Altynbek07\Exchange1C\Events; | ||
|
||
/** | ||
* Class AbstractEventInterface. | ||
*/ | ||
abstract class AbstractEventInterface implements \Altynbek07\Exchange1C\Interfaces\EventInterface | ||
{ | ||
public const NAME = self::class; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return self::NAME; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Altynbek07\Exchange1C\Events; | ||
|
||
class AfterOffersSync extends AbstractEventInterface | ||
{ | ||
const NAME = 'after.offers.sync'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $ids; | ||
|
||
/** | ||
* AfterOffersSync constructor. | ||
* | ||
* @param array $ids | ||
*/ | ||
public function __construct(array $ids = []) | ||
{ | ||
$this->ids = $ids; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Altynbek07\Exchange1C\Events; | ||
|
||
class AfterProductsSync extends AbstractEventInterface | ||
{ | ||
const NAME = 'after.products.sync'; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $ids; | ||
|
||
/** | ||
* AfterProductsSync constructor. | ||
* | ||
* @param array $ids | ||
*/ | ||
public function __construct(array $ids = []) | ||
{ | ||
$this->ids = $ids; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Altynbek07\Exchange1C\Events; | ||
|
||
use Altynbek07\Exchange1C\Interfaces\OfferInterface; | ||
use Zenwalker\CommerceML\Model\Offer; | ||
|
||
class AfterUpdateOffer extends AbstractEventInterface | ||
{ | ||
const NAME = 'after.update.offer'; | ||
|
||
/** | ||
* @var OfferInterface | ||
*/ | ||
public $model; | ||
|
||
/** | ||
* @var Offer | ||
*/ | ||
public $offer; | ||
|
||
/** | ||
* AfterUpdateOffer constructor. | ||
* | ||
* @param OfferInterface $model | ||
* @param Offer $offer | ||
*/ | ||
public function __construct(OfferInterface $model, Offer $offer) | ||
{ | ||
$this->model = $model; | ||
$this->offer = $offer; | ||
} | ||
} |
Oops, something went wrong.