Skip to content

Commit

Permalink
Merge branch '4.0' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Aug 19, 2024
2 parents 7ae9a15 + e725540 commit 86bf75b
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 27 deletions.
1 change: 1 addition & 0 deletions phpstan-package.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parameters:
- '**/DataHub/*.php'
- 'vendor/***'
- 'Core/EventListener/SessionStoreStorageListSubscriber.php'
- 'Core/EventListener/SessionStoreStorageListLogoutSubscriber.php'
- 'Core/EventListener/StorageListBlamerListener.php'
- 'Core/Context/CustomerAndStoreBasedStorageListContext.php'
- 'Core/Context/SessionAndStoreBasedStorageListContext.php'
Expand Down
17 changes: 17 additions & 0 deletions src/CoreShop/Bundle/CurrencyBundle/CoreExtension/MoneyCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace CoreShop\Bundle\CurrencyBundle\CoreExtension;

use Carbon\Carbon;
use CoreShop\Bundle\ResourceBundle\Pimcore\CacheMarshallerInterface;
use CoreShop\Component\Currency\Model\CurrencyInterface;
use CoreShop\Component\Currency\Model\Money;
Expand Down Expand Up @@ -219,6 +220,22 @@ public function getDataFromEditmode(mixed $data, Concrete $object = null, array
return null;
}

public function getDataForGrid(?Money $data, Concrete $object = null, array $params = []): ?array
{
if (null === $data) {
return null;
}

return [
'value' => $data->getValue(),
'currency' => [
'id' => $data->getCurrency()?->getId(),
'name' => $data->getCurrency()?->getName(),
'isoCode' => $data->getCurrency()?->getIsoCode(),
]
];
}

