Skip to content

Commit

Permalink
Merge branch 'next-17107/cherry-picks-1' into '6.4.4.1'
Browse files Browse the repository at this point in the history
NEXT-17107 - Cherry picks

See merge request shopware/6/product/platform!6366
  • Loading branch information
pweyck committed Sep 10, 2021
2 parents 5dc6f92 + 4401acd commit 08b0bd5
Show file tree
Hide file tree
Showing 22 changed files with 637 additions and 65 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Changelog
This is the official changelog index of Shopware 6. Here you find a registry of all Shopware 6 releases with a reference to the detailed changelog of each version. If you want to know more about how the changelog is created have a look [here](/adr/2020-08-03-Implement-New-Changelog.md).

## 6.4.4.1
* [NEXT-15675 - Improve file download](/changelog/release-6-4-4-1/2021-07-29-improve-file-download.md)
* [NEXT-17058 - Bugfix autowiring type+name for already defined repositories](/changelog/release-6-4-4-1/2021-09-06-bugfix-autowiring-type-name-for-already-defined-repositories.md) ([mynameisbogdan](https://github.com/mynameisbogdan))
* [NEXT-17059 - Fixed Theme Inheritance](/changelog/release-6-4-4-1/2021-09-08-fixed-theme-inheritance.md)
* [NEXT-17072 - Fixed PriceFieldSerializer percentage calculation](/changelog/release-6-4-4-1/2021-09-09-fixed-price-field-serializer-percentage-calculation.md)
* [NEXT-17170 - Add missing context to CartVerifyPersistEvent](/changelog/release-6-4-4-1/2021-09-10-add-missing-context-to-cartverifypersistevent.md)
* [NEXT-17105 - Fixed EntitySearcher for PrimaryKeys other than `id`](/changelog/release-6-4-4-1/2021-09-10-fixed-entity-reader-for-non-id-pks.md)

## 6.4.4.0
* [NEXT-16588 - Add support for .well-known/change-password](/changelog/release-6-4-4-0/2020-11-22-add-well-known-change-password.md) ([Joshua Behrens](https://github.com/JoshuaBehrens))
* [NEXT-16516 - Sidebar flash on cookie accept all](/changelog/release-6-4-4-0/2021-04-08-sidebar-flash-on-cookie-accept-all.md) ([Rune Laenen](https://github.com/runelaenen))
Expand Down Expand Up @@ -131,6 +139,10 @@ This is the official changelog index of Shopware 6. Here you find a registry of
* [NEXT-16770 - Fix JSON structure of App CMS blocks](/changelog/release-6-4-4-0/2021-08-25-fix-json-structure-of-app-cms-blocks.md)
* [NEXT-16968 - Pin symfony/translation to 5.3.4](./changelog/release-6-4-4-0/2021-08-30-pin-symfony-translation-to-5-3-4.md)

## 6.4.3.1
* [NEXT-15675 - Improve file download](/changelog/release-6-4-3-1/2021-07-29-improve-file-download.md)
* [NEXT-15671 - Add `system.plugin_upload` privilege](./changelog/release-6-4-3-1/2021-07-30-add-plugin-upload-privilege.md)

## 6.4.3.0
* [NEXT-14114 - Add the new field is tax-free from to table currency and country.](/changelog/release-6-4-3-0/2021-03-10-add-new-field-tax-free-from-to-table-currency-and-country.md)
* [NEXT-14118 - Add VAT id required to each country setting](/changelog/release-6-4-3-0/2021-03-21-add-vat-id-required-to-each-country-setting.md)
Expand Down
27 changes: 27 additions & 0 deletions UPGRADE-6.4.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
UPGRADE FROM 6.3.x.x to 6.4
=======================

# 6.4.4.1
## Deprecating reading entities with the storage name of the primary key fields

When you added a custom entity definition with a combined primary key you need to pass the field names when you want to read specific entities.
The use of storage names when reading entities is deprecated by now, please use the property names instead.
The support of reading entities with the storage name of the primary keys will be removed in 6.5.0.0.

### Before
```php
new Criteria([
[
'storage_name_of_first_pk' => 1,
'storage_name_of_second_pk' => 2,
],
]);
```

### Now
```php
new Criteria([
[
'propertyNameOfFirstPk' => 1,
'propertyNameOfSecondPk' => 2,
],
]);
```

# 6.4.4.0
## Added support for building administration without database

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Bugfix autowiring type+name for already defined repositories
issue: NEXT-17058
author: mynameisbogdan
author_email: [email protected]
author_github: mynameisbogdan
---
# Core
* Changed `Shopware\Core\Framework\DependencyInjection\CompilerPass\EntityCompilerPass` to add `registerAliasForArgument` for already defined repositories and move duplicated calls after try-catch.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Fixed Theme Inheritance
issue: NEXT-17059
---
# Storefront
* Changed `ThemeService::mergeStaticConfig` to read correct config even on themes without own configFields.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Fixed PriceFieldSerializer percentage calculation
issue: NEXT-17072
---
# Core
* Changed `\Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\PriceFieldSerializer` to not divide by zero when calculating the percentage and allowing to decode data in the old format.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Add missing context to CartVerifyPersistEvent
issue: NEXT-17170
author_github: @Dominik28111
---
# Core
* Added SalesChannelConext to `Shopware\Core\Checkout\Cart\Event\CartVerifyPersistEvent::__construct()`.
* Added method `Shopware\Core\Checkout\Cart\Event\CartVerifyPersistEvent::setShouldPersist()`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Fixed EntitySearcher for PrimaryKeys other than `id`
issue: NEXT-17105
---
# Core
* Changed `\Shopware\Core\Framework\DataAbstractionLayer\Dbal\EntityDefinitionQueryHelper` to fix problem when entities have primary keys, where the storage name and the property name differs.
* Deprecated reading entities with the storage name of the primary key, use the property name instead.
___
# Upgrade Information

## Deprecating reading entities with the storage name of the primary key fields

When you added a custom entity definition with a combined primary key you need to pass the field names when you want to read specific entities.
The use of storage names when reading entities is deprecated by now, please use the property names instead.
The support of reading entities with the storage name of the primary keys will be removed in 6.5.0.0.

### Before
```php
new Criteria([
[
'storage_name_of_first_pk' => 1,
'storage_name_of_second_pk' => 2,
],
]);
```

### Now
```php
new Criteria([
[
'propertyNameOfFirstPk' => 1,
'propertyNameOfSecondPk' => 2,
],
]);
```
2 changes: 1 addition & 1 deletion src/Core/Checkout/Cart/CartPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function save(Cart $cart, SalesChannelContext $context): void
|| $cart->getCustomerComment() !== null
|| $cart->getExtension(DeliveryProcessor::MANUAL_SHIPPING_COSTS) instanceof CalculatedPrice;

$event = new CartVerifyPersistEvent($cart, $shouldPersist);
$event = new CartVerifyPersistEvent($context, $cart, $shouldPersist);

$this->eventDispatcher->dispatch($event);

Expand Down
8 changes: 7 additions & 1 deletion src/Core/Checkout/Cart/Event/CartVerifyPersistEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class CartVerifyPersistEvent extends Event implements ShopwareSalesChannelEvent

protected bool $shouldPersist;

public function __construct(Cart $cart, bool $shouldPersist)
public function __construct(SalesChannelContext $context, Cart $cart, bool $shouldPersist)
{
$this->context = $context;
$this->cart = $cart;
$this->shouldPersist = $shouldPersist;
}
Expand All @@ -41,4 +42,9 @@ public function shouldBePersisted(): bool
{
return $this->shouldPersist;
}

public function setShouldPersist(bool $persist): void
{
$this->shouldPersist = $persist;
}
}
45 changes: 45 additions & 0 deletions src/Core/Checkout/Test/Cart/CartPersisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
use Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection;
use Shopware\Core\Checkout\Cart\Tax\Struct\TaxRuleCollection;
use Shopware\Core\Checkout\Test\Cart\Common\Generator;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\EventDispatcher\EventDispatcher;

class CartPersisterTest extends TestCase
Expand Down Expand Up @@ -232,4 +235,46 @@ public function testCartVerifyPersistEventIsFiredAndPersisted(): void
static::assertTrue($caughtEvent->shouldBePersisted());
static::assertCount(1, $caughtEvent->getCart()->getLineItems());
}

public function testCartVerifyPersistEventIsFiredAndModified(): void
{
$connection = $this->createMock(Connection::class);
$eventDispatcher = new EventDispatcher();

$caughtEvent = null;
$handler = static function (CartVerifyPersistEvent $event) use (&$caughtEvent): void {
$caughtEvent = $event;
$event->setShouldPersist(false);
};
$eventDispatcher->addListener(CartVerifyPersistEvent::class, $handler);

$persister = new CartPersister($connection, $eventDispatcher);

$cart = new Cart('shopware', 'existing');
$cart->addLineItems(new LineItemCollection([
new LineItem(Uuid::randomHex(), LineItem::PROMOTION_LINE_ITEM_TYPE, Uuid::randomHex(), 1),
]));

$connection->expects(static::once())
->method('delete')
->with('`cart`', ['token' => $cart->getToken()]);

$persister->save(
$cart,
$this->getSalesChannelContext($cart->getToken())
);

static::assertInstanceOf(CartVerifyPersistEvent::class, $caughtEvent);
static::assertFalse($caughtEvent->shouldBePersisted());
static::assertCount(1, $caughtEvent->getCart()->getLineItems());

$eventDispatcher->removeListener(CartVerifyPersistEvent::class, $handler);
}

private function getSalesChannelContext(string $token): SalesChannelContext
{
return $this->getContainer()
->get(SalesChannelContextFactory::class)
->create($token, Defaults::SALES_CHANNEL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -559,20 +559,41 @@ private function addIdConditionWithOr(Criteria $criteria, EntityDefinition $defi

$where = [];

foreach ($primaryKey as $storageName => $value) {
$field = $definition->getFields()->getByStorageName($storageName);
foreach ($primaryKey as $propertyName => $value) {
$field = $definition->getFields()->get($propertyName);

/*
* @deprecated tag:v6.5.0 - with 6.5.0 the only passing the propertyName will be supported
*/
if (!$field) {
$field = $definition->getFields()->getByStorageName($propertyName);
}

if (!$field) {
throw new UnmappedFieldException($propertyName, $definition);
}

if (!$field instanceof StorageAware) {
throw new \RuntimeException('Only storage aware fields are supported in read condition');
}

if ($field instanceof IdField || $field instanceof FkField) {
$value = Uuid::fromHexToBytes($value);
}

$key = 'pk' . Uuid::randomHex();

$accessor = EntityDefinitionQueryHelper::escape($definition->getEntityName()) . '.' . EntityDefinitionQueryHelper::escape($storageName);
$accessor = EntityDefinitionQueryHelper::escape($definition->getEntityName()) . '.' . EntityDefinitionQueryHelper::escape($field->getStorageName());

$where[] = $accessor . ' = :' . $key;
/*
* @deprecated tag:v6.5.0 - check for duplication in accessors will be removed,
* when we only support propertyNames to be used in search and when IdSearchResult only returns the propertyNames
*/
if (!\array_key_exists($accessor, $where)) {
$where[$accessor] = $accessor . ' = :' . $key;

$query->setParameter($key, $value);
$query->setParameter($key, $value);
}
}

$wheres[] = '(' . implode(' AND ', $where) . ')';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,23 @@ public function encode(
$price['gross'] = (float) $price['gross'];
$price['net'] = (float) $price['net'];

if (isset($price['listPrice']) && isset($price['listPrice']['gross'])) {
if (isset($price['listPrice'])) {
$price['percentage'] = null;
}

if (($price['listPrice']['net'] ?? 0) > 0 || ($price['listPrice']['gross'] ?? 0) > 0) {
$price['percentage'] = [
'net' => round(100 - $price['net'] / $price['listPrice']['net'] * 100, 2),
'gross' => round(100 - $price['gross'] / $price['listPrice']['gross'] * 100, 2),
'net' => 0.0,
'gross' => 0.0,
];
}

if (\array_key_exists('listPrice', $price) && $price['listPrice'] === null) {
$price['percentage'] = null;
if (($price['listPrice']['net'] ?? 0) > 0) {
$price['percentage']['net'] = round(100 - $price['net'] / $price['listPrice']['net'] * 100, 2);
}

if (($price['listPrice']['gross'] ?? 0) > 0) {
$price['percentage']['gross'] = round(100 - $price['gross'] / $price['listPrice']['gross'] * 100, 2);
}
}

$converted['c' . $price['currencyId']] = $price;
Expand Down Expand Up @@ -137,7 +145,7 @@ public function decode(Field $field, /*?string */$value)/*: ?PriceCollection*/
(float) $data['gross'],
(bool) $data['linked'],
),
$row['percentage']
$row['percentage'] ?? null
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ private function collectDefinitions(ContainerBuilder $container): void
$repository = $container->getDefinition($repositoryId);
//@deprecated tag:v6.5.0 (flag:FEATURE_NEXT_16155) - remove add method call
$repository->addMethodCall('setEntityLoadedEventFactory', [new Reference(EntityLoadedEventFactory::class)]);
$repository->setPublic(true);
} catch (ServiceNotFoundException $exception) {
$repository = new Definition(
EntityRepository::class,
Expand All @@ -72,11 +71,11 @@ private function collectDefinitions(ContainerBuilder $container): void
new Reference(EntityLoadedEventFactory::class),
]
);
$repository->setPublic(true);

$container->setDefinition($repositoryId, $repository);
$container->registerAliasForArgument($repositoryId, EntityRepositoryInterface::class);
}
$repository->setPublic(true);
$container->registerAliasForArgument($repositoryId, EntityRepositoryInterface::class);

$repositoryNameMap[$entity] = $repositoryId;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace Shopware\Core\Framework\Test\DataAbstractionLayer\Field\TestDefinition;

use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\ApiAware;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\PrimaryKey;
use Shopware\Core\Framework\DataAbstractionLayer\Field\IdField;
use Shopware\Core\Framework\DataAbstractionLayer\Field\StringField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;

class NonIdPrimaryKeyTestDefinition extends EntityDefinition
{
public const ENTITY_NAME = 'non_id_primary_key_test';

public function getEntityName(): string
{
return self::ENTITY_NAME;
}

public function since(): ?string
{
return '6.0.0.0';
}

protected function defineFields(): FieldCollection
{
return new FieldCollection([
(new IdField('test_field', 'testField'))->addFlags(new ApiAware(), new PrimaryKey()),

new StringField('name', 'name'),
]);
}
}
Loading

0 comments on commit 08b0bd5

Please sign in to comment.