Skip to content

Commit 55bfaef

Browse files
committed
Merge branch '3.2' into 4.0
* 3.2: [ResourceBundle] Version Marshalling for FieldCollections - psalm [ResourceBundle] Version Marshalling for FieldCollections [priceNull - 3.2] - add listener for null/empty price on field [PimcoreBundle] fix MultiSelect (check for existing store)
2 parents e73e3ae + 006604f commit 55bfaef

File tree

5 files changed

+143
-1
lines changed

5 files changed

+143
-1
lines changed

src/CoreShop/Bundle/CoreBundle/Resources/public/pimcore/js/product/storevalues/items/price.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ coreshop.product.storeValues.items.price = Class.create(coreshop.product.storeVa
5151
priceField.setMaxValue(this.builder.fieldConfig.maxValue);
5252
}
5353

54+
priceField.on('blur', function (field) {
55+
var value = field.getValue();
56+
if (value === null || value === '') {
57+
field.setValue(0);
58+
}
59+
});
60+
5461
priceField.resumeEvents(true);
5562

5663
return priceField;

src/CoreShop/Bundle/PimcoreBundle/Resources/public/pimcore/js/ext/MultiSelect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Ext.define('Ext.ux.form.MultiSelect', {
142142

143143
me.bindStore(me.store, true);
144144

145-
if (me.store.autoCreated) {
145+
if (me.store?.autoCreated) {
146146
me.valueField = me.displayField = 'field1';
147147
if (!me.store.expanded) {
148148
me.displayField = 'field2';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* CoreShop
7+
*
8+
* This source file is available under two different licenses:
9+
* - GNU General Public License version 3 (GPLv3)
10+
* - CoreShop Commercial License (CCL)
11+
* Full copyright and license information is available in
12+
* LICENSE.md which is distributed with this source code.
13+
*
14+
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
15+
* @license https://www.coreshop.org/license GPLv3 and CCL
16+
*
17+
*/
18+
19+
namespace CoreShop\Bundle\ResourceBundle\DeepCopy;
20+
21+
use DeepCopy\Matcher\Matcher;
22+
use Pimcore\Model\DataObject\Fieldcollection;
23+
24+
class PimcoreFieldCollectionDefinitionMatcher implements Matcher
25+
{
26+
public function __construct(private string $matchType)
27+
{
28+
}
29+
30+
public function matches(mixed $object, mixed $property): bool
31+
{
32+
if ($object instanceof Fieldcollection\Data\AbstractData) {
33+
$collectionDef = Fieldcollection\Definition::getByKey($object->getType());
34+
35+
if ($collectionDef instanceof Fieldcollection\Definition) {
36+
return $collectionDef->getFieldDefinition($property) instanceof $this->matchType;
37+
}
38+
}
39+
40+
return false;
41+
}
42+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* CoreShop
7+
*
8+
* This source file is available under two different licenses:
9+
* - GNU General Public License version 3 (GPLv3)
10+
* - CoreShop Commercial License (CCL)
11+
* Full copyright and license information is available in
12+
* LICENSE.md which is distributed with this source code.
13+
*
14+
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
15+
* @license https://www.coreshop.org/license GPLv3 and CCL
16+
*
17+
*/
18+
19+
namespace CoreShop\Bundle\ResourceBundle\DeepCopy;
20+
21+
use DeepCopy\Filter\Filter;
22+
use DeepCopy\Reflection\ReflectionHelper;
23+
use Pimcore\Model\DataObject\Concrete;
24+
use Pimcore\Model\DataObject\Fieldcollection;
25+
26+
class PimcoreFieldCollectionDefinitionReplaceFilter implements Filter
27+
{
28+
public function __construct(protected \Closure $callback)
29+
{
30+
}
31+
32+
public function apply($object, $property, $objectCopier)
33+
{
34+
if (!$object instanceof Fieldcollection\Data\AbstractData) {
35+
return;
36+
}
37+
38+
$fieldDefinition = $object->getDefinition()->getFieldDefinition($property);
39+
40+
if (!$fieldDefinition) {
41+
return;
42+
}
43+
44+
$reflectionProperty = ReflectionHelper::getProperty($object, $property);
45+
$reflectionProperty->setAccessible(true);
46+
47+
$value = ($this->callback)($object, $fieldDefinition, $property, $reflectionProperty->getValue($object));
48+
49+
$reflectionProperty->setValue($object, $value);
50+
}
51+
}

src/CoreShop/Bundle/ResourceBundle/EventListener/DeepCopySubscriber.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@
1818

1919
namespace CoreShop\Bundle\ResourceBundle\EventListener;
2020

21+
use CoreShop\Bundle\ResourceBundle\DeepCopy\PimcoreFieldCollectionDefinitionMatcher;
22+
use CoreShop\Bundle\ResourceBundle\DeepCopy\PimcoreFieldCollectionDefinitionReplaceFilter;
2123
use CoreShop\Bundle\ResourceBundle\Pimcore\CacheMarshallerInterface;
24+
use CoreShop\Component\Resource\Model\ResourceInterface;
2225
use DeepCopy\DeepCopy;
2326
use DeepCopy\Filter\Doctrine\DoctrineCollectionFilter;
2427
use DeepCopy\Matcher\PropertyTypeMatcher;
2528
use DeepCopy\TypeMatcher\TypeMatcher;
2629
use Pimcore\Event\SystemEvents;
30+
use Pimcore\Model\DataObject\ClassDefinition\Data;
2731
use Pimcore\Model\DataObject\Concrete;
32+
use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData;
33+
use Pimcore\Model\Element\DeepCopy\PimcoreClassDefinitionMatcher;
34+
use Pimcore\Model\Element\DeepCopy\PimcoreClassDefinitionReplaceFilter;
2835
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2936
use Symfony\Component\EventDispatcher\GenericEvent;
3037

@@ -55,6 +62,41 @@ public function addDoctrineCollectionFilter(GenericEvent $event): void
5562
$event->setArgument('copier', $copier);
5663
}
5764

65+
if (($context['source'] ?? false) === 'Pimcore\Model\Version::marshalData') {
66+
/**
67+
* Pimcore handles CustomVersionMarshallInterface for Objects, but not for Fieldcollections
68+
* this means that our custom types, get fully copied and serialized in to the version file
69+
* meaning that for Cart Price Rules, you can end up serializing 100MB of data.... 🙈
70+
*/
71+
$copier->addFilter(
72+
new PimcoreFieldCollectionDefinitionReplaceFilter(
73+
function (AbstractData $object, Data $fieldDefinition, mixed $property, mixed $currentValue): mixed {
74+
if ($fieldDefinition instanceof Data\CustomVersionMarshalInterface) {
75+
return $fieldDefinition->marshalVersion($object->getObject(), $currentValue);
76+
}
77+
78+
return $currentValue;
79+
}
80+
),
81+
new PimcoreFieldCollectionDefinitionMatcher(Data\CustomVersionMarshalInterface::class)
82+
);
83+
}
84+
85+
if (($context['source'] ?? false) === 'Pimcore\Model\Version::unmarshalData') {
86+
$copier->addFilter(
87+
new PimcoreFieldCollectionDefinitionReplaceFilter(
88+
function (AbstractData $object, Data $fieldDefinition, mixed $property, mixed $currentValue): mixed {
89+
if ($fieldDefinition instanceof Data\CustomVersionMarshalInterface) {
90+
return $fieldDefinition->unmarshalVersion($object->getObject(), $currentValue);
91+
}
92+
93+
return $currentValue;
94+
}
95+
),
96+
new PimcoreFieldCollectionDefinitionMatcher(Data\CustomVersionMarshalInterface::class)
97+
);
98+
}
99+
58100
if (($context['source'] ?? false) === 'Pimcore\Cache\Core\CoreCacheHandler::storeCacheData') {
59101
/**
60102
* This honestly absolutely sucks:

0 commit comments

Comments
 (0)