Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/10.3' into 11.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Website/LinkGenerator/CategoryLinkGenerator.php
#	src/Website/LinkGenerator/NewsLinkGenerator.php
#	src/Website/LinkGenerator/ProductLinkGenerator.php
#	var/classes/definition_Customer.php
  • Loading branch information
kingjia90 committed Jul 20, 2023
2 parents ddefe8e + 9573b1e commit 70ba7a9
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 54 deletions.
2 changes: 2 additions & 0 deletions dump/data-0-bootstrap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,7 @@ CREATE TABLE `object_query_CU` (
`passwordRecoveryTokenDate` bigint(20) DEFAULT NULL,
`customerLanguage` varchar(190) DEFAULT NULL,
`newsletter` tinyint(1) DEFAULT NULL,
`newsletterActive` tinyint(1) DEFAULT NULL,
`newsletterConfirmed` tinyint(1) DEFAULT NULL,
`profiling` tinyint(1) DEFAULT NULL,
`newsletterConfirmToken` varchar(190) DEFAULT NULL,
Expand Down Expand Up @@ -2526,6 +2527,7 @@ CREATE TABLE `object_store_CU` (
`customerLanguage` varchar(190) DEFAULT NULL,
`newsletter__consent` tinyint(1) DEFAULT NULL,
`newsletter__note` int(11) DEFAULT NULL,
`newsletterActive` tinyint(1) DEFAULT NULL,
`newsletterConfirmed` tinyint(1) DEFAULT NULL,
`profiling__consent` tinyint(1) DEFAULT NULL,
`profiling__note` int(11) DEFAULT NULL,
Expand Down
26 changes: 13 additions & 13 deletions dump/data-1-object_query_CU.sql

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions dump/data-1-object_store_CU.sql

Large diffs are not rendered by default.

59 changes: 46 additions & 13 deletions src/Twig/Extension/LanguageSwitcherExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@

namespace App\Twig\Extension;

use App\Website\LinkGenerator\AbstractProductLinkGenerator;
use App\Website\LinkGenerator\CategoryLinkGenerator;
use App\Website\LinkGenerator\NewsLinkGenerator;
use App\Website\LinkGenerator\ProductLinkGenerator;
use Pimcore\Model\Document;
use Pimcore\Model\Document\Service;
use Pimcore\Tool;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Pimcore\Model\DataObject;

class LanguageSwitcherExtension extends AbstractExtension
{
Expand All @@ -32,25 +37,39 @@ class LanguageSwitcherExtension extends AbstractExtension
*/
private $documentService;

/**
* @var UrlGeneratorInterface $urlGenerator
*/
private UrlGeneratorInterface $urlGenerator;

/**
* @var RequestStack $requestStack
*/
private RequestStack $requestStack;
private CategoryLinkGenerator $categoryLinkGenerator;
private NewsLinkGenerator $newsLinkGenerator;
private ProductLinkGenerator $productLinkGenerator;

public function __construct(Service $documentService, UrlGeneratorInterface $urlGenerator, RequestStack $requestStack)
public function __construct(Service $documentService, UrlGeneratorInterface $urlGenerator, RequestStack $requestStack, CategoryLinkGenerator $categoryLinkGenerator, NewsLinkGenerator $newsLinkGenerator, ProductLinkGenerator $productLinkGenerator)
{
$this->documentService = $documentService;
$this->urlGenerator = $urlGenerator;
$this->requestStack = $requestStack;
$this->categoryLinkGenerator = $categoryLinkGenerator;
$this->newsLinkGenerator = $newsLinkGenerator;
$this->productLinkGenerator = $productLinkGenerator;
}

public function getLocalizedLinks(Document $document): array
{
$dynamicRoutesMapping = [
'shop-detail' => [
'generator' => 'productLinkGenerator',
'requiredField' => 'product'
],
'shop-category' => [
'generator' => 'categoryLinkGenerator',
'requiredField' => 'category'
],
'news-detail' => [
'generator' => 'newsLinkGenerator',
'requiredField' => 'news'
]
];

$translations = $this->documentService->getTranslations($document);
$request = $this->requestStack->getCurrentRequest();

Expand All @@ -71,12 +90,26 @@ public function getLocalizedLinks(Document $document): array
}

$route = $request->get('_route');
$routeParams = $request->get('_route_params');

if ($route && $routeParams) {
$routeParams['_locale'] = \Locale::getPrimaryLanguage($language);
$route = $this->urlGenerator->generate($route, $routeParams);
$target = $route;
if ($route && array_key_exists($route, $dynamicRoutesMapping)) {
$routeParams = $request->get('_route_params', []);
$requiredField = $dynamicRoutesMapping[$route]['requiredField'];

if (!array_key_exists($requiredField, $routeParams)){
continue;
}

$generator = $dynamicRoutesMapping[$route]['generator'];
$object = $request->get($requiredField);

if (!is_object($object)) {
$object = DataObject::getById($object);
}

$linkGeneratorService = $this->$generator;
if ($linkGeneratorService instanceof AbstractProductLinkGenerator) {
$target = $linkGeneratorService->generate($object, ['locale' => \Locale::getPrimaryLanguage($language)]);
}
}

$links[$language] = [
Expand Down
4 changes: 2 additions & 2 deletions src/Website/LinkGenerator/AbstractProductLinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(DocumentResolver $documentResolver, RequestStack $re
* @param Category|null $rootCategory
* @return string
*/
public function getNavigationPath(?Category $category, ?Category $rootCategory = null)
public function getNavigationPath(?Category $category, ?Category $rootCategory = null, $locale = null)
{
if (empty($rootCategory)) {
if (!$this->document) {
Expand All @@ -83,7 +83,7 @@ public function getNavigationPath(?Category $category, ?Category $rootCategory =
}

foreach ($categories as $categoryInPath) {
$path .= Text::toUrl($categoryInPath->getName()).'/';
$path .= Text::toUrl($categoryInPath->getName($locale)).'/';
}

return $path;
Expand Down
8 changes: 5 additions & 3 deletions src/Website/LinkGenerator/CategoryLinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public function generate(object $object, array $params = [], bool $reset = false
$this->document = $params['document'];
}

$locale = $params['locale'] ?? null;

return $this->pimcoreUrl->__invoke(
[
'categoryname' => Text::toUrl($object->getName() ? $object->getName() : 'elements'),
'categoryname' => Text::toUrl($object->getName($locale) ? $object->getName($locale) : 'elements'),
'category' => $object->getId(),
'path' => $this->getNavigationPath($object, $params['rootCategory'] ?? null),
'path' => $this->getNavigationPath($object, $params['rootCategory'] ?? null, $locale),
'page' => null,
'_locale' => $params['locale'] ?? null,
'_locale' => $locale,
],
'shop-category',
$reset
Expand Down
6 changes: 4 additions & 2 deletions src/Website/LinkGenerator/NewsLinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ public function generate(object $object, array $params = []): string
$fullPath = $document->getProperty('news_default_document') ? substr($document->getProperty('news_default_document')->getFullPath(), strlen($localeUrlPart)) : '';
}

$locale = $params['locale'] ?? null;

return $this->pimcoreUrl->__invoke(
[
'newstitle' => Text::toUrl($object->getTitle() ? $object->getTitle() : 'news'),
'newstitle' => Text::toUrl($object->getTitle($locale) ? $object->getTitle($locale) : 'news'),
'news' => $object->getId(),
'path' => $fullPath,
'_locale' => $params['locale'] ?? null,
'_locale' => $locale,
],
'news-detail',
true
Expand Down
6 changes: 4 additions & 2 deletions src/Website/LinkGenerator/ProductLinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ protected function doGenerate($object, $params): string
return current($object->getUrlSlug())->getSlug();
}

$locale = $params['locale'] ?? null;

return $this->pimcoreUrl->__invoke(
[
'productname' => Text::toUrl($object->getOSName() ?? 'product'),
'product' => $object->getId(),
'path' => $this->getNavigationPath($object->getMainCategory(), $params['rootCategory'] ?? null),
'path' => $this->getNavigationPath($object->getMainCategory(), $params['rootCategory'] ?? null, $locale),
'page' => null,
'_locale' => $params['locale'] ?? null,
'_locale' => $locale,
],
'shop-detail',
true
Expand Down
2 changes: 1 addition & 1 deletion src/Website/Tool/PimcoreUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __invoke(array $urlOptions = [], $name = null, $reset = false, $
{
// merge all parameters from request to parameters
if (!$reset && $this->requestHelper->hasMainRequest()) {
$urlOptions = array_replace($this->requestHelper->getMainRequest()->attributes->get('_route_params'), $urlOptions);
$urlOptions = array_replace($this->requestHelper->getMainRequest()->attributes->get('_route_params', []), $urlOptions);
}

return parent::__invoke($urlOptions, $name, $reset, $encode, $relative);
Expand Down
36 changes: 31 additions & 5 deletions var/classes/definition_Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* - idEncoded [input]
* - customerLanguage [language]
* - newsletter [consent]
* - newsletterActive [newsletterActive]
* - newsletterConfirmed [newsletterConfirmed]
* - newsletterConfirmToken [input]
* - profiling [consent]
Expand All @@ -36,9 +37,9 @@
'name' => 'Customer',
'description' => '',
'creationDate' => 0,
'modificationDate' => 1683551625,
'modificationDate' => 1685007611,
'userOwner' => 2,
'userModification' => 1,
'userModification' => 2,
'parentClass' => '\\CustomerManagementFrameworkBundle\\Model\\AbstractCustomer\\DefaultAbstractUserawareCustomer',
'implementsInterfaces' => '',
'listingParentClass' => '',
Expand Down Expand Up @@ -142,6 +143,7 @@
'blockedVarsForExport' =>
array (
),
'options' => NULL,
'width' => '',
'defaultValue' => NULL,
'optionsProviderClass' => NULL,
Expand Down Expand Up @@ -478,6 +480,7 @@
'blockedVarsForExport' =>
array (
),
'options' => NULL,
'width' => '',
'defaultValue' => NULL,
'optionsProviderClass' => NULL,
Expand Down Expand Up @@ -526,6 +529,29 @@
'width' => NULL,
)),
1 =>
Pimcore\Model\DataObject\ClassDefinition\Data\NewsletterActive::__set_state(array(
'name' => 'newsletterActive',
'title' => 'Newsletter Active',
'tooltip' => '',
'mandatory' => false,
'noteditable' => true,
'index' => false,
'locked' => false,
'style' => '',
'permissions' => NULL,
'datatype' => 'data',
'fieldtype' => 'newsletterActive',
'relationType' => false,
'invisible' => false,
'visibleGridView' => false,
'visibleSearch' => false,
'blockedVarsForExport' =>
array (
),
'defaultValue' => NULL,
'defaultValueGenerator' => '',
)),
2 =>
Pimcore\Model\DataObject\ClassDefinition\Data\NewsletterConfirmed::__set_state(array(
'name' => 'newsletterConfirmed',
'title' => 'Newsletter Confirmed',
Expand All @@ -548,7 +574,7 @@
'defaultValue' => NULL,
'defaultValueGenerator' => '',
)),
2 =>
3 =>
Pimcore\Model\DataObject\ClassDefinition\Data\Input::__set_state(array(
'name' => 'newsletterConfirmToken',
'title' => 'Newsletter Confirm Token',
Expand Down Expand Up @@ -579,7 +605,7 @@
'showCharCount' => false,
'defaultValueGenerator' => '',
)),
3 =>
4 =>
Pimcore\Model\DataObject\ClassDefinition\Data\Consent::__set_state(array(
'name' => 'profiling',
'title' => 'Profiling',
Expand Down Expand Up @@ -962,7 +988,7 @@
'group' => 'CustomerManagement',
'showAppLoggerTab' => false,
'linkGeneratorReference' => '',
'previewGeneratorReference' => NULL,
'previewGeneratorReference' => '',
'compositeIndices' =>
array (
),
Expand Down

0 comments on commit 70ba7a9

Please sign in to comment.