Skip to content

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed May 4, 2023
2 parents def11c9 + ca4aa4d commit c21cab4
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 89 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ services:
- db
volumes:
- .:/var/www/html:cached
- ./.docker/xdebug-config.ini:/usr/local/etc/php/conf.d/21-xdebug.ini
environment:
PHP_IDE_CONFIG: serverName=localhost
XDEBUG_TRIGGER: PHPSTORM
Expand All @@ -110,6 +111,7 @@ services:
- db
volumes:
- .:/var/www/html:cached
- ./.docker/xdebug-config.ini:/usr/local/etc/php/conf.d/21-xdebug.ini
environment:
PHP_IDE_CONFIG: serverName=localhost
COMPOSER_HOME: /var/www/html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function load(array $configs, ContainerBuilder $container): void
'priority' => 10,
]);

$container->setParameter('coreshop.resources', []);
$container->setDefinition('coreshop.body_listener', $bodyListener);

$container
Expand Down
72 changes: 71 additions & 1 deletion src/CoreShop/Bundle/StoreBundle/CoreExtension/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

use CoreShop\Bundle\ResourceBundle\CoreExtension\Select;
use CoreShop\Component\Store\Model\StoreInterface;
use InvalidArgumentException;
use Pimcore\Model\DataObject\ClassDefinition\Helper\OptionsProviderResolver;

/**
* @psalm-suppress InvalidReturnType, InvalidReturnStatement
Expand All @@ -33,6 +35,12 @@ class Store extends Select
*/
public $fieldtype = 'coreShopStore';

/** @var array|null */
public $options = [];

/** @var string */
public $optionsProviderClass = '@'.StoreOptionProvider::class;

protected function getRepository()
{
return \Pimcore::getContainer()->get('coreshop.repository.store');
Expand All @@ -55,6 +63,68 @@ protected function getNullable(): bool

public function getOptionsProviderClass()
{
return '@' . StoreOptionProvider::class;
return $this->optionsProviderClass;
}

public function getDataForGrid($data, $object = null, $params = [])
{
$optionsProvider = OptionsProviderResolver::resolveProvider(
$this->getOptionsProviderClass(),
OptionsProviderResolver::MODE_SELECT
);

if ($optionsProvider) {
$context = $params['context'] ?? [];
$context['object'] = $object;
if ($object) {
$context['class'] = $object->getClass();
}

$context['fieldname'] = $this->getName();
$options = $optionsProvider->{'getOptions'}($context, $this);
$this->setOptions($options);

if (isset($params['purpose']) && $params['purpose'] === 'editmode') {
$result = $data?->getId();
} else {
$result = ['value' => $data?->getId(), 'options' => $this->getOptions()];
}

return $result;
}

return $data?->getId();
}

/**
* @param array|null $options
*
* @return $this
*/
public function setOptions(?array $options)
{
if (is_array($options)) {
$this->options = [];
foreach ($options as $option) {
$option = (array)$option;
if (!array_key_exists('key', $option) || !array_key_exists('value', $option)) {
throw new InvalidArgumentException('Please provide select options as associative array with fields "key" and "value"');
}

$this->options[] = $option;
}
} else {
$this->options = null;
}

return $this;
}

/**
* @return array
*/
public function getOptions()
{
return $this->options;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,6 @@
"datatype": "layout",
"permissions": null,
"children": [
{
"fieldtype": "input",
"width": "",
"defaultValue": null,
"columnLength": 190,
"regex": "",
"regexFlags": [],
"unique": false,
"showCharCount": false,
"name": "name",
"title": "Name",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"defaultValueGenerator": ""
},
{
"fieldtype": "input",
"width": null,
Expand All @@ -92,27 +67,9 @@
"visibleSearch": false,
"defaultValueGenerator": ""
},
{
"fieldtype": "coreShopStore",
"allowEmpty": false,
"name": "store",
"title": "coreshop.order.store",
"tooltip": "",
"mandatory": false,
"noteditable": true,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"relationType": false,
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopRelations",
"stack": "coreshop.product",
"stack": "coreshop.wishlist_item",
"relationType": true,
"objectsAllowed": true,
"assetsAllowed": false,
Expand All @@ -139,38 +96,6 @@
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
},
{
"fieldtype": "coreShopRelation",
"stack": "coreshop.customer",
"relationType": true,
"objectsAllowed": true,
"assetsAllowed": false,
"documentsAllowed": false,
"returnConcrete": false,
"width": null,
"assetUploadPath": null,
"assetTypes": [],
"documentTypes": [],
"classes": [
{
"classes": "CoreShopCustomer"
}
],
"pathFormatterClass": "",
"name": "customer",
"title": "Customer",
"tooltip": "",
"mandatory": false,
"noteditable": false,
"index": false,
"locked": false,
"style": "",
"permissions": null,
"datatype": "data",
"invisible": false,
"visibleGridView": false,
"visibleSearch": false
}
],
"locked": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
"assetTypes": [],
"documentTypes": [],
"classes": [
{
"classes": "CoreShopProduct"
}
],
"pathFormatterClass": "",
"name": "product",
Expand Down Expand Up @@ -119,11 +116,6 @@
"invisible": false,
"visibleGridView": false,
"visibleSearch": false,
"classes": [
{
"classes": "CoreShopWishlist"
}
],
"pathFormatterClass": "",
"width": null,
"assetUploadPath": null,
Expand Down
6 changes: 6 additions & 0 deletions src/CoreShop/Component/Pimcore/Event/SlugGenerationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(
protected string $slug,
protected ?string $suffix = null,
protected ?Site $site = null,
protected ?string $locale = null,
) {
}

Expand Down Expand Up @@ -56,4 +57,9 @@ public function getSite(): ?Site
{
return $this->site;
}

public function getLocale(): ?string
{
return $this->locale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
public function generateSlugsForSite(SluggableInterface $sluggable, string $locale, ?Site $site = null): string
{
$slug = $this->slugger->slug($sluggable, $locale, null);
$slug = $this->dispatchSlugEvent($sluggable, $slug, null, $site);
$slug = $this->dispatchSlugEvent($sluggable, $slug, null, $site, $locale);

$i = 1;

Expand All @@ -47,17 +47,17 @@ public function generateSlugsForSite(SluggableInterface $sluggable, string $loca
}

$slug = $this->slugger->slug($sluggable, $locale, (string) $i);
$slug = $this->dispatchSlugEvent($sluggable, $slug, (string) $i, $site);
$slug = $this->dispatchSlugEvent($sluggable, $slug, (string) $i, $site, $locale);

++$i;
}

return $slug;
}

private function dispatchSlugEvent(SluggableInterface $sluggable, string $slug, string $prefix = null, ?Site $site = null)
private function dispatchSlugEvent(SluggableInterface $sluggable, string $slug, string $prefix = null, ?Site $site = null, ?string $locale = null)
{
$event = new SlugGenerationEvent($sluggable, $slug, $prefix, $site);
$event = new SlugGenerationEvent($sluggable, $slug, $prefix, $site, $locale);
$this->eventDispatcher->dispatch($event);

return $event->getSlug();
Expand Down

0 comments on commit c21cab4

Please sign in to comment.