Skip to content

Commit c051c68

Browse files
committed
fix store and language mutation
1 parent 9484b1c commit c051c68

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/Event/Dispatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ private function check(string $category, string $endpoint, Variables $variables)
7171
else
7272
{
7373
$language = $variables['lang_id'] ?? 'en';
74-
$store_id = $variables['store_id'] ?? 0;
74+
$shop_id = $variables['shop_id'] ?? 0;
7575
$category = str_replace('-', '_', $category);
7676

7777
if (!in_array($this->settings->load('main:language_mutation'), [1, true, '1'], true))
7878
{
7979
$language = 'default';
8080
}
8181

82-
foreach (["admin_sms-default-$store_id", "customer_sms-$language-$store_id"] as $scope)
82+
foreach (["admin_sms-default-$shop_id", "customer_sms-$language-$shop_id"] as $scope)
8383
{
8484
if ($category === 'order' && $endpoint === 'status_change' && isset($variables['order_status_id']))
8585
{

src/Event/Hook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function dispatch(string $category, string $endpoint, array $variables):
4040
$category = str_replace('_', '-', $category);
4141
$endpoint = str_replace('_', '-', $endpoint);
4242

43-
$this->send("api/$this->version/eshop/$category/$endpoint", ['variables' => $variables]);
43+
$this->send("api/$this->version/eshop/$category/$endpoint", ['language' => $variables['lang_id'] ?? null, 'shop_id' => $variables['shop_id'] ?? null, 'variables' => $variables]);
4444
}
4545

4646

tests/Event/HookTest.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ class HookTest extends TestCase
2626

2727
$connection->shouldReceive('run')->once()->with(Mockery::on(function (Request $request): bool
2828
{
29-
Assert::same('{"variables":{"test":"test"}}', $request->serialize());
29+
Assert::same('{"language":"cs","shop_id":1,"variables":{"test":"test","shop_id":1,"lang_id":"cs"}}', $request->serialize());
3030
Assert::same('https://portal.bulkgate.com/api/1.0/eshop/order/new', $request->url);
3131

3232
return true;
3333
}));
3434

3535
$variables = new Variables();
3636
$variables['test'] = 'test';
37+
$variables['shop_id'] = 1;
38+
$variables['lang_id'] = 'cs';
3739

3840
$hook->dispatch('order', 'new', $variables->toArray());
3941

@@ -47,7 +49,7 @@ class HookTest extends TestCase
4749

4850
$hook = new Hook($version, $connection = Mockery::mock(Connection::class), new Url(), $logger = Mockery::mock(Logger::class));
4951
$connection->shouldReceive('run')->once()->andThrow(InvalidResponseException::class, 'error_test');
50-
$logger->shouldReceive('log')->with('Hook Error: \'api/1.0/eshop/order/new\' - error_test, {"variables":{"test":"test"}}')->once();
52+
$logger->shouldReceive('log')->with('Hook Error: \'api/1.0/eshop/order/new\' - error_test, {"language":null,"shop_id":null,"variables":{"test":"test"}}')->once();
5153

5254
$variables = new Variables();
5355
$variables['test'] = 'test';

0 commit comments

Comments
 (0)