public function getVersionPreview(mixed $data, Concrete $object = null, array $params = []): string
{
return (string) $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ pimcore.object.tags.coreShopMoneyCurrency = Class.create(pimcore.object.tags.abs
return this.component;
},

getGridColumnConfig:function (field) {
var renderer = function (key, value, metaData, record) {
this.applyPermissionStyle(key, value, metaData, record);

try {
if (record.data.inheritedFields && record.data.inheritedFields[key] && record.data.inheritedFields[key].inherited == true) {
metaData.tdCls += " grid_value_inherited";
}
} catch (e) {
console.log(e);
}

if (!value) {
return '';
}

return Ext.util.Format.htmlEncode(coreshop.util.format.currency(value.currency.isoCode, value.value));

}.bind(this, field.key);

return {text: t(field.label), sortable:true, dataIndex:field.key, renderer:renderer,
editor:this.getGridColumnEditor(field)};
},

getLayoutShow: function ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ pimcore.object.tags.coreShopMoney = Class.create(pimcore.object.tags.abstract, {
}
},

getGridColumnConfig:function (field) {
var renderer = function (key, value, metaData, record) {
this.applyPermissionStyle(key, value, metaData, record);

try {
if (record.data.inheritedFields && record.data.inheritedFields[key] && record.data.inheritedFields[key].inherited == true) {
metaData.tdCls += " grid_value_inherited";
}
} catch (e) {
console.log(e);
}

return Ext.util.Format.htmlEncode(coreshop.util.format.number(value));

}.bind(this, field.key);

return {text: t(field.label), sortable:true, dataIndex:field.key, renderer:renderer,
editor:this.getGridColumnEditor(field)};
},

getGridColumnFilter: function (field)
{
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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\StorageListBundle\Core\EventListener;

use CoreShop\Component\StorageList\Context\StorageListContextInterface;
use CoreShop\Component\StorageList\Context\StorageListNotFoundException;
use CoreShop\Component\Store\Model\StoreAwareInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;

final class SessionStoreStorageListLogoutSubscriber
{
public function __construct(
private StorageListContextInterface $context,
private string $sessionKeyName,
) {
}

public function onLogoutSuccess(LogoutEvent $event): void
{
$request = $event->getRequest();

if (!$request->hasSession()) {
return;
}

if ($request->attributes->get('_stateless', false)) {
return;
}

$request = $event->getRequest();

try {
$storageList = $this->context->getStorageList();
} catch (StorageListNotFoundException) {
return;
}

if (!$storageList instanceof StoreAwareInterface) {
return;
}

if (null !== $storageList->getStore()) {
$session = $request->getSession();

$session->remove(sprintf('%s.%s', $this->sessionKeyName, $storageList->getStore()->getId()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private function addStorageListSection(ArrayNodeDefinition $node): void
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultFalse()->end()
->booleanNode('enable_logout_subscriber')->defaultFalse()->end()
->scalarNode('key')->defaultValue('storage_list')->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace CoreShop\Bundle\StorageListBundle\DependencyInjection;

use CoreShop\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractModelExtension;
use CoreShop\Bundle\StorageListBundle\Core\EventListener\SessionStoreStorageListLogoutSubscriber;
use CoreShop\Bundle\StorageListBundle\Core\EventListener\SessionStoreStorageListSubscriber;
use CoreShop\Bundle\StorageListBundle\Core\EventListener\StorageListBlamerListener;
use CoreShop\Bundle\StorageListBundle\EventListener\CacheListener;
Expand Down Expand Up @@ -50,6 +51,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Security\Http\Event\LogoutEvent;

final class CoreShopStorageListExtension extends AbstractModelExtension
{
Expand Down Expand Up @@ -283,6 +285,25 @@ public function load(array $configs, ContainerBuilder $container): void
$sessionAndStoreSubscriber->addTag('kernel.event_subscriber');

$container->setDefinition('coreshop.storage_list.session_and_store_subscriber.' . $name, $sessionAndStoreSubscriber);

if ($list['session']['enable_logout_subscriber']) {
$logoutSubscriber = new Definition(SessionStoreStorageListLogoutSubscriber::class);
$logoutSubscriber->setArgument('$context', new Reference($contextCompositeServiceName));
$logoutSubscriber->setArgument('$sessionKeyName', $list['session']['key']);
$logoutSubscriber->addTag(
'kernel.event_listener',
[
'event' => LogoutEvent::class,
'method' => 'onLogoutSuccess',
'dispatcher' => 'security.event_dispatcher.coreshop_frontend'
]
);

$container->setDefinition(
'coreshop.storage_list.logout_subscriber.'.$name,
$logoutSubscriber
);
}
}

$blamer = new Definition(StorageListBlamerListener::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ core_shop_storage_list:
enable_default_store_based_decorator: true
session:
enabled: true
enable_logout_subscriber: true
key: 'coreshop.wishlist'
form:
type: CoreShop\Bundle\WishlistBundle\Form\Type\WishlistType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

final class SessionAndStoreBasedStorageListContext implements StorageListContextInterface
{
private ?StorageListInterface $storageList = null;

public function __construct(
private StorageListStorageInterface $storageListStorage,
private StoreContextInterface $storeContext,
Expand All @@ -38,10 +36,6 @@ public function __construct(

public function getStorageList(): StorageListInterface
{
if (null !== $this->storageList && !$this->storageListStorage->gotReset()) {
return $this->storageList;
}

try {
$store = $this->storeContext->getStore();
} catch (StoreNotFoundException $exception) {
Expand Down Expand Up @@ -75,8 +69,6 @@ public function getStorageList(): StorageListInterface
throw new StorageListNotFoundException('CoreShop was not able to find the List in session');
}

$this->storageList = $storageList;

return $storageList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

class SessionStorageListStorage implements StorageListStorageInterface
{
private bool $gotReset = true;

public function __construct(
private RequestStack $requestStack,
private string $sessionKeyName,
Expand All @@ -46,18 +44,12 @@ public function hasForContext(array $context): bool
return $this->getSession()->has($this->getKeyName($context));
}

public function gotReset(): bool
{
return $this->gotReset;
}

public function getForContext(array $context): ?StorageListInterface
{
if (!$this->hasSession()) {
return null;
}

$this->gotReset = false;
if ($this->hasForContext($context)) {
$storageListId = $this->getSession()->get($this->getKeyName($context));

Expand All @@ -77,7 +69,6 @@ public function setForContext(array $context, StorageListInterface $storageList)
throw new \InvalidArgumentException('Session is not available');
}

$this->gotReset = true;
$this->getSession()->set($this->getKeyName($context), $storageList->getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

class SimpleStorageListStorage implements StorageListStorageInterface
{
private bool $gotReset = true;
private array $simple = [];

public function hasForContext(array $context): bool
Expand All @@ -34,18 +33,12 @@ public function hasForContext(array $context): bool
return array_key_exists('coreshop.cart', $this->simple);
}

public function gotReset(): bool
{
return $this->gotReset;
}

public function getForContext(array $context): ?StorageListInterface
{
if (!isset($this->simple['coreshop.cart'])) {
return null;
}

$this->gotReset = false;
if ($this->hasForContext($context)) {
return $this->simple['coreshop.cart'];
}
Expand All @@ -55,7 +48,6 @@ public function getForContext(array $context): ?StorageListInterface

public function setForContext(array $context, StorageListInterface $storageList): void
{
$this->gotReset = true;
$this->simple['coreshop.cart'] = $storageList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ public function getForContext(array $context): ?StorageListInterface;
public function setForContext(array $context, StorageListInterface $storageList): void;

public function removeForContext(array $context): void;

public function gotReset(): bool;
}

0 comments on commit 86bf75b

Please sign in to comment.