Skip to content

Commit

Permalink
Merge commit 'a1561898e358fb9d7dca87c37455ea0692acd8db' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed May 31, 2023
2 parents 4807e57 + a156189 commit 898eb30
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 81 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"payum/payum-bundle": "^2.5",
"php-http/guzzle7-adapter": "^1.0",
"php-http/message-factory": "^1.0",
"pimcore/pimcore": "~10.6.1",
"pimcore/pimcore": "^10.5",
"rinvex/countries": "^7.3",
"sebastian/diff": "^4.0 | ^5.0",
"stof/doctrine-extensions-bundle": "^1.6",
Expand Down
4 changes: 2 additions & 2 deletions docs/03_Development/04_Cart/05_Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ $ bin/console coreshop:cart:expire --user
$ bin/console coreshop:cart:expire --days=20
```

## Expire Abandoned Carts via Maintenance Mode
## Expire Abandoned Carts via maintenance job
By default, this feature is disabled.
If you want to swipe abandoned carts by default you need to define a expiration date:
If you want to delete abandoned carts, you need to define an expiration date:

```yml
core_shop_order:
Expand Down
26 changes: 23 additions & 3 deletions src/CoreShop/Bundle/MenuBundle/Guard/PimcoreGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
namespace CoreShop\Bundle\MenuBundle\Guard;

use Knp\Menu\ItemInterface;
use Pimcore\Bundle\AdminBundle\Security\User\TokenStorageUserResolver;
use Pimcore\Model\User;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class PimcoreGuard
{
public function __construct(
private TokenStorageUserResolver $tokenStorageUserResolver,
private TokenStorageInterface $tokenStorage,
) {
}

Expand All @@ -35,7 +35,27 @@ public function matchItem(ItemInterface $item): bool
return true;
}

$user = $this->tokenStorageUserResolver->getUser();
$token = $this->tokenStorage->getToken();

if (null === $token) {
return false;
}

$user = $token->getUser();

if (class_exists(\Pimcore\Security\User\User::class) && $user instanceof \Pimcore\Security\User\User) {
/**
* @psalm-suppress UndefinedClass, UndefinedInterfaceMethod
*/
$user = $user->getUser();
}

if (class_exists(\Pimcore\Bundle\AdminBundle\Security\User\User::class) && $user instanceof \Pimcore\Bundle\AdminBundle\Security\User\User) {
/**
* @psalm-suppress UndefinedClass, UndefinedInterfaceMethod
*/
$user = $user->getUser();
}

if ($user instanceof User) {
return $user->isAllowed((string) $item->getAttribute('permission'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:

CoreShop\Bundle\MenuBundle\Guard\PimcoreGuard:
arguments:
- '@Pimcore\Bundle\AdminBundle\Security\User\TokenStorageUserResolver'
- '@security.token_storage'

coreshop.menu_provider.lazy_provider:
class: Knp\Menu\Provider\LazyProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function load(array $configs, ContainerBuilder $container): void
if (!array_key_exists('CoreShopCoreBundle', $bundles)) {
$loader->load('services/menu.yml');
}
else {
$loader->load('services/resource.yml');
}

$this->registerPimcoreResources('coreshop', $config['pimcore_admin'], $container);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@
use Pimcore\Event\BundleManager\PathsEvent;
use Pimcore\Event\BundleManagerEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface;

final class AdminJavascriptListener implements EventSubscriberInterface
{
public function __construct(
private RouterInterface $router,
) {
}

public static function getSubscribedEvents(): array
{
return [
Expand All @@ -41,7 +35,7 @@ public function getAdminJavascript(PathsEvent $event): void
{
$event->setPaths(
array_merge($event->getPaths(), [
$this->router->generate('coreshop_menu', ['type' => 'coreshop.messenger']),
'/bundles/coreshopmessenger/pimcore/js/resource.js',
]),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/*
* CoreShop
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - CoreShop Commercial License (CCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GPLv3 and CCL
*
*/

namespace CoreShop\Bundle\MessengerBundle\EventListener;

use Pimcore\Event\BundleManager\PathsEvent;
use Pimcore\Event\BundleManagerEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface;

final class StandaloneAdminJavascriptListener implements EventSubscriberInterface
{
public function __construct(
private RouterInterface $router,
) {
}

public static function getSubscribedEvents(): array
{
return [
BundleManagerEvents::JS_PATHS => 'getAdminJavascript',
];
}

public function getAdminJavascript(PathsEvent $event): void
{
$event->setPaths(
array_merge($event->getPaths(), [
$this->router->generate('coreshop_menu', ['type' => 'coreshop.messenger']),
'/bundles/coreshopmessenger/pimcore/js/resource_standalone.js',
]),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
core_shop_messenger:
pimcore_admin:
js:
resource: '/bundles/coreshopmessenger/pimcore/js/resource.js'
list: '/bundles/coreshopmessenger/pimcore/js/list.js'
css:
index: '/bundles/coreshopmessenger/pimcore/css/messenger.css'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
tags:
- { name: 'coreshop.menu', type: messenger, menu: messenger }

CoreShop\Bundle\MessengerBundle\EventListener\AdminJavascriptListener:
CoreShop\Bundle\MessengerBundle\EventListener\StandaloneAdminJavascriptListener:
arguments:
- '@router'
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
_defaults:
public: true

CoreShop\Bundle\MessengerBundle\EventListener\AdminJavascriptListener:
tags:
- { name: kernel.event_subscriber }
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,27 @@

pimcore.registerNS('coreshop.messenger.resource');

if (coreshop.resource !== undefined) {
coreshop.messenger.resource = Class.create(coreshop.resource, {
initialize: function () {
coreshop.broker.fireEvent('resource.register', 'coreshop.messenger', this);
},

openResource: function(item) {
if (item === 'list') {
this.openList();
}
},

openList: function() {
try {
pimcore.globalmanager.get('coreshop_messenger_list').activate();
}
catch (e) {
pimcore.globalmanager.add('coreshop_messenger_list', new coreshop.messenger.list());
}
},
});

coreshop.broker.addListener('pimcore.ready', function() {
new coreshop.messenger.resource();
});
} else {
coreshop.messenger.resource = Class.create(pimcore.plugin.admin, {
initialize: function () {
var me = this;

document.addEventListener(pimcore.events.pimcoreReady, (e) => {
if (coreshop.menu.coreshop.messenger) {
new coreshop.menu.coreshop.messenger();
}
});

document.addEventListener(coreshop.events.menu.open, (e) => {
var item = e.detail.item;
var type = e.detail.type;

if (type === 'coreshop.messenger' && item.attributes.function === 'list') {
me.openList();
}
});
},

openList: function () {
try {
pimcore.globalmanager.get('coreshop_messenger_list').activate();
} catch (e) {
pimcore.globalmanager.add('coreshop_messenger_list', new coreshop.messenger.list());
}
},
});
coreshop.messenger.resource = Class.create(coreshop.resource, {
initialize: function () {
coreshop.broker.fireEvent('resource.register', 'coreshop.messenger', this);
},

openResource: function(item) {
if (item === 'list') {
this.openList();
}
},

openList: function() {
try {
pimcore.globalmanager.get('coreshop_messenger_list').activate();
}
catch (e) {
pimcore.globalmanager.add('coreshop_messenger_list', new coreshop.messenger.list());
}
},
});

coreshop.broker.addListener('pimcore.ready', function() {
new coreshop.messenger.resource();
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

/*
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GPLv3 and CCL
*
*/

pimcore.registerNS('coreshop.messenger.resource');

coreshop.messenger.resource = Class.create(pimcore.plugin.admin, {
initialize: function () {
var me = this;

document.addEventListener(pimcore.events.pimcoreReady, (e) => {
if (coreshop.menu.coreshop.messenger) {
new coreshop.menu.coreshop.messenger();
}
});

document.addEventListener(coreshop.events.menu.open, (e) => {
var item = e.detail.item;
var type = e.detail.type;

if (type === 'coreshop.messenger' && item.attributes.function === 'list') {
me.openList();
}
});
},

openList: function () {
try {
pimcore.globalmanager.get('coreshop_messenger_list').activate();
} catch (e) {
pimcore.globalmanager.add('coreshop_messenger_list', new coreshop.messenger.list());
}
},
});
new coreshop.messenger.resource();
12 changes: 10 additions & 2 deletions src/CoreShop/Bundle/OrderBundle/Renderer/Pdf/WkHtmlToPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,17 @@ private function convert($httpSource, $config = []): string
return $pdfContent;
}

private function unlinkFile($file): void
private function unlinkFile(?string $file): void
{
@unlink($file);
if ($file === null) {
return;
}

if (!file_exists($file)) {
return;
}

unlink($file);
}

private function getWkHtmlToPdfBinary(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public function getDataForGrid($data, $object = null, $params = [])

public function getVersionPreview($data, $object = null, $params = [])
{
return $this->getDataFromResource($data, $object, $params);
$data = $this->getDataFromResource($data, $object, $params);

return is_array($data) ? serialize($data) : '--';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use Doctrine\Persistence\ObjectManager;
use Pimcore\Model\DataObject;
use Pimcore\Model\User;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Expand Down Expand Up @@ -55,12 +54,21 @@ protected function isGrantedOr403(): void
if ($this->metadata->hasParameter('permission')) {
$permission = sprintf('%s_permission_%s', $this->metadata->getApplicationName(), $this->metadata->getParameter('permission'));

/**
* @var User $user
*
* @psalm-var User $user
*/
$user = method_exists($this, 'getAdminUser') ? $this->getAdminUser() : $this->getUser();
$user = $this->getUser();

if (class_exists(\Pimcore\Security\User\User::class) && $user instanceof \Pimcore\Security\User\User) {
/**
* @psalm-suppress UndefinedClass, UndefinedInterfaceMethod
*/
$user = $user->getUser();
} elseif (class_exists(\Pimcore\Bundle\AdminBundle\Security\User\User::class) && $user instanceof \Pimcore\Bundle\AdminBundle\Security\User\User) {
/**
* @psalm-suppress UndefinedClass, UndefinedInterfaceMethod
*/
$user = $user->getUser();
} else {
throw new \RuntimeException(sprintf('Unknown Pimcore Admin User Class given "%s"', get_class($user)));
}

if ($user->isAllowed($permission)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/CoreShop/Component/Order/Modifier/VoucherModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function decrement(OrderInterface $order): void
continue;
}

if (!$item->getVoucherCode()) {
continue;
}

$voucherCode = $this->voucherCodeRepository->findByCode($item->getVoucherCode());
if ($voucherCode instanceof CartPriceRuleVoucherCodeInterface) {
if ($voucherCode->getUses() !== 0) {
Expand Down

0 comments on commit 898eb30

Please sign in to comment.