Skip to content

Commit fa4045a

Browse files
Initital Commit
1 parent 1a32573 commit fa4045a

File tree

12 files changed

+230
-2
lines changed

12 files changed

+230
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
AreanetDefaultProductLayout/src/Resources/public
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [1.0.0 / 2.0.0] - 2024-02-16
2+
3+
- Inital implementation, set default layout for products in plugin config
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "areanet/default-product-layout",
3+
"type": "shopware-platform-plugin",
4+
"description": "Custom defaultlayout for products @area-net.den",
5+
"version": "1.0.0",
6+
"license": "MIT",
7+
"require": {
8+
"shopware/core": "6.4.* || 6.5.*"
9+
},
10+
"extra": {
11+
"shopware-plugin-class": "AreanetDefaultProductLayout\\AreanetDefaultProductLayout",
12+
"label": {
13+
"de-DE": "Eigenes Standardlayout für Produkte @area-net.de",
14+
"en-GB": "Custom defaultlayout for products @area-net.den"
15+
}
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"AreanetDefaultProductLayout\\": "src/"
20+
}
21+
}
22+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace AreanetDefaultProductLayout;
4+
5+
use Shopware\Core\Framework\Plugin;
6+
use Shopware\Core\Framework\Plugin\Context\ActivateContext;
7+
use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
8+
use Shopware\Core\Framework\Plugin\Context\InstallContext;
9+
use Shopware\Core\Framework\Plugin\Context\UninstallContext;
10+
use Shopware\Core\Framework\Plugin\Context\UpdateContext;
11+
use AreanetDefaultPluginLayout\Service\CustomFieldsInstaller;
12+
13+
class AreanetDefaultProductLayout extends Plugin
14+
{
15+
public function install(InstallContext $installContext): void
16+
{
17+
18+
}
19+
20+
public function uninstall(UninstallContext $uninstallContext): void
21+
{
22+
parent::uninstall($uninstallContext);
23+
24+
if ($uninstallContext->keepUserData()) {
25+
return;
26+
}
27+
28+
}
29+
30+
public function activate(ActivateContext $activateContext): void
31+
{
32+
33+
}
34+
35+
public function deactivate(DeactivateContext $deactivateContext): void
36+
{
37+
38+
}
39+
40+
public function update(UpdateContext $updateContext): void
41+
{
42+
43+
}
44+
45+
public function postInstall(InstallContext $installContext): void
46+
{
47+
}
48+
49+
public function postUpdate(UpdateContext $updateContext): void
50+
{
51+
}
52+
53+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace AreanetDefaultProductLayout\Core\Content\Product\Subscriber;
4+
5+
use Shopware\Core\Content\Product\AbstractIsNewDetector;
6+
use Shopware\Core\Content\Product\AbstractProductMaxPurchaseCalculator;
7+
use Shopware\Core\Content\Product\AbstractProductVariationBuilder;
8+
use Shopware\Core\Content\Product\AbstractPropertyGroupSorter;
9+
use Shopware\Core\Content\Product\ProductDefinition;
10+
use Shopware\Core\Content\Product\SalesChannel\Price\AbstractProductPriceCalculator;
11+
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
12+
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
13+
use Shopware\Core\Framework\Feature;
14+
use Shopware\Core\System\SystemConfig\SystemConfigService;
15+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16+
use Shopware\Core\Content\Product\ProductEvents;
17+
18+
class AreanetProductSubscriber implements EventSubscriberInterface
19+
{
20+
private SystemConfigService $systemConfigService;
21+
22+
public function __construct(
23+
SystemConfigService $systemConfigService
24+
) {
25+
$this->systemConfigService = $systemConfigService;
26+
}
27+
28+
public static function getSubscribedEvents(): array
29+
{
30+
31+
return [
32+
ProductEvents::PRODUCT_LOADED_EVENT => 'loaded',
33+
];
34+
}
35+
36+
public function loaded(EntityLoadedEvent $event)
37+
{
38+
$salesChannelId = $event->getContext()->getSource()->getSalesChannelId();
39+
40+
foreach ($event->getEntities() as $product) {
41+
$this->setDefaultLayout($product, $salesChannelId);
42+
}
43+
}
44+
45+
protected function setDefaultLayout(Entity $product, string $salesChannelId ){
46+
47+
$systemDefaultCmsPageId = $this->systemConfigService->get(ProductDefinition::CONFIG_KEY_DEFAULT_CMS_PAGE_PRODUCT, $salesChannelId);
48+
if($product->has('cmsPageId') != $systemDefaultCmsPageId){
49+
return;
50+
}
51+
52+
$cmsPageId = $this->systemConfigService->get('AreanetDefaultProductLayout.config.layout', $salesChannelId);
53+
if(!$cmsPageId){
54+
$this->systemConfigService->get(ProductDefinition::CONFIG_KEY_DEFAULT_CMS_PAGE_PRODUCT, $salesChannelId);
55+
}
56+
57+
$product->assign(['cmsPageId' => $cmsPageId]);
58+
}
59+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { Component } = Shopware;
2+
const { Criteria } = Shopware.Data;
3+
4+
Component.extend('layout-state-select', 'sw-entity-single-select', {
5+
props: {
6+
criteria: {
7+
type: Object,
8+
required: false,
9+
default() {
10+
const criteria = new Criteria(1, this.resultLimit);
11+
criteria.addFilter(Criteria.equals('type', 'product_detail'));
12+
return criteria;
13+
}
14+
},
15+
}
16+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './component/entity/layout-state-select';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/trunk/src/Core/System/SystemConfig/Schema/config.xsd">
5+
6+
<card>
7+
<title>Default product layout</title>
8+
<title lang="de-DE">Standard Produktlayout</title>
9+
10+
<component name="layout-state-select">
11+
<name>layout</name>
12+
<entity>cms_page</entity>
13+
<label lang="de-DE">Layout</label>
14+
<label>Layout</label>
15+
</component>
16+
</card>
17+
18+
</config>
2.18 KB
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
9+
<service id="AreanetDefaultProductLayout\Core\Content\Product\Subscriber\AreanetProductSubscriber">
10+
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService"/>
11+
<tag name="kernel.event_subscriber"/>
12+
</service>
13+
14+
</services>
15+
</container>

0 commit comments

Comments
 (0